Skip to content

Commit

Permalink
style(rubocop): correct new cops
Browse files Browse the repository at this point in the history
- Style/TrailingCommaInArguments
- Style/MagicCommentFormat
- Lint/MissingCopEnableDirective
  • Loading branch information
flavorjones committed Jan 16, 2023
1 parent 8736373 commit b910c6a
Show file tree
Hide file tree
Showing 26 changed files with 56 additions and 50 deletions.
2 changes: 2 additions & 0 deletions ext/nokogiri/extconf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1080,3 +1080,5 @@ def compile
EOF
end
end

# rubocop:enable Style/GlobalVars
2 changes: 1 addition & 1 deletion lib/nokogiri/decorators/slop.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def method_missing(name, *args, &block)
else
CSS::Parser.without_cache do
list = xpath(
*CSS.xpath_for("#{name}#{args.first}", prefix: XPATH_PREFIX)
*CSS.xpath_for("#{name}#{args.first}", prefix: XPATH_PREFIX),
)
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/nokogiri/xml/document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,8 @@ def empty_doc?(string_or_io)
# Since v1.12.4
attr_accessor :namespace_inheritance

# rubocop:disable Lint/MissingSuper
def initialize(*args) # :nodoc:
# :nodoc:
def initialize(*args) # rubocop:disable Lint/MissingSuper
@errors = []
@decorators = nil
@namespace_inheritance = false
Expand Down
2 changes: 2 additions & 0 deletions rakelib/check-manifest.rake
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,5 @@ task :check_manifest, [:verbose] do |_, args|
extra_files.sort.each { |f| puts "+ #{f}" }
end
end

# rubocop:enable Style/WordArray
4 changes: 2 additions & 2 deletions scripts/test-gem-file-contents
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ gemspec = Dir.mktmpdir do |dir|

YAML.safe_load(
%x(gunzip -c metadata.gz),
permitted_classes: [Gem::Specification, Gem::Version, Gem::Dependency, Gem::Requirement, Time, Symbol]
permitted_classes: [Gem::Specification, Gem::Version, Gem::Dependency, Gem::Requirement, Time, Symbol],
)
end
end
Expand Down Expand Up @@ -286,7 +286,7 @@ describe File.basename(gemfile) do
assert_equal(
1,
actual_jars.count { |j| File.fnmatch?("lib/nokogiri/jruby/**/#{name}-*.jar", j) },
"expected to contain '#{name}-*.jar'"
"expected to contain '#{name}-*.jar'",
)
end
end
Expand Down
10 changes: 5 additions & 5 deletions test/css/test_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class TestNokogiri < Nokogiri::TestCase
[:CONDITIONAL_SELECTOR,
[:ELEMENT_NAME],
[:PSEUDO_CLASS,
[:FUNCTION],],]
[:FUNCTION],],],
)
assert_equal(1, matches.length)
assert_equal(ast, matches.first)
Expand All @@ -25,7 +25,7 @@ class TestNokogiri < Nokogiri::TestCase
[:ELEMENT_NAME],
[:PSEUDO_CLASS,
[:FUNCTION],],],
ast.to_type
ast.to_type,
)
end

Expand All @@ -36,7 +36,7 @@ class TestNokogiri < Nokogiri::TestCase
[:ELEMENT_NAME, ["a"]],
[:PSEUDO_CLASS,
[:FUNCTION, ["nth-child("], ["2"]],],],
asts.first.to_a
asts.first.to_a,
)
end

Expand All @@ -49,15 +49,15 @@ class TestNokogiri < Nokogiri::TestCase
[:ATTRIB_NAME, ["class"]],
[:includes],
["bar"],],],
ast.to_a
ast.to_a,
)
end

it "parses xpath attributes" do
ast = parser.parse("a/@href").first
assert_equal(
[:CHILD_SELECTOR, [:ELEMENT_NAME, ["a"]], [:ATTRIB_NAME, ["href"]]],
ast.to_a
ast.to_a,
)
end

Expand Down
2 changes: 1 addition & 1 deletion test/css/test_tokenizer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def test_has
@scanner.scan("a:has(b)")
assert_tokens(
[[:IDENT, "a"], [":", ":"], [:HAS, "has("], [:IDENT, "b"], [:RPAREN, ")"]],
@scanner
@scanner,
)
end

Expand Down
10 changes: 6 additions & 4 deletions test/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -126,18 +126,18 @@ class TestBenchmark < Minitest::BenchSpec
extend TestBase
end

# rubocop:disable Style/ClassVars
class TestCase < MiniTest::Spec
include TestBase

COMPACT_EVERY = 20
@@test_count = 0 # rubocop:disable Style/ClassVars
@@gc_level = nil # rubocop:disable Style/ClassVars
@@test_count = 0
@@gc_level = nil

def initialize_nokogiri_test_gc_level
return if Nokogiri.jruby?
return if @@gc_level

# rubocop:disable Style/ClassVars
@@gc_level = if ["stress", "major", "minor", "normal"].include?(ENV["NOKOGIRI_TEST_GC_LEVEL"])
ENV["NOKOGIRI_TEST_GC_LEVEL"]
elsif (ENV["NOKOGIRI_TEST_GC_LEVEL"] == "compact") && defined?(GC.compact)
Expand All @@ -151,6 +151,7 @@ def initialize_nokogiri_test_gc_level
else
"major"
end

if ["compact", "verify"].include?(@@gc_level)
# the only way of detecting an unsupported platform is actually
# trying GC compaction
Expand All @@ -167,7 +168,7 @@ def initialize_nokogiri_test_gc_level
def setup
initialize_nokogiri_test_gc_level

@@test_count += 1 # rubocop:disable Style/ClassVars
@@test_count += 1
if Nokogiri.uses_libxml?
@fake_error_handler_called = false
Nokogiri::Test.__foreign_error_handler do
Expand Down Expand Up @@ -278,6 +279,7 @@ def pending_if(msg, pend_eh, &block)
pending(msg, &block)
end
end
# rubocop:enable Style/ClassVars

module SAX
class TestCase < Nokogiri::TestCase
Expand Down
4 changes: 2 additions & 2 deletions test/html4/test_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def test_has_ampersand
end
assert_equal(
'<div class="rad" id="thing">&lt;awe&amp;some&gt;<b>hello &amp; world</b></div>',
builder.doc.root.to_html.delete("\n")
builder.doc.root.to_html.delete("\n"),
)
end

Expand All @@ -89,7 +89,7 @@ def test_multi_tags
end
assert_equal(
'<div class="rad" id="thing">&lt;awesome&gt;<b>hello</b></div>',
builder.doc.root.to_html.delete("\n")
builder.doc.root.to_html.delete("\n"),
)
end

Expand Down
6 changes: 3 additions & 3 deletions test/html4/test_document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ def test_parse_temp_file
temp_html_file.open
assert_equal(
Nokogiri::HTML4.parse(File.read(HTML_FILE)).xpath("//div/a").length,
Nokogiri::HTML4.parse(temp_html_file).xpath("//div/a").length
Nokogiri::HTML4.parse(temp_html_file).xpath("//div/a").length,
)
end

Expand Down Expand Up @@ -437,7 +437,7 @@ def test_doc_type
assert_equal("http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd", html.internal_subset.system_id)
assert_equal(
"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\" \"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\">",
html.to_s[0, 97]
html.to_s[0, 97],
)
end

Expand Down Expand Up @@ -865,7 +865,7 @@ def initialize(*args)
doc = klass.new("http://www.w3.org/TR/REC-html40/loose.dtd", "-//W3C//DTD HTML 4.0 Transitional//EN")
assert_equal(
["http://www.w3.org/TR/REC-html40/loose.dtd", "-//W3C//DTD HTML 4.0 Transitional//EN"],
doc.initialized_with
doc.initialized_with,
)
end
end
Expand Down
2 changes: 1 addition & 1 deletion test/html4/test_document_encoding.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def test_encoding_non_utf8
text = Nokogiri::HTML4.parse(html).at("title").inner_text
assert_equal(
orig.encode(enc).force_encoding(bin),
text.encode(enc).force_encoding(bin)
text.encode(enc).force_encoding(bin),
)
end
end
Expand Down
2 changes: 1 addition & 1 deletion test/html5/test_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ def initialize(*args)
doc = klass.new("http://www.w3.org/TR/REC-html40/loose.dtd", "-//W3C//DTD HTML 4.0 Transitional//EN")
assert_equal(
["http://www.w3.org/TR/REC-html40/loose.dtd", "-//W3C//DTD HTML 4.0 Transitional//EN"],
doc.initialized_with
doc.initialized_with,
)
end
end
Expand Down
2 changes: 1 addition & 1 deletion test/test_css_cache.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def test_cache_key_on_ns_prefix_and_visitor_config
Nokogiri::CSS.xpath_for("foo", prefix: ".//", ns: { "example" => "http://example.com/" })
Nokogiri::CSS.xpath_for("foo", prefix: ".//", ns: { "example" => "http://example.com/" },
visitor: Nokogiri::CSS::XPathVisitor.new(
builtins: Nokogiri::CSS::XPathVisitor::BuiltinsConfig::ALWAYS
builtins: Nokogiri::CSS::XPathVisitor::BuiltinsConfig::ALWAYS,
))
Nokogiri::CSS.xpath_for("foo", prefix: ".//", ns: { "example" => "http://example.com/" },
visitor: Nokogiri::CSS::XPathVisitor.new(
Expand Down
6 changes: 3 additions & 3 deletions test/test_xslt_transforms.rb
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ def test_exslt
if Nokogiri::VersionInfo.instance.libxslt_has_datetime?
assert_match(
/\d{4}-\d\d-\d\d([-|+]\d\d:\d\d)?/,
result_doc.at("/root/date").content
result_doc.at("/root/date").content,
)
end
result_doc.xpath("/root/params/*").each do |p|
Expand Down Expand Up @@ -352,12 +352,12 @@ def test_non_html_xslt_transform
if truffleruby_system_libraries?
assert_equal(
"xslt_generic_error_handler: xmlXPathCompOpEval: function %s not found\nxslt_generic_error_handler: %s",
exception.message
exception.message,
)
else
assert_match(
/xmlXPathCompOpEval: function decimal not found|java.lang.NoSuchMethodException.*decimal/,
exception.message
exception.message,
)
end
end
Expand Down
8 changes: 4 additions & 4 deletions test/xml/sax/test_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ class TestCase
EOF
assert_equal(
["root", "foo:f", "bar"],
parser.document.start_elements.map(&:first)
parser.document.start_elements.map(&:first),
)
end

Expand Down Expand Up @@ -337,7 +337,7 @@ def call_parse_io_with_encoding(encoding)
EOF
assert_equal(
[["p", [["xmlns:foo", "http://foo.example.com/"]]]],
parser.document.start_elements
parser.document.start_elements,
)
end

Expand All @@ -348,7 +348,7 @@ def call_parse_io_with_encoding(encoding)
EOF
assert_equal(
[["xml-stylesheet", 'href="a.xsl" type="text/xsl"']],
parser.document.processing_instructions
parser.document.processing_instructions,
)
end

Expand Down Expand Up @@ -393,7 +393,7 @@ def call_parse_io_with_encoding(encoding)

assert_equal(
[["Root", []], ["Data", []], ["Item", []], ["Data", []], ["Item", []]],
parser.document.start_elements
parser.document.start_elements,
)
end

Expand Down
2 changes: 1 addition & 1 deletion test/xml/test_attribute_decl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def setup
def test_inspect
assert_equal(
"#<#{@attr_decl.class.name}:#{format("0x%x", @attr_decl.object_id)} #{@attr_decl.to_s.inspect}>",
@attr_decl.inspect
@attr_decl.inspect,
)
end

Expand Down
6 changes: 3 additions & 3 deletions test/xml/test_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def test_builder_namespace_inheritance_true
assert(result.doc.namespace_inheritance)
assert(
result.doc.at_xpath("//soapenv:Header", "soapenv" => "http://schemas.xmlsoap.org/soap/envelope/"),
"header element should have a namespace"
"header element should have a namespace",
)
end

Expand All @@ -155,7 +155,7 @@ def test_builder_namespace_inheritance_false
refute(result.doc.namespace_inheritance)
assert(
result.doc.at_xpath("//Header"),
"header element should not have a namespace"
"header element should not have a namespace",
)
end

Expand Down Expand Up @@ -196,7 +196,7 @@ def test_dtd_in_builder_output
xml.doc.create_internal_subset(
"html",
"-//W3C//DTD HTML 4.01 Transitional//EN",
"http://www.w3.org/TR/html4/loose.dtd"
"http://www.w3.org/TR/html4/loose.dtd",
)
xml.root do
xml.foo
Expand Down
4 changes: 2 additions & 2 deletions test/xml/test_c14n.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ def test_exclude_block_params
if Nokogiri.jruby?
assert_equal(
["a", "document", "document", nil, "b", "a"],
list.flatten.map { |x| x ? x.name : x }
list.flatten.map { |x| x ? x.name : x },
)
else
assert_equal(
["a", "document", "document", nil, "b", "a", "a", "document"],
list.flatten.map { |x| x ? x.name : x }
list.flatten.map { |x| x ? x.name : x },
)
end
end
Expand Down
2 changes: 1 addition & 1 deletion test/xml/test_document_fragment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def test_xml_fragment_with_leading_whitespace_and_newline

def test_fragment_children_search
fragment = Nokogiri::XML::Document.new.fragment(
'<div><p id="content">hi</p></div>'
'<div><p id="content">hi</p></div>',
)
expected = fragment.children.xpath(".//p")
assert_equal(1, expected.length)
Expand Down
2 changes: 1 addition & 1 deletion test/xml/test_element_decl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def test_inspect
e = @elements.first
assert_equal(
"#<#{e.class.name}:#{format("0x%x", e.object_id)} #{e.to_s.inspect}>",
e.inspect
e.inspect,
)
end

Expand Down
2 changes: 1 addition & 1 deletion test/xml/test_entity_decl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def test_line
def test_inspect
assert_equal(
"#<#{@entity_decl.class.name}:#{format("0x%x", @entity_decl.object_id)} #{@entity_decl.to_s.inspect}>",
@entity_decl.inspect
@entity_decl.inspect,
)
end
end
Expand Down
2 changes: 1 addition & 1 deletion test/xml/test_node_encoding.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# encoding: UTF-8
# encoding: utf-8
# frozen_string_literal: true

require "helper"
Expand Down
Loading

0 comments on commit b910c6a

Please sign in to comment.