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

[1.28.0] ClassLength (and cops that rely on CodeLengthCalculator) crash on methods without parens #10559

Closed
Darhazer opened this issue Apr 21, 2022 · 0 comments · Fixed by #10561
Labels

Comments

@Darhazer
Copy link
Member

The changes in #10543 introduced a crash, when the send node omits parenthesis


Spec to reproduce:

      it 'counts single line correctly if asked folding' do
        source = parse_source(<<~RUBY)
          def test
            foo foo: :bar, baz: :quux
          end
        RUBY

        length = described_class.new(source.ast, source, foldable_types: %i[hash]).calculate
        expect(length).to eq(1)
      end

Expected behavior

Spec to pass

Actual behavior

     Failure/Error: parent.loc.begin.end_pos != descendant.loc.expression.begin_pos,
     
     NoMethodError:
       undefined method `end_pos' for nil:NilClass
     # ./lib/rubocop/cop/metrics/utils/code_length_calculator.rb:162:in `omit_length'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
1 participant