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

Rubocop issue with 0.3.0 #286

Closed
elliotcm opened this issue Nov 2, 2022 · 9 comments · Fixed by #288
Closed

Rubocop issue with 0.3.0 #286

elliotcm opened this issue Nov 2, 2022 · 9 comments · Fixed by #288

Comments

@elliotcm
Copy link

elliotcm commented Nov 2, 2022

As of 0.3.0 we seem to be getting a Rubocop error (not a linting failure, an actual error) on what looks like every erb file in the project:

An error occurred while Lint/RedundantCopEnableDirective cop was inspecting /Users/ellcro/code/apply-for-teacher-training.worktrees/origin/dependabot/bundler/erb_lint-0.3.0/app/components/candidate_interface/application_form_course_choices_component.html.erb.
To see the complete backtrace run rubocop -d.
An error occurred while Lint/MissingCopEnableDirective cop was inspecting /Users/ellcro/code/apply-for-teacher-training.worktrees/origin/dependabot/bundler/erb_lint-0.3.0/app/components/candidate_interface/application_form_course_choices_component.html.erb.
To see the complete backtrace run rubocop -d.

Unfortunately I can't figure a way to get erblint to pass along a debugger option to rubocop so I'm not sure what the cause might be.

This came up during a dependabot update here:
DFE-Digital/apply-for-teacher-training#7638

@davidenglishmusic
Copy link

I started getting this with 0.2.0 having upgraded to Rubocop 1.38.0.

@mattbrictson
Copy link

I'm running into the same problem after upgrading to rubocop 1.38.0.

I was able to get the full exception for the error:

An error occurred while Lint/MissingCopEnableDirective cop was inspecting app/views/shared/_flash.html.erb.
undefined method `disabled' for nil:NilClass

      registry.disabled(config).each do |cop|
              ^^^^^^^^^
rubocop-1.38.0/lib/rubocop/comment_config.rb:94:in `inject_disabled_cops_directives'
rubocop-1.38.0/lib/rubocop/comment_config.rb:78:in `analyze'
rubocop-1.38.0/lib/rubocop/comment_config.rb:45:in `cop_disabled_line_ranges'
rubocop-1.38.0/lib/rubocop/ext/processed_source.rb:14:in `disabled_line_ranges'
rubocop-1.38.0/lib/rubocop/cop/lint/missing_cop_enable_directive.rb:65:in `each_missing_enable'
rubocop-1.38.0/lib/rubocop/cop/lint/missing_cop_enable_directive.rb:52:in `on_new_investigation'
rubocop-1.38.0/lib/rubocop/cop/commissioner.rb:153:in `block (2 levels) in invoke'
rubocop-1.38.0/lib/rubocop/cop/commissioner.rb:160:in `with_cop_error_handling'
rubocop-1.38.0/lib/rubocop/cop/commissioner.rb:153:in `block in invoke'
rubocop-1.38.0/lib/rubocop/cop/commissioner.rb:153:in `each'
rubocop-1.38.0/lib/rubocop/cop/commissioner.rb:153:in `invoke'
rubocop-1.38.0/lib/rubocop/cop/commissioner.rb:84:in `investigate'
rubocop-1.38.0/lib/rubocop/cop/team.rb:154:in `investigate_partial'
rubocop-1.38.0/lib/rubocop/cop/team.rb:82:in `investigate'
erb_lint-0.3.0/lib/erb_lint/linters/rubocop.rb:90:in `activate_team'
erb_lint-0.3.0/lib/erb_lint/linters/rubocop.rb:85:in `inspect_content'
erb_lint-0.3.0/lib/erb_lint/linters/rubocop.rb:35:in `block in run'
better_html-2.0.1/lib/better_html/ast/iterator.rb:12:in `<<'
better_html-2.0.1/lib/better_html/ast/iterator.rb:12:in `block (2 levels) in descendants'
better_html-2.0.1/lib/better_html/ast/iterator.rb:26:in `traverse'
better_html-2.0.1/lib/better_html/ast/iterator.rb:32:in `block in traverse_all'
better_html-2.0.1/lib/better_html/ast/iterator.rb:31:in `each'
better_html-2.0.1/lib/better_html/ast/iterator.rb:31:in `traverse_all'
better_html-2.0.1/lib/better_html/ast/iterator.rb:27:in `traverse'
better_html-2.0.1/lib/better_html/ast/iterator.rb:32:in `block in traverse_all'
better_html-2.0.1/lib/better_html/ast/iterator.rb:31:in `each'
better_html-2.0.1/lib/better_html/ast/iterator.rb:31:in `traverse_all'
better_html-2.0.1/lib/better_html/ast/iterator.rb:27:in `traverse'
better_html-2.0.1/lib/better_html/ast/iterator.rb:13:in `block in descendants'
erb_lint-0.3.0/lib/erb_lint/linters/rubocop.rb:34:in `each'
erb_lint-0.3.0/lib/erb_lint/linters/rubocop.rb:34:in `each'
erb_lint-0.3.0/lib/erb_lint/linters/rubocop.rb:34:in `run'
erb_lint-0.3.0/lib/erb_lint/runner.rb:24:in `block in run'
erb_lint-0.3.0/lib/erb_lint/runner.rb:23:in `each'
erb_lint-0.3.0/lib/erb_lint/runner.rb:23:in `run'
erb_lint-0.3.0/lib/erb_lint/cli.rb:160:in `block in run_with_corrections'
erb_lint-0.3.0/lib/erb_lint/cli.rb:158:in `times'
erb_lint-0.3.0/lib/erb_lint/cli.rb:158:in `run_with_corrections'
erb_lint-0.3.0/lib/erb_lint/cli.rb:129:in `run_on_file'
erb_lint-0.3.0/lib/erb_lint/cli.rb:85:in `block in run'
erb_lint-0.3.0/lib/erb_lint/cli.rb:82:in `each'
erb_lint-0.3.0/lib/erb_lint/cli.rb:82:in `run'
erb_lint-0.3.0/exe/erblint:9:in `<top (required)>'
bin/erblint:27:in `load'
bin/erblint:27:in `<main>'

@brunoprietog
Copy link

I also have this issue

@oehlschl
Copy link

oehlschl commented Nov 9, 2022

Also experiencing this. Is there currently a way to configure the RuboCop linter to fail with a non-zero exit code in this case? (I didn't see one.)

@mvz
Copy link
Contributor

mvz commented Nov 9, 2022

@oehlschl the easiest fix workaround for now is to downgrade RuboCop to version 1.37.1.

@oehlschl
Copy link

oehlschl commented Nov 9, 2022

Thanks @mvz; that makes sense. My hope was that erb-lint would fail loudly and return a non-zero exit code in this case, so this would have been caught in CI when we upgraded rubocop. That said, I can file that as a separate issue / feature request.

@mvz
Copy link
Contributor

mvz commented Nov 9, 2022

I suppose the build failure on the first commit in #283 kind of points to there being a problem with RuboCop 1.38.0 ...

@mishina2228
Copy link

Thanks for releasing v0.3.1!
I hit another error, but it seems to be a failure on the RuboCop side.

An error occurred while Style/RedundantEach cop was inspecting .../app/views/records/_form.html.erb:1:11.
To see the complete backtrace run rubocop -d.
An error occurred while Style/RedundantEach cop was inspecting .../app/views/records/index.html.erb:1:5.
To see the complete backtrace run rubocop -d.

Full trace is here:

An error occurred while Style/RedundantEach cop was inspecting .../app/views/records/_form.html.erb:1:11.
undefined method `block_type?' for nil:NilClass

          if node.method?(:each) && !node.parent.block_type?
                                                ^^^^^^^^^^^^
/home/owner/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.38.0/lib/rubocop/cop/style/redundant_each.rb:64:in `redundant_each_method'
/home/owner/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.38.0/lib/rubocop/cop/style/redundant_each.rb:44:in `on_send'
/home/owner/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.38.0/lib/rubocop/cop/commissioner.rb:136:in `public_send'
/home/owner/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.38.0/lib/rubocop/cop/commissioner.rb:136:in `block (2 levels) in trigger_restricted_cops'
/home/owner/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.38.0/lib/rubocop/cop/commissioner.rb:160:in `with_cop_error_handling'
/home/owner/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.38.0/lib/rubocop/cop/commissioner.rb:135:in `block in trigger_restricted_cops'
/home/owner/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.38.0/lib/rubocop/cop/commissioner.rb:134:in `each'
/home/owner/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.38.0/lib/rubocop/cop/commissioner.rb:134:in `trigger_restricted_cops'
/home/owner/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.38.0/lib/rubocop/cop/commissioner.rb:70:in `on_send'
/home/owner/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-ast-1.23.0/lib/rubocop/ast/traversal.rb:20:in `walk'
/home/owner/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.38.0/lib/rubocop/cop/commissioner.rb:86:in `investigate'
/home/owner/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.38.0/lib/rubocop/cop/team.rb:154:in `investigate_partial'
/home/owner/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.38.0/lib/rubocop/cop/team.rb:76:in `investigate'
/home/owner/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/erb_lint-0.3.1/lib/erb_lint/linters/rubocop.rb:90:in `activate_team'
/home/owner/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/erb_lint-0.3.1/lib/erb_lint/linters/rubocop.rb:85:in `inspect_content'
/home/owner/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/erb_lint-0.3.1/lib/erb_lint/linters/rubocop.rb:35:in `block in run'
/home/owner/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/better_html-2.0.1/lib/better_html/ast/iterator.rb:12:in `<<'
/home/owner/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/better_html-2.0.1/lib/better_html/ast/iterator.rb:12:in `block (2 levels) in descendants'
/home/owner/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/better_html-2.0.1/lib/better_html/ast/iterator.rb:26:in `traverse'
/home/owner/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/better_html-2.0.1/lib/better_html/ast/iterator.rb:32:in `block in traverse_all'
/home/owner/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/better_html-2.0.1/lib/better_html/ast/iterator.rb:31:in `each'
/home/owner/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/better_html-2.0.1/lib/better_html/ast/iterator.rb:31:in `traverse_all'
/home/owner/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/better_html-2.0.1/lib/better_html/ast/iterator.rb:27:in `traverse'
/home/owner/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/better_html-2.0.1/lib/better_html/ast/iterator.rb:32:in `block in traverse_all'
/home/owner/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/better_html-2.0.1/lib/better_html/ast/iterator.rb:31:in `each'
/home/owner/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/better_html-2.0.1/lib/better_html/ast/iterator.rb:31:in `traverse_all'
/home/owner/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/better_html-2.0.1/lib/better_html/ast/iterator.rb:27:in `traverse'
/home/owner/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/better_html-2.0.1/lib/better_html/ast/iterator.rb:13:in `block in descendants'
/home/owner/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/erb_lint-0.3.1/lib/erb_lint/linters/rubocop.rb:34:in `each'
/home/owner/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/erb_lint-0.3.1/lib/erb_lint/linters/rubocop.rb:34:in `each'
/home/owner/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/erb_lint-0.3.1/lib/erb_lint/linters/rubocop.rb:34:in `run'
/home/owner/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/erb_lint-0.3.1/lib/erb_lint/runner.rb:24:in `block in run'
/home/owner/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/erb_lint-0.3.1/lib/erb_lint/runner.rb:23:in `each'
/home/owner/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/erb_lint-0.3.1/lib/erb_lint/runner.rb:23:in `run'
/home/owner/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/erb_lint-0.3.1/lib/erb_lint/cli.rb:160:in `block in run_with_corrections'
/home/owner/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/erb_lint-0.3.1/lib/erb_lint/cli.rb:158:in `times'
/home/owner/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/erb_lint-0.3.1/lib/erb_lint/cli.rb:158:in `run_with_corrections'
/home/owner/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/erb_lint-0.3.1/lib/erb_lint/cli.rb:129:in `run_on_file'
/home/owner/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/erb_lint-0.3.1/lib/erb_lint/cli.rb:85:in `block in run'
/home/owner/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/erb_lint-0.3.1/lib/erb_lint/cli.rb:82:in `each'
/home/owner/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/erb_lint-0.3.1/lib/erb_lint/cli.rb:82:in `run'
/home/owner/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/erb_lint-0.3.1/exe/erblint:9:in `<top (required)>'
/home/owner/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/bin/erblint:25:in `load'
/home/owner/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/bin/erblint:25:in `<top (required)>'
/home/owner/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.3.16/lib/bundler/cli/exec.rb:58:in `load'
/home/owner/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.3.16/lib/bundler/cli/exec.rb:58:in `kernel_load'
/home/owner/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.3.16/lib/bundler/cli/exec.rb:23:in `run'
/home/owner/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.3.16/lib/bundler/cli.rb:479:in `exec'
/home/owner/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.3.16/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
/home/owner/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.3.16/lib/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command'
/home/owner/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.3.16/lib/bundler/vendor/thor/lib/thor.rb:392:in `dispatch'
/home/owner/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.3.16/lib/bundler/cli.rb:31:in `dispatch'
/home/owner/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.3.16/lib/bundler/vendor/thor/lib/thor/base.rb:485:in `start'
/home/owner/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.3.16/lib/bundler/cli.rb:25:in `start'
/home/owner/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.3.16/exe/bundle:48:in `block in <top (required)>'
/home/owner/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.3.16/lib/bundler/friendly_errors.rb:117:in `with_friendly_errors'
/home/owner/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.3.16/exe/bundle:36:in `<top (required)>'
/home/owner/.rbenv/versions/3.1.2/bin/bundle:25:in `load'
/home/owner/.rbenv/versions/3.1.2/bin/bundle:25:in `<main>'

This issue has already been fixed at rubocop/rubocop#11142 but has not yet been released.

@mishina2228
Copy link

I couldn't figure out a smart way to pass the -d flag to RuboCop,
so I solved it in the following not-so-smart way of modifying the erb-lint source directly.

I modified this method

def build_team
::RuboCop::Cop::Team.new(
cop_classes,
@rubocop_config,
extra_details: true,
display_cop_names: true,
autocorrect: true,
auto_correct: true,
stdin: "",
)
end

as follows:

      def build_team
        ::RuboCop::Cop::Team.new(
          cop_classes,
          @rubocop_config,
          extra_details: true,
          display_cop_names: true,
          autocorrect: true,
          auto_correct: true,
          stdin: "",
          debug: true, # inserted
        )
      end

Please let me know if there is a correct way to get RuboCop debug info...

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

Successfully merging a pull request may close this issue.

7 participants