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

An error occurred while Packaging/RequireHardcodingLib cop was inspecting file #44

Closed
ShockwaveNN opened this issue Aug 5, 2022 · 18 comments

Comments

@ShockwaveNN
Copy link

ShockwaveNN commented Aug 5, 2022

Hi, seems with latest update of rubocop to v1.33.0 some changes introduced and rubocop-packaging started to fail

Error looks like this:

Scanning /home/lobashov/sources/onlyoffice_webdriver_wrapper/spec/webdriver_spec.rb
An error occurred while Packaging/RequireHardcodingLib cop was inspecting /home/lobashov/sources/onlyoffice_webdriver_wrapper/spec/webdriver_spec.rb:3:0.
undefined method `project_root' for RuboCop::ConfigLoader:Class

        RuboCop::ConfigLoader.project_root
                             ^^^^^^^^^^^^^
/home/lobashov/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-packaging-0.5.1/lib/rubocop/packaging/lib_helper_module.rb:10:in `root_dir'
/home/lobashov/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-packaging-0.5.1/lib/rubocop/packaging/lib_helper_module.rb:15:in `target_falls_in_lib?'
/home/lobashov/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-packaging-0.5.1/lib/rubocop/cop/packaging/require_hardcoding_lib.rb:87:in `falls_in_lib?'
/home/lobashov/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-packaging-0.5.1/lib/rubocop/cop/packaging/require_hardcoding_lib.rb:55:in `require?'
/home/lobashov/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-packaging-0.5.1/lib/rubocop/cop/packaging/require_hardcoding_lib.rb:68:in `on_send'
/home/lobashov/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.33.0/lib/rubocop/cop/commissioner.rb:100:in `public_send'
/home/lobashov/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.33.0/lib/rubocop/cop/commissioner.rb:100:in `block (2 levels) in trigger_responding_cops'
/home/lobashov/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.33.0/lib/rubocop/cop/commissioner.rb:160:in `with_cop_error_handling'
/home/lobashov/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.33.0/lib/rubocop/cop/commissioner.rb:99:in `block in trigger_responding_cops'
/home/lobashov/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.33.0/lib/rubocop/cop/commissioner.rb:98:in `each'
/home/lobashov/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.33.0/lib/rubocop/cop/commissioner.rb:98:in `trigger_responding_cops'
/home/lobashov/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.33.0/lib/rubocop/cop/commissioner.rb:69:in `on_send'
/home/lobashov/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-ast-1.19.1/lib/rubocop/ast/traversal.rb:136:in `block in on_dstr'
/home/lobashov/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-ast-1.19.1/lib/rubocop/ast/traversal.rb:136:in `each'
/home/lobashov/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-ast-1.19.1/lib/rubocop/ast/traversal.rb:136:in `on_dstr'
/home/lobashov/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.33.0/lib/rubocop/cop/commissioner.rb:71:in `on_begin'
/home/lobashov/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-ast-1.19.1/lib/rubocop/ast/traversal.rb:20:in `walk'
/home/lobashov/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.33.0/lib/rubocop/cop/commissioner.rb:86:in `investigate'
/home/lobashov/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.33.0/lib/rubocop/cop/team.rb:155:in `investigate_partial'
/home/lobashov/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.33.0/lib/rubocop/cop/team.rb:83:in `investigate'
/home/lobashov/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.33.0/lib/rubocop/runner.rb:311:in `inspect_file'
/home/lobashov/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.33.0/lib/rubocop/runner.rb:255:in `block in do_inspection_loop'
/home/lobashov/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.33.0/lib/rubocop/runner.rb:289:in `block in iterate_until_no_changes'
/home/lobashov/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.33.0/lib/rubocop/runner.rb:282:in `loop'
/home/lobashov/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.33.0/lib/rubocop/runner.rb:282:in `iterate_until_no_changes'
/home/lobashov/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.33.0/lib/rubocop/runner.rb:251:in `do_inspection_loop'
/home/lobashov/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.33.0/lib/rubocop/runner.rb:134:in `block in file_offenses'
/home/lobashov/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.33.0/lib/rubocop/runner.rb:159:in `file_offense_cache'
/home/lobashov/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.33.0/lib/rubocop/runner.rb:133:in `file_offenses'
/home/lobashov/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.33.0/lib/rubocop/runner.rb:124:in `process_file'
/home/lobashov/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.33.0/lib/rubocop/runner.rb:105:in `block in each_inspected_file'
/home/lobashov/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.33.0/lib/rubocop/runner.rb:104:in `each'
/home/lobashov/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.33.0/lib/rubocop/runner.rb:104:in `reduce'
/home/lobashov/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.33.0/lib/rubocop/runner.rb:104:in `each_inspected_file'
/home/lobashov/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.33.0/lib/rubocop/runner.rb:90:in `inspect_files'
/home/lobashov/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.33.0/lib/rubocop/runner.rb:47:in `run'
/home/lobashov/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.33.0/lib/rubocop/cli/command/execute_runner.rb:26:in `block in execute_runner'
/home/lobashov/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.33.0/lib/rubocop/cli/command/execute_runner.rb:52:in `with_redirect'
/home/lobashov/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.33.0/lib/rubocop/cli/command/execute_runner.rb:25:in `execute_runner'
/home/lobashov/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.33.0/lib/rubocop/cli/command/execute_runner.rb:17:in `run'
/home/lobashov/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.33.0/lib/rubocop/cli/command.rb:11:in `run'
/home/lobashov/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.33.0/lib/rubocop/cli/environment.rb:18:in `run'
/home/lobashov/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.33.0/lib/rubocop/cli.rb:72:in `run_command'
/home/lobashov/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.33.0/lib/rubocop/cli.rb:79:in `execute_runners'
/home/lobashov/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.33.0/lib/rubocop/cli.rb:48:in `run'
/home/lobashov/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.33.0/exe/rubocop:19:in `block in <top (required)>'
/home/lobashov/.rbenv/versions/3.1.2/lib/ruby/3.1.0/benchmark.rb:311:in `realtime'
/home/lobashov/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.33.0/exe/rubocop:19:in `<top (required)>'
/home/lobashov/.rbenv/versions/3.1.2/bin/rubocop:25:in `load'
/home/lobashov/.rbenv/versions/3.1.2/bin/rubocop:25:in `<main>'

You can reproduce it on my project onlyoffice_webdriver_wrapper

  1. git clone https://github.com/ONLYOFFICE-QA/onlyoffice_webdriver_wrapper.git
  2. cd onlyoffice_webdriver_wrapper && bundle update
  3. rubocop -d

There will be countless failures

Env:

1.33.0 (using Parser 3.1.2.0, rubocop-ast 1.19.1, running on ruby 3.1.2 x86_64-linux)
@ShockwaveNN
Copy link
Author

ShockwaveNN commented Aug 5, 2022

Reported this issue to main rubocop team just in case

koic added a commit to koic/rubocop-packaging that referenced this issue Aug 5, 2022
Fixes utkarsh2102#44.

Fix a build error when using RuboCop 1.33+.

The upstream will be resolved by the release of rubocop/rubocop#10872.
Aprt from that, this patch can be resolved by RuboCop::Packaging alone
independently from the upstream.
koic added a commit to koic/rubocop-packaging that referenced this issue Aug 5, 2022
Fixes utkarsh2102#44.

Fix a build error when using RuboCop 1.33+.

The upstream will be resolved by the release of rubocop/rubocop#10872.
Apart from that, this patch can be resolved by RuboCop::Packaging alone
independently from the upstream.
koic added a commit to koic/rubocop-packaging that referenced this issue Aug 5, 2022
Fixes utkarsh2102#44.

Fix a build error when using RuboCop 1.33+.

The upstream will be resolved by the release of rubocop/rubocop#10872.
Apart from that, this patch can be resolved by RuboCop::Packaging alone
independently from the upstream.
@koic
Copy link
Collaborator

koic commented Aug 5, 2022

This issue has been fixed by #43.

@ShockwaveNN
Copy link
Author

@koic Thanks for the quickest response )

@koic
Copy link
Collaborator

koic commented Aug 5, 2022

@ShockwaveNN You are welcome! Thank you for the quickest feedback too :-)

@ShockwaveNN
Copy link
Author

@koic Thanks for dependabot I'm always on edge of rubocop development )

@koic
Copy link
Collaborator

koic commented Aug 5, 2022

@utkarsh2102 Can you cut a new release to resolve this issue? The issue is already resolved in the master branch.

koic added a commit to koic/rubocop that referenced this issue Aug 5, 2022
…eprecated

Fixes rubocop#10871 and utkarsh2102/rubocop-packaging#44.

This PR restores `RuboCop::ConfigLoader.project_root` as deprecated.

It fixes the following build error.

```console
% cd path/to/github.com/utkarsh2102/rubocop-packaging
% bundle update && bundle exec rake
(snip)

Failures:

  1) RuboCop::Cop::Packaging::BundlerSetupInTests when `require
  bundler/setup` is used in a Rakefile does not register an offense
     Failure/Error: let(:project_root) {
  RuboCop::ConfigLoader.project_root }

     NoMethodError:
       undefined method `project_root' for RuboCop::ConfigLoader:Class
     # ./spec/rubocop/cop/packaging/bundler_setup_in_tests_spec.rb:6:in
       `block (2 levels) in <top (required)>'
     # ./spec/rubocop/cop/packaging/bundler_setup_in_tests_spec.rb:39:in
       `block (3 levels) in <top (required)>'
     # ./spec/rubocop/cop/packaging/bundler_setup_in_tests_spec.rb:43:in
       `block (3 levels) in <top (required)>'
```

I considered a soft deprecation, but decided to issue a warning as it
is probably of limited use.
bbatsov pushed a commit to rubocop/rubocop that referenced this issue Aug 5, 2022
Fixes #10871 and utkarsh2102/rubocop-packaging#44.

This PR restores `RuboCop::ConfigLoader.project_root` as deprecated.

It fixes the following build error.

```console
% cd path/to/github.com/utkarsh2102/rubocop-packaging
% bundle update && bundle exec rake
(snip)

Failures:

  1) RuboCop::Cop::Packaging::BundlerSetupInTests when `require
  bundler/setup` is used in a Rakefile does not register an offense
     Failure/Error: let(:project_root) {
  RuboCop::ConfigLoader.project_root }

     NoMethodError:
       undefined method `project_root' for RuboCop::ConfigLoader:Class
     # ./spec/rubocop/cop/packaging/bundler_setup_in_tests_spec.rb:6:in
       `block (2 levels) in <top (required)>'
     # ./spec/rubocop/cop/packaging/bundler_setup_in_tests_spec.rb:39:in
       `block (3 levels) in <top (required)>'
     # ./spec/rubocop/cop/packaging/bundler_setup_in_tests_spec.rb:43:in
       `block (3 levels) in <top (required)>'
```

I considered a soft deprecation, but decided to issue a warning as it
is probably of limited use.
@utkarsh2102
Copy link
Owner

Super! Thank you, @koic. I'll cut a new release on Sunday/Monday. I'm in midst of flying back home. :)

WJWH pushed a commit to WJWH/rubocop that referenced this issue Aug 8, 2022
…eprecated

Fixes rubocop#10871 and utkarsh2102/rubocop-packaging#44.

This PR restores `RuboCop::ConfigLoader.project_root` as deprecated.

It fixes the following build error.

```console
% cd path/to/github.com/utkarsh2102/rubocop-packaging
% bundle update && bundle exec rake
(snip)

Failures:

  1) RuboCop::Cop::Packaging::BundlerSetupInTests when `require
  bundler/setup` is used in a Rakefile does not register an offense
     Failure/Error: let(:project_root) {
  RuboCop::ConfigLoader.project_root }

     NoMethodError:
       undefined method `project_root' for RuboCop::ConfigLoader:Class
     # ./spec/rubocop/cop/packaging/bundler_setup_in_tests_spec.rb:6:in
       `block (2 levels) in <top (required)>'
     # ./spec/rubocop/cop/packaging/bundler_setup_in_tests_spec.rb:39:in
       `block (3 levels) in <top (required)>'
     # ./spec/rubocop/cop/packaging/bundler_setup_in_tests_spec.rb:43:in
       `block (3 levels) in <top (required)>'
```

I considered a soft deprecation, but decided to issue a warning as it
is probably of limited use.
@iMacTia
Copy link

iMacTia commented Aug 9, 2022

@utkarsh2102 sorry to be a pain, just nudging on this in case it fell through the cracks 🙏

Also, in case you're interested, I use an automated deployment process based on GitHub Releases for my open source projects which allows anyone with permissions to create tags/releases to push a new version to RubyGems without messing with owners. If you're interested let me know and I'd be happy to share

@koic
Copy link
Collaborator

koic commented Aug 9, 2022

FYI: RuboCop 1.34 has been released that is the upstream resolved release. However, rubocop-packaging-0.5.1 user will get a deprecation warning. Anyway, the error is resolved.

@utkarsh2102
Copy link
Owner

utkarsh2102 commented Aug 9, 2022

@iMacTia: sorry for the delay, I am just cutting a new release. But spotted some failures. @koic: should we use RuboCop >= 1.34, instead?

Whilst running rake, I get:
53 examples, 37 failures, all of them for:

NameError:
   uninitialized constant RuboCop::ConfigFinder

@marcotc
Copy link
Contributor

marcotc commented Aug 9, 2022

👋 @utkarsh2102, I opened one of the PRs to fix this issue (#43), and it is indeed required for rubocop-packaging to depend on at least Rubocop 1.33.0, but that's already part of the PR and merged into master:

spec.add_runtime_dependency "rubocop", ">= 1.33", "< 2.0"

Might be a silly question, but did you forget to run bundle install in your environment before running bundle exec rake?

@mvz
Copy link
Collaborator

mvz commented Aug 11, 2022

@utkarsh2102 all test succeed in CI: https://github.com/utkarsh2102/rubocop-packaging/runs/7754085197?check_suite_focus=true

@utkarsh2102
Copy link
Owner

Aaah, my bad. I ran into a bunch of stupid problems. But all in all, everything looks good. Thank you very much for the quick fix, @marcotc! ❤️

I've made a new release, v0.5.2 - that should fix the problem. :D

@utkarsh2102
Copy link
Owner

Closing this issue as everything seems good again but should you run into the same issue (or any other issue), please feel free to re-open or open a new one. Sorry for the slight delay and thank you very much for reporting! \o/

@ShockwaveNN
Copy link
Author

ShockwaveNN commented Aug 11, 2022

I've made a new release, v0.5.2 - that should fix the problem. :D

@utkarsh2102 Didn't you forgot to make a github release at here?

@utkarsh2102
Copy link
Owner

I've made a new release, v0.5.2 - that should fix the problem. :D

@utkarsh2102 Didn't you forgot to make a github release at here?

Thanks, @ShockwaveNN! I did a draft - wanted to credit everyone before finalizing it. It's live now: https://github.com/utkarsh2102/rubocop-packaging/releases/tag/v0.5.2. :D

@ShockwaveNN
Copy link
Author

@utkarsh2102 Thank you and thanks for special mention in Changelog )))

@iMacTia
Copy link

iMacTia commented Aug 11, 2022

Thank you @utkarsh2102 🙏 !

iMacTia added a commit to lostisland/faraday that referenced this issue Jun 15, 2023
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.

6 participants