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
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
ruby-version: ['3.0', '3.1', '3.2', '3.3', '3.4', 'jruby']
ruby-version: ['3.3', '3.4', 'jruby']

steps:
- uses: actions/checkout@v4
Expand All @@ -35,7 +35,7 @@ jobs:

- uses: ruby/setup-ruby@v1
with:
ruby-version: '3.0' # lowest supported Ruby version
ruby-version: '3.3' # lowest supported Ruby version
bundler-cache: true

- run: bundle exec rake rubocop
11 changes: 10 additions & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ require:
- rubocop-rake

AllCops:
TargetRubyVersion: 3.0 # lowest supported version
TargetRubyVersion: 3.3 # lowest supported version
NewCops: enable

Layout/ArgumentAlignment:
Expand Down Expand Up @@ -79,3 +79,12 @@ Style/WordArray:

Style/SymbolArray:
EnforcedStyle: brackets

Style/HashSyntax:
EnforcedShorthandSyntax: never

Naming/BlockForwarding:
EnforcedStyle: explicit

Style/CollectionQuerying:
Enabled: false
4 changes: 3 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ gem 'benchmark-ips'
gem 'bump'
gem 'maxitest'
gem 'memory_profiler'
gem 'mocha'
gem 'ostruct'
gem 'rake'
gem 'rubocop'
gem 'rubocop', '~> 1.84.2' # locked down so we don't get accidental new cops
gem 'rubocop-performance'
gem 'rubocop-rake'
gem 'webrick'
83 changes: 48 additions & 35 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,50 +7,61 @@ PATH
GEM
remote: https://rubygems.org/
specs:
addressable (2.8.6)
public_suffix (>= 2.0.2, < 6.0)
ast (2.4.2)
benchmark-ips (2.13.0)
addressable (2.8.8)
public_suffix (>= 2.0.2, < 8.0)
ast (2.4.3)
benchmark-ips (2.14.0)
bump (0.10.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)
json (2.18.1)
json (2.18.1-java)
language_server-protocol (3.17.0.5)
lint_roller (1.1.0)
maxitest (7.1.1)
minitest (>= 6.0.0, < 6.1.0)
memory_profiler (1.1.0)
minitest (6.0.1)
prism (~> 1.5)
mocha (3.0.2)
ruby2_keywords (>= 0.0.5)
ostruct (0.6.3)
parallel (1.27.0)
parser (3.3.10.2)
ast (~> 2.4.1)
racc
public_suffix (5.0.5)
racc (1.7.3)
racc (1.7.3-java)
prism (1.9.0)
public_suffix (7.0.2)
racc (1.8.1)
racc (1.8.1-java)
rainbow (3.1.1)
rake (13.2.1)
regexp_parser (2.9.0)
rexml (3.2.6)
rubocop (1.62.1)
rake (13.3.1)
regexp_parser (2.11.3)
rubocop (1.84.2)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
language_server-protocol (~> 3.17.0.2)
lint_roller (~> 1.1.0)
parallel (~> 1.10)
parser (>= 3.3.0.2)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
rexml (>= 3.2.5, < 4.0)
rubocop-ast (>= 1.31.1, < 2.0)
regexp_parser (>= 2.9.3, < 3.0)
rubocop-ast (>= 1.49.0, < 2.0)
ruby-progressbar (~> 1.7)
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)
unicode-display_width (>= 2.4.0, < 4.0)
rubocop-ast (1.49.0)
parser (>= 3.3.7.2)
prism (~> 1.7)
rubocop-performance (1.26.1)
lint_roller (~> 1.1)
rubocop (>= 1.75.0, < 2.0)
rubocop-ast (>= 1.47.1, < 2.0)
rubocop-rake (0.7.1)
lint_roller (~> 1.1)
rubocop (>= 1.72.1)
ruby-progressbar (1.13.0)
unicode-display_width (2.5.0)
webrick (1.8.1)
ruby2_keywords (0.0.5)
unicode-display_width (3.2.0)
unicode-emoji (~> 4.1)
unicode-emoji (4.2.0)
webrick (1.9.2)

PLATFORMS
java
Expand All @@ -62,8 +73,10 @@ DEPENDENCIES
css_parser!
maxitest
memory_profiler
mocha
ostruct
rake
rubocop
rubocop (~> 1.84.2)
rubocop-performance
rubocop-rake
webrick
Expand Down
4 changes: 2 additions & 2 deletions css_parser.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ Gem::Specification.new name, CssParser::VERSION do |s|
s.author = 'Alex Dunae'
s.files = Dir.glob('lib/**/*') + ['MIT-LICENSE']
s.license = 'MIT'
s.required_ruby_version = '>= 3.0'
s.required_ruby_version = '>= 3.3'

s.metadata['changelog_uri'] = 'https://github.com/premailer/css_parser/blob/master/CHANGELOG.md'
s.metadata['source_code_uri'] = 'https://github.com/premailer/css_parser'
s.metadata['bug_tracker_uri'] = 'https://github.com/premailer/css_parser/issues'
s.metadata['rubygems_mfa_required'] = 'true'

s.add_runtime_dependency 'addressable'
s.add_dependency 'addressable'
end
5 changes: 3 additions & 2 deletions lib/css_parser/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def add_block!(block, options = {})
media_types = [:all]
end

next unless options[:only_media_types].include?(:all) or media_types.empty? or !(media_types & options[:only_media_types]).empty?
next unless options[:only_media_types].include?(:all) or media_types.empty? or media_types.intersect?(options[:only_media_types])

import_path = import_rule[0].to_s.gsub(/['"]*/, '').strip

Expand Down Expand Up @@ -568,7 +568,8 @@ def load_string!(src, options = {}, deprecated = nil)
#
# Raises a CircularReferenceError exception if io_exceptions are on,
# otherwise returns true/false.
def circular_reference_check(path)
# TODO: fix rubocop
def circular_reference_check(path) # rubocop:disable Naming/PredicateMethod
path = path.to_s
if @loaded_uris.include?(path)
raise CircularReferenceError, "can't load #{path} more than once" if @options[:io_exceptions]
Expand Down
11 changes: 4 additions & 7 deletions test/rule_set/test_declarations.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# frozen_string_literal: true

require_relative '../test_helper'
require 'minitest/spec'

class RuleSetDeclarationsTest < Minitest::Test
describe '.new' do
Expand Down Expand Up @@ -382,14 +381,12 @@ class RuleSetDeclarationsTest < Minitest::Test

declarations = CssParser::RuleSet::Declarations.new({foo: foo_value, bar: bar_value, baz: baz_value})

mock = Minitest::Mock.new
mock.expect :call, true, ['foo', foo_value]
mock.expect :call, true, ['bar', bar_value]
mock.expect :call, true, ['baz', baz_value]
mock = stub("Fake")
mock.expects(:call).with('foo', foo_value).returns(true)
mock.expects(:call).with('bar', bar_value).returns(true)
mock.expects(:call).with('baz', baz_value).returns(true)

declarations.each { |name, value| mock.call(name, value) }

assert_mock mock
end
end
end
Expand Down
5 changes: 3 additions & 2 deletions test/test_css_parser_misc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,10 @@ def test_enumerator_nonempty
end
end

def with_value_exception(&block)
def with_value_exception
# Raise synthetic exception to test error handling because there is no known way to cause it naturally
CssParser::RuleSet::Declarations::Value.stub :new, -> { raise ArgumentError.new, 'stub' }, &block
CssParser::RuleSet::Declarations::Value.stubs(:new).raises(ArgumentError.new('stub'))
yield # TODO: do not pass a block instead
end

def test_catching_argument_exceptions_for_add_rule
Expand Down
2 changes: 2 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

require 'bundler/setup'
require 'maxitest/autorun'
require 'mocha/minitest'
require 'ostruct'
require 'net/http'
require 'webrick'
require 'css_parser'
3 changes: 1 addition & 2 deletions test/test_rule_set.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# frozen_string_literal: true

require_relative 'test_helper'
require "set"

# Test cases for parsing CSS blocks
class RuleSetTests < Minitest::Test
Expand Down Expand Up @@ -81,7 +80,7 @@ def test_each_declaration_containing_semicolons
def test_each_declaration_with_newlines
expected = Set[
{property: 'background-image', value: 'url(foo;bar)', is_important: false},
{property: 'font-weight', value: 'bold', is_important: true},
{property: 'font-weight', value: 'bold', is_important: true}
]
rs = RuleSet.new(block: "background-image\n:\nurl(foo;bar);\n\n\n\n\n;;font-weight\n\n\n:bold\n\n\n!important")
actual = Set.new
Expand Down