Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(on master only!) empty block generates an error #194

Closed
flavorjones opened this issue Nov 4, 2022 · 1 comment
Closed

(on master only!) empty block generates an error #194

flavorjones opened this issue Nov 4, 2022 · 1 comment

Comments

@flavorjones
Copy link
Contributor

flavorjones commented Nov 4, 2022

After 7d612d7 an error is raised when a set has an empty block.

Steps to reproduce the problem

The following test exists in the Nokogiri code base:

      def test_read_error_document
        reader = Nokogiri::XML::Reader.from_memory(<<-eoxml)
        <x xmlns:tenderlove='http://tenderlovemaking.com/'>
          <tenderlove:foo awesome='true'>snuggles!</tenderlove:foo>
          <foo>
        </x>
        eoxml
        assert_raises(Nokogiri::XML::SyntaxError) do
          reader.each { |node| }
        end
        assert_equal(1, reader.errors.length)
      end

The key line is

reader.each { |node| }

This strange syntax is used to intentionally pass a block without any side effects to the method, because this particular test is focused on advancing the Reader's cursor and ensuring parse errors are handled.

After the fix in 7d612d7 the following exception is raised:

rubocop -d /home/flavorjones/code/oss/nokogiri/test/xml/test_reader.rb
For /home/flavorjones/code/oss/nokogiri: configuration from /home/flavorjones/code/oss/nokogiri/.rubocop.yml
configuration from /home/flavorjones/code/oss/rubocop-minitest/config/default.yml
configuration from /home/flavorjones/code/oss/rubocop-minitest/config/default.yml
Default configuration from /home/flavorjones/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.37.1/config/default.yml
configuration from /home/flavorjones/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-performance-1.15.0/config/default.yml
configuration from /home/flavorjones/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-performance-1.15.0/config/default.yml
configuration from /home/flavorjones/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-rake-0.6.0/config/default.yml
configuration from /home/flavorjones/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-rake-0.6.0/config/default.yml
Inheriting configuration from /home/flavorjones/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-shopify-2.9.0/rubocop.yml
Inheriting configuration from /home/flavorjones/code/oss/nokogiri/.rubocop_todo.yml
Use parallel by default.
Skipping parallel inspection: only a single file needs inspection
Inspecting 1 file
Scanning /home/flavorjones/code/oss/nokogiri/test/xml/test_reader.rb
An error occurred while Minitest/EmptyLineBeforeAssertionMethods cop was inspecting /home/flavorjones/code/oss/nokogiri/test/xml/test_reader.rb:206:10.
undefined method `send_type?' for nil:NilClass

        return false unless node.send_type?
                                ^^^^^^^^^^^
/home/flavorjones/code/oss/rubocop-minitest/lib/rubocop/cop/mixin/minitest_exploration_helpers.rb:81:in `assertion_method?'
/home/flavorjones/code/oss/rubocop-minitest/lib/rubocop/cop/minitest/empty_line_before_assertion_methods.rb:42:in `assertion_method'
/home/flavorjones/code/oss/rubocop-minitest/lib/rubocop/cop/minitest/empty_line_before_assertion_methods.rb:26:in `on_send'
/home/flavorjones/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.37.1/lib/rubocop/cop/commissioner.rb:100:in `public_send'
/home/flavorjones/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.37.1/lib/rubocop/cop/commissioner.rb:100:in `block (2 levels) in trigger_responding_cops'

...

.

1 file inspected, no offenses detected

1 error occurred:
An error occurred while Minitest/EmptyLineBeforeAssertionMethods cop was inspecting /home/flavorjones/code/oss/nokogiri/test/xml/test_reader.rb:206:10.
Errors are usually caused by RuboCop bugs.
Please, report your problems to RuboCop's issue tracker.
https://github.com/rubocop/rubocop/issues

Mention the following information in the issue report:
1.37.1 (using Parser 3.1.2.1, rubocop-ast 1.23.0, running on ruby 3.1.2) [x86_64-linux]
Finished in 0.6805142869998235 seconds

There is at least one other place in the Nokogiri suite where we pass an empty block, so I imagine other projects may be (rarely) doing something similar.

RuboCop version

×1 $ be rubocop -V
1.37.1 (using Parser 3.1.2.1, rubocop-ast 1.23.0, running on ruby 3.1.2) [x86_64-linux]
  - rubocop-minitest 0.23.0
  - rubocop-performance 1.15.0
  - rubocop-rake 0.6.0

(note that the rubocop-minitest version is incorrect, I've run the above using e3b4936)

koic added a commit to koic/rubocop-minitest that referenced this issue Nov 4, 2022
…ssertionMethods`

Fixes rubocop#189 and rubocop#194.

This PR fixes a false negative for `Minitest/EmptyLineBeforeAssertionMethods`
when using assertion method used in block before assertion method.
@koic
Copy link
Member

koic commented Nov 4, 2022

Thank you for your early feedback. This issue will be resolved by #195.

@koic koic closed this as completed Nov 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants