diff --git a/.rubocop.yml b/.rubocop.yml index f005b3a..a30ab8e 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,3 +1,6 @@ +require: + - rubocop-rake + AllCops: TargetRubyVersion: 2.7 # lowest supported version NewCops: enable @@ -53,6 +56,10 @@ Style/Not: Style/NumericPredicate: Enabled: false +Style/OpenStructUse: + Exclude: + - 'test/**/*' + Style/RedundantFreeze: Enabled: false diff --git a/Gemfile b/Gemfile index 1d4e592..1ca5eff 100644 --- a/Gemfile +++ b/Gemfile @@ -5,3 +5,12 @@ source 'https://rubygems.org' gemspec + +gem 'benchmark-ips' +gem 'bump' +gem 'maxitest' +gem 'memory_profiler' +gem 'rake' +gem 'rubocop' +gem 'rubocop-rake' +gem 'webrick' diff --git a/Gemfile.lock b/Gemfile.lock index c173c50..b6f2222 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -9,37 +9,45 @@ GEM specs: addressable (2.8.6) public_suffix (>= 2.0.2, < 6.0) - ast (2.4.1) - benchmark-ips (2.8.4) + ast (2.4.2) + benchmark-ips (2.13.0) bump (0.10.0) - maxitest (3.6.0) - minitest (>= 5.0.0, < 5.14.0) - memory_profiler (1.0.0) - minitest (5.12.0) - parallel (1.20.1) - parser (3.0.0.0) + json (2.7.2) + json (2.7.2-java) + language_server-protocol (3.17.0.3) + maxitest (4.5.0) + minitest (>= 5.0.0, < 5.19.0) + memory_profiler (1.0.1) + minitest (5.18.1) + parallel (1.24.0) + parser (3.3.0.5) ast (~> 2.4.1) + racc public_suffix (5.0.5) - rainbow (3.0.0) - rake (13.0.3) - regexp_parser (2.0.3) - rexml (3.2.4) - rubocop (1.8.0) + racc (1.7.3) + racc (1.7.3-java) + rainbow (3.1.1) + rake (13.2.1) + regexp_parser (2.9.0) + rexml (3.2.6) + rubocop (1.62.1) + json (~> 2.3) + language_server-protocol (>= 3.17.0) parallel (~> 1.10) - parser (>= 3.0.0.0) + parser (>= 3.3.0.2) rainbow (>= 2.2.2, < 4.0) regexp_parser (>= 1.8, < 3.0) - rexml - rubocop-ast (>= 1.2.0, < 2.0) + rexml (>= 3.2.5, < 4.0) + rubocop-ast (>= 1.31.1, < 2.0) ruby-progressbar (~> 1.7) - unicode-display_width (>= 1.4.0, < 3.0) - rubocop-ast (1.4.0) - parser (>= 2.7.1.5) - rubocop-rake (0.5.1) - rubocop - ruby-progressbar (1.11.0) - unicode-display_width (2.0.0) - webrick (1.7.0) + unicode-display_width (>= 2.4.0, < 3.0) + rubocop-ast (1.31.2) + parser (>= 3.3.0.4) + rubocop-rake (0.6.0) + rubocop (~> 1.0) + ruby-progressbar (1.13.0) + unicode-display_width (2.5.0) + webrick (1.8.1) PLATFORMS java @@ -52,9 +60,9 @@ DEPENDENCIES maxitest memory_profiler rake - rubocop (~> 1.8) + rubocop rubocop-rake webrick BUNDLED WITH - 2.1.4 + 2.4.12 diff --git a/css_parser.gemspec b/css_parser.gemspec index f3a12d8..242c11c 100644 --- a/css_parser.gemspec +++ b/css_parser.gemspec @@ -19,13 +19,4 @@ Gem::Specification.new name, CssParser::VERSION do |s| s.metadata['rubygems_mfa_required'] = 'true' s.add_runtime_dependency 'addressable' - - s.add_development_dependency 'benchmark-ips' - s.add_development_dependency 'bump' - s.add_development_dependency 'maxitest' - s.add_development_dependency 'memory_profiler' - s.add_development_dependency 'rake' - s.add_development_dependency 'rubocop', '~> 1.8' - s.add_development_dependency 'rubocop-rake' - s.add_development_dependency 'webrick' end diff --git a/lib/css_parser.rb b/lib/css_parser.rb index a852fe6..b50f81b 100644 --- a/lib/css_parser.rb +++ b/lib/css_parser.rb @@ -111,7 +111,7 @@ def self.merge(*rule_sets) #++ def self.calculate_specificity(selector) a = 0 - b = selector.scan(/\#/).length + b = selector.scan('#').length c = selector.scan(NON_ID_ATTRIBUTES_AND_PSEUDO_CLASSES_RX_NC).length d = selector.scan(ELEMENTS_AND_PSEUDO_ELEMENTS_RX_NC).length diff --git a/lib/css_parser/parser.rb b/lib/css_parser/parser.rb index b5e203a..357b79e 100644 --- a/lib/css_parser/parser.rb +++ b/lib/css_parser/parser.rb @@ -133,7 +133,7 @@ def add_block!(block, options = {}) block.scan(RE_AT_IMPORT_RULE).each do |import_rule| media_types = [] if (media_string = import_rule[-1]) - media_string.split(/,/).each do |t| + media_string.split(',').each do |t| media_types << CssParser.sanitize_media_query(t) unless t.empty? end else diff --git a/lib/css_parser/regexps.rb b/lib/css_parser/regexps.rb index 0529173..cf83b2d 100644 --- a/lib/css_parser/regexps.rb +++ b/lib/css_parser/regexps.rb @@ -11,7 +11,7 @@ def self.regex_possible_values(*values) RE_NON_ASCII = Regexp.new('([\x00-\xFF])', Regexp::IGNORECASE | Regexp::NOENCODING) # [^\0-\177] RE_UNICODE = Regexp.new('(\\\\[0-9a-f]{1,6}(\r\n|[ \n\r\t\f])*)', Regexp::IGNORECASE | Regexp::EXTENDED | Regexp::MULTILINE | Regexp::NOENCODING) RE_ESCAPE = Regexp.union(RE_UNICODE, '|(\\\\[^\n\r\f0-9a-f])') - RE_IDENT = Regexp.new("[\-]?([_a-z]|#{RE_NON_ASCII}|#{RE_ESCAPE})([_a-z0-9\-]|#{RE_NON_ASCII}|#{RE_ESCAPE})*", Regexp::IGNORECASE | Regexp::NOENCODING) + RE_IDENT = Regexp.new("[-]?([_a-z]|#{RE_NON_ASCII}|#{RE_ESCAPE})([_a-z0-9-]|#{RE_NON_ASCII}|#{RE_ESCAPE})*", Regexp::IGNORECASE | Regexp::NOENCODING) # General strings RE_STRING1 = /("(.[^\n\r\f"]*|\\#{RE_NL}|#{RE_ESCAPE})*")/.freeze diff --git a/lib/css_parser/rule_set.rb b/lib/css_parser/rule_set.rb index 3b445cd..c3904c1 100644 --- a/lib/css_parser/rule_set.rb +++ b/lib/css_parser/rule_set.rb @@ -58,7 +58,7 @@ def ==(other) extend Forwardable - def_delegators :declarations, :each + def_delegators :declarations, :each, :each_value def initialize(declarations = {}) self.declarations = {} @@ -142,7 +142,7 @@ def replace_declaration!(property, replacements, preserve_importance: false) if preserve_importance importance = get_value(property).important - replacement_declarations.each { |_key, value| value.important = importance } + replacement_declarations.each_value { |value| value.important = importance } end replacement_keys = declarations.keys @@ -308,7 +308,7 @@ def expand_background_shorthand! # :nodoc: replacement = if value.match(CssParser::RE_INHERIT) - BACKGROUND_PROPERTIES.map { |key| [key, 'inherit'] }.to_h + BACKGROUND_PROPERTIES.to_h { |key| [key, 'inherit'] } else { 'background-image' => value.slice!(CssParser::RE_IMAGE), @@ -448,7 +448,7 @@ def expand_list_style_shorthand! # :nodoc: replacement = if value =~ CssParser::RE_INHERIT - LIST_STYLE_PROPERTIES.map { |key| [key, 'inherit'] }.to_h + LIST_STYLE_PROPERTIES.to_h { |key| [key, 'inherit'] } else { 'list-style-type' => value.slice!(CssParser::RE_LIST_STYLE_TYPE), diff --git a/test/rule_set/test_declarations.rb b/test/rule_set/test_declarations.rb index d2d2a4d..8158787 100644 --- a/test/rule_set/test_declarations.rb +++ b/test/rule_set/test_declarations.rb @@ -167,7 +167,7 @@ class RuleSetDeclarationsTest < Minitest::Test declarations = CssParser::RuleSet::Declarations.new({foo: 'foo value'}) assert_equal 1, declarations.size - declarations.remove_declaration!('fOo'.to_sym) + declarations.remove_declaration!(:fOo) assert_equal 0, declarations.size end diff --git a/test/test_css_parser_media_types.rb b/test/test_css_parser_media_types.rb index 0784ae2..054d1b1 100644 --- a/test/test_css_parser_media_types.rb +++ b/test/test_css_parser_media_types.rb @@ -43,7 +43,7 @@ def test_finding_by_media_type assert_equal 'font-size: 10pt; line-height: 1.2;', @cp.find_by_selector('body', :print).join(' ') assert_equal 'font-size: 13px; line-height: 1.2; color: blue;', @cp.find_by_selector('body', :screen).join(' ') - assert_equal 'color: blue;', @cp.find_by_selector('body', 'print and resolution > 90dpi'.to_sym).join(' ') + assert_equal 'color: blue;', @cp.find_by_selector('body', :'print and resolution > 90dpi').join(' ') end def test_with_parenthesized_media_features diff --git a/test/test_css_parser_misc.rb b/test/test_css_parser_misc.rb index 3756c8c..758355a 100644 --- a/test/test_css_parser_misc.rb +++ b/test/test_css_parser_misc.rb @@ -79,7 +79,7 @@ def test_parsing_blocks \ foo(int x) {\ this.x = 'test';\ - this.x = \"test\";\ + this.x = "test";\ }\ \ }"] { color: red } @@ -127,8 +127,7 @@ def test_multiline_declarations @cp.each_selector do |selector, declarations, _spec| assert_equal '@font-face', selector assert_equal "font-family: 'some_font'; " \ - "src: url(https://example.com/font.woff2) format('woff2')," \ - "url(https://example.com/font.woff) format('woff'); " \ + "src: url(https://example.com/font.woff2) format('woff2'),url(https://example.com/font.woff) format('woff'); " \ "font-style: normal;", declarations end end diff --git a/test/test_rule_set.rb b/test/test_rule_set.rb index 90eae0d..e8bf458 100644 --- a/test/test_rule_set.rb +++ b/test/test_rule_set.rb @@ -73,7 +73,7 @@ def test_each_declaration_respects_order def test_each_declaration_containing_semicolons rs = RuleSet.new(nil, "background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABwAAAAiCAMAAAB7);" \ - "background-repeat: no-repeat") + "background-repeat: no-repeat") assert_equal('url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABwAAAAiCAMAAAB7);', rs['background-image']) assert_equal('no-repeat;', rs['background-repeat']) end diff --git a/test/test_rule_set_creating_shorthand.rb b/test/test_rule_set_creating_shorthand.rb index d15aaa1..0fce89c 100644 --- a/test/test_rule_set_creating_shorthand.rb +++ b/test/test_rule_set_creating_shorthand.rb @@ -219,7 +219,7 @@ def test_a_single_property_is_not_shorted protected def assert_properties_are_deleted(ruleset, properties) - properties.each do |property, _value| + properties.each_key do |property| assert_equal '', ruleset[property] end end diff --git a/test/test_rule_set_expanding_shorthand.rb b/test/test_rule_set_expanding_shorthand.rb index 792285e..d7b3887 100644 --- a/test/test_rule_set_expanding_shorthand.rb +++ b/test/test_rule_set_expanding_shorthand.rb @@ -247,7 +247,7 @@ def test_getting_list_style_properties_from_shorthand 'list-style-position' => 'inside' } - shorthand = "list-style: katakana inside url(\'chess.png\');" + shorthand = "list-style: katakana inside url('chess.png');" declarations = expand_declarations(shorthand) assert_equal expected, declarations end