Skip to content

Commit

Permalink
kiss style
Browse files Browse the repository at this point in the history
  • Loading branch information
grosser committed Feb 1, 2021
1 parent 1f942bc commit 2d5c1b1
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Expand Up @@ -35,7 +35,7 @@ jobs:

- uses: ruby/setup-ruby@v1
with:
ruby-version: '3.0'
ruby-version: '2.4' # same as target version
bundler-cache: true

- run: bundle exec rake rubocop
3 changes: 3 additions & 0 deletions .rubocop.yml
Expand Up @@ -68,3 +68,6 @@ Style/StringLiterals:

Style/WordArray:
Enabled: false

Style/SymbolArray:
EnforcedStyle: brackets
4 changes: 2 additions & 2 deletions Rakefile
Expand Up @@ -6,6 +6,8 @@ require 'rake/testtask'
require 'rubocop/rake_task'
require 'bump/tasks'

task default: [:rubocop, :test]

Rake::TestTask.new do |test|
test.pattern = 'test/**/test*.rb'
test.verbose = true
Expand Down Expand Up @@ -37,5 +39,3 @@ task :benchmark do
report = MemoryProfiler.report { CssParser::Parser.new.load_file!(complex_css_path) }
puts "Loading `complex.css` allocated #{report.total_allocated} objects, #{report.total_allocated_memsize / 1024} KiB"
end

task default: %i[rubocop test]
10 changes: 5 additions & 5 deletions lib/css_parser/rule_set.rb
Expand Up @@ -529,7 +529,7 @@ def create_dimensions_shorthand! # :nodoc:
return if declarations.size < NUMBER_OF_DIMENSIONS

DIMENSIONS.each do |property, dimensions|
values = %i[top right bottom left].each_with_index.with_object({}) do |(side, index), result|
values = [:top, :right, :bottom, :left].each_with_index.with_object({}) do |(side, index), result|
next unless declarations.key?(dimensions[index])

result[side] = declarations[dimensions[index]].value
Expand Down Expand Up @@ -586,15 +586,15 @@ def create_list_style_shorthand! # :nodoc:

def compute_dimensions_shorthand(values)
# All four sides are equal, returning single value
return %i[top] if values.values.uniq.count == 1
return [:top] if values.values.uniq.count == 1

# `/* top | right | bottom | left */`
return %i[top right bottom left] if values[:left] != values[:right]
return [:top, :right, :bottom, :left] if values[:left] != values[:right]

# Vertical are the same & horizontal are the same, `/* vertical | horizontal */`
return %i[top left] if values[:top] == values[:bottom]
return [:top, :left] if values[:top] == values[:bottom]

%i[top left bottom]
[:top, :left, :bottom]
end

def parse_declarations!(block) # :nodoc:
Expand Down
6 changes: 3 additions & 3 deletions test/test_css_parser_media_types.rb
Expand Up @@ -59,7 +59,7 @@ def test_finding_by_multiple_media_types
}
CSS

assert_equal 'font-size: 13px; line-height: 1.2;', @cp.find_by_selector('body', %i[screen handheld]).join(' ')
assert_equal 'font-size: 13px; line-height: 1.2;', @cp.find_by_selector('body', [:screen, :handheld]).join(' ')
end

def test_adding_block_with_media_types
Expand Down Expand Up @@ -116,7 +116,7 @@ def test_adding_block_and_limiting_media_types
end

def test_adding_rule_set_with_media_type
@cp.add_rule!('body', 'color: black;', %i[handheld tty])
@cp.add_rule!('body', 'color: black;', [:handheld, :tty])
@cp.add_rule!('body', 'color: blue;', :screen)
assert_equal 'color: black;', @cp.find_by_selector('body', :handheld).join(' ')
end
Expand All @@ -128,7 +128,7 @@ def test_adding_rule_set_with_media_query
end

def test_selecting_with_all_media_types
@cp.add_rule!('body', 'color: black;', %i[handheld tty])
@cp.add_rule!('body', 'color: black;', [:handheld, :tty])
assert_equal 'color: black;', @cp.find_by_selector('body', :all).join(' ')
end

Expand Down

0 comments on commit 2d5c1b1

Please sign in to comment.