From f57a0e367b1135736d48d2b11813fc2ca818f644 Mon Sep 17 00:00:00 2001 From: nobuyo Date: Fri, 17 Jun 2022 23:20:31 +0900 Subject: [PATCH] Add new global `ActiveSupportExtensionsEnabled` option --- ...global_active_support_extensions_enabled_option.md | 1 + config/default.yml | 2 ++ docs/modules/ROOT/pages/configuration.adoc | 11 +++++++++++ lib/rubocop/config.rb | 4 ++++ lib/rubocop/cop/base.rb | 4 ++++ 5 files changed, 22 insertions(+) create mode 100644 changelog/new_add_new_global_active_support_extensions_enabled_option.md diff --git a/changelog/new_add_new_global_active_support_extensions_enabled_option.md b/changelog/new_add_new_global_active_support_extensions_enabled_option.md new file mode 100644 index 00000000000..73c0456fb47 --- /dev/null +++ b/changelog/new_add_new_global_active_support_extensions_enabled_option.md @@ -0,0 +1 @@ +* [#10699](https://github.com/rubocop/rubocop/pull/10699): Add new global `ActiveSupportExtensionsEnabled` option. ([@nobuyo][]) diff --git a/config/default.yml b/config/default.yml index 60f1c4b39eb..54404cbc74c 100644 --- a/config/default.yml +++ b/config/default.yml @@ -153,6 +153,8 @@ AllCops: rubocop-sequel: [sequel] rubocop-rake: [rake] rubocop-graphql: [graphql] + # Enable/Disable checking the methods extended by Active Support. + ActiveSupportExtensionsEnabled: false #################### Bundler ############################### diff --git a/docs/modules/ROOT/pages/configuration.adoc b/docs/modules/ROOT/pages/configuration.adoc index 9a39523edeb..58667a8a250 100644 --- a/docs/modules/ROOT/pages/configuration.adoc +++ b/docs/modules/ROOT/pages/configuration.adoc @@ -784,3 +784,14 @@ The following is an example of specifying `Rails` department. Rails: DocumentationBaseURL: https://docs.rubocop.org/rubocop-rails ---- + +== Enable checking Active Support extensions + +Some cops for checking specified methods (e.g. `Style/HashExcept`) supports Active Support extensions. +This is off by default, but can be enabled by the `ActiveSupportExtensionsEnabled` option. + +[source,yaml] +---- +AllCops: + ActiveSupportExtensionsEnabled: true +---- diff --git a/lib/rubocop/config.rb b/lib/rubocop/config.rb index 9bdcad1ec95..823fab1f959 100644 --- a/lib/rubocop/config.rb +++ b/lib/rubocop/config.rb @@ -146,6 +146,10 @@ def enabled_new_cops? for_all_cops['NewCops'] == 'enable' end + def active_support_extensions_enabled? + for_all_cops['ActiveSupportExtensionsEnabled'] + end + def file_to_include?(file) relative_file_path = path_relative_to_config(file) diff --git a/lib/rubocop/cop/base.rb b/lib/rubocop/cop/base.rb index 68cc1db20bb..c6560573000 100644 --- a/lib/rubocop/cop/base.rb +++ b/lib/rubocop/cop/base.rb @@ -220,6 +220,10 @@ def target_rails_version @config.target_rails_version end + def active_support_extensions_enabled? + @config.active_support_extensions_enabled? + end + def relevant_file?(file) file == RuboCop::AST::ProcessedSource::STRING_SOURCE_NAME || (file_name_matches_any?(file, 'Include', true) &&