Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require:
- rubocop-performance
- rubocop-rake

AllCops:
Expand Down Expand Up @@ -41,6 +42,13 @@ Metrics/ModuleLength:
Metrics/PerceivedComplexity:
Enabled: false

# TODO: Progressively fix performance offences and remove this setting
Performance:
Enabled: false

Performance/RegexpMatch:
Enabled: true

Style/AndOr:
Enabled: false

Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

### Unreleased

* Minor performance improvements

### Version v1.20.0

* Remove `iconv` conditional require
Expand Down
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ gem 'maxitest'
gem 'memory_profiler'
gem 'rake'
gem 'rubocop'
gem 'rubocop-performance'
gem 'rubocop-rake'
gem 'webrick'
4 changes: 4 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ GEM
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.31.2)
parser (>= 3.3.0.4)
rubocop-performance (1.23.0)
rubocop (>= 1.48.1, < 2.0)
rubocop-ast (>= 1.31.1, < 2.0)
rubocop-rake (0.6.0)
rubocop (~> 1.0)
ruby-progressbar (1.13.0)
Expand All @@ -61,6 +64,7 @@ DEPENDENCIES
memory_profiler
rake
rubocop
rubocop-performance
rubocop-rake
webrick

Expand Down
2 changes: 1 addition & 1 deletion lib/css_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def self.convert_uris(css, base_uri)
css.gsub(URI_RX) do
uri = Regexp.last_match(1).to_s.gsub(/["']+/, '')
# Don't process URLs that are already absolute
unless uri.match(%r{^[a-z]+://}i)
unless uri.match?(%r{^[a-z]+://}i)
begin
uri = base_uri.join(uri)
rescue
Expand Down
4 changes: 2 additions & 2 deletions lib/css_parser/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ def parse_block_into_rule_sets!(block, options = {}) # :nodoc:
# restart our search for selectors and declarations
rule_start = nil if options[:capture_offsets]
end
elsif token =~ /@media/i
elsif /@media/i.match?(token)
# found '@media', reset current media_types
in_at_media_rule = true
current_media_queries = []
Expand Down Expand Up @@ -718,7 +718,7 @@ def css_node_to_h(hash, key, val)
nodes = {}
lines.each do |line|
parts = line.split(':', 2)
if parts[1] =~ /:/
if /:/.match?(parts[1])
nodes[parts[0]] = css_node_to_h(hash, parts[0], parts[1])
else
nodes[parts[0].to_s.strip] = parts[1].to_s.strip
Expand Down
14 changes: 7 additions & 7 deletions lib/css_parser/rule_set.rb
Original file line number Diff line number Diff line change
Expand Up @@ -455,17 +455,17 @@ def expand_font_shorthand! # :nodoc:
else
font_props['font-family'] = m
end
elsif m =~ /normal|inherit/i
elsif /normal|inherit/i.match?(m)
['font-style', 'font-weight', 'font-variant'].each do |font_prop|
font_props[font_prop] ||= m
end
elsif m =~ /italic|oblique/i
elsif /italic|oblique/i.match?(m)
font_props['font-style'] = m
elsif m =~ /small-caps/i
elsif /small-caps/i.match?(m)
font_props['font-variant'] = m
elsif m =~ /[1-9]00$|bold|bolder|lighter/i
elsif /[1-9]00$|bold|bolder|lighter/i.match?(m)
font_props['font-weight'] = m
elsif m =~ CssParser::FONT_UNITS_RX
elsif CssParser::FONT_UNITS_RX.match?(m)
if m.include?('/')
font_props['font-size'], font_props['line-height'] = m.split('/', 2)
else
Expand All @@ -488,7 +488,7 @@ def expand_list_style_shorthand! # :nodoc:
value = declaration.value.dup

replacement =
if value =~ CssParser::RE_INHERIT
if CssParser::RE_INHERIT.match?(value)
LIST_STYLE_PROPERTIES.to_h { |key| [key, 'inherit'] }
else
{
Expand Down Expand Up @@ -559,7 +559,7 @@ def create_border_shorthand! # :nodoc:
next if declaration.important
# can't merge if any value contains a space (i.e. has multiple values)
# we temporarily remove any spaces after commas for the check (inside rgba, etc...)
next if declaration.value.gsub(/,\s/, ',').strip =~ /\s/
next if /\s/.match?(declaration.value.gsub(/,\s/, ',').strip)

declaration.value
end.compact
Expand Down
Loading