From 8ccd832a832849eabbc88496c47837f181427dc4 Mon Sep 17 00:00:00 2001 From: Koichi ITO Date: Fri, 5 Aug 2022 16:40:29 +0900 Subject: [PATCH] [Fix #10871] Restore `RuboCop::ConfigLoader.project_root` as deprecated Fixes #10871 and https://github.com/utkarsh2102/rubocop-packaging/issues/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 ' # ./spec/rubocop/cop/packaging/bundler_setup_in_tests_spec.rb:39:in `block (3 levels) in ' # ./spec/rubocop/cop/packaging/bundler_setup_in_tests_spec.rb:43:in `block (3 levels) in ' ``` I considered a soft deprecation, but decided to issue a warning as it is probably of limited use. --- ...fix_restore_rubocop_config_loader_project_root.md | 1 + lib/rubocop/config_loader.rb | 12 ++++++++++++ 2 files changed, 13 insertions(+) create mode 100644 changelog/fix_restore_rubocop_config_loader_project_root.md diff --git a/changelog/fix_restore_rubocop_config_loader_project_root.md b/changelog/fix_restore_rubocop_config_loader_project_root.md new file mode 100644 index 00000000000..d6842c48d6c --- /dev/null +++ b/changelog/fix_restore_rubocop_config_loader_project_root.md @@ -0,0 +1 @@ +* [#10871](https://github.com/rubocop/rubocop/issues/10871): Restore `RuboCop::ConfigLoader.project_root` as deprecated. ([@koic][]) diff --git a/lib/rubocop/config_loader.rb b/lib/rubocop/config_loader.rb index 6bbcdcf3b16..f594843f52a 100644 --- a/lib/rubocop/config_loader.rb +++ b/lib/rubocop/config_loader.rb @@ -137,6 +137,18 @@ def default_configuration end end + # Returns the path RuboCop inferred as the root of the project. No file + # searches will go past this directory. + # @deprecated Use `RuboCop::ConfigFinder.project_root` instead. + def project_root + warn Rainbow(<<~WARNING).yellow + `RuboCop::ConfigLoader.project_root` is deprecated and will be removed in RuboCop 2.0. \ + Use `RuboCop::ConfigFinder.project_root` instead. + WARNING + + ConfigFinder.project_root + end + PENDING_BANNER = <<~BANNER The following cops were added to RuboCop, but are not configured. Please set Enabled to either `true` or `false` in your `.rubocop.yml` file.