From 2d5c1b1926a4bc571858f660cc3b8cd037b67dc4 Mon Sep 17 00:00:00 2001 From: Michael Grosser Date: Sun, 31 Jan 2021 21:14:21 -0800 Subject: [PATCH] kiss style --- .github/workflows/ci.yml | 2 +- .rubocop.yml | 3 +++ Rakefile | 4 ++-- lib/css_parser/rule_set.rb | 10 +++++----- test/test_css_parser_media_types.rb | 6 +++--- 5 files changed, 14 insertions(+), 11 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 96ba605..890b504 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 diff --git a/.rubocop.yml b/.rubocop.yml index 0f3ce72..4759162 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -68,3 +68,6 @@ Style/StringLiterals: Style/WordArray: Enabled: false + +Style/SymbolArray: + EnforcedStyle: brackets diff --git a/Rakefile b/Rakefile index 35522bd..021cd23 100644 --- a/Rakefile +++ b/Rakefile @@ -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 @@ -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] diff --git a/lib/css_parser/rule_set.rb b/lib/css_parser/rule_set.rb index 7e97394..d744e2d 100644 --- a/lib/css_parser/rule_set.rb +++ b/lib/css_parser/rule_set.rb @@ -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 @@ -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: diff --git a/test/test_css_parser_media_types.rb b/test/test_css_parser_media_types.rb index 11a0f54..6f3ff27 100644 --- a/test/test_css_parser_media_types.rb +++ b/test/test_css_parser_media_types.rb @@ -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 @@ -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 @@ -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