diff --git a/CHANGELOG.md b/CHANGELOG.md index 644cc6e9db4..f28bccbf2a9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -109,6 +109,7 @@ ### Changes +* [#8413](https://github.com/rubocop-hq/rubocop/issues/8413): Pending cops warning now contains snippet that can be directly copied into `.rubocop.yml` as well as a notice about `NewCops: enable` config option. ([@colszowka][]) * [#8376](https://github.com/rubocop-hq/rubocop/pull/8376): `Style/MethodMissingSuper` cop is removed in favor of new `Lint/MissingSuper` cop. ([@fatkodima][]) * [#8433](https://github.com/rubocop-hq/rubocop/pull/8433): `Lint/UselessComparison` cop is removed in favor of new `Lint/BinaryOperatorWithIdenticalOperands` cop. ([@fatkodima][]) * [#8350](https://github.com/rubocop-hq/rubocop/pull/8350): Set default max line length to 120 for `Style/MultilineMethodSignature`. ([@koic][]) @@ -4809,9 +4810,10 @@ [@knejad]: https://github.com/knejad [@iamravitejag]: https://github.com/iamravitejag [@volfgox]: https://github.com/volfgox +[@colszowka]: https://github.com/colszowka [@dsavochkin]: https://github.com/dmytro-savochkin [@sonalinavlakhe]: https://github.com/sonalinavlakhe [@wcmonty]: https://github.com/wcmonty [@nguyenquangminh0711]: https://github.com/nguyenquangminh0711 [@chocolateboy]: https://github.com/chocolateboy -[@Lykos]: https://github.com/Lykos +[@Lykos]: https://github.com/Lykos \ No newline at end of file diff --git a/lib/rubocop/config_loader.rb b/lib/rubocop/config_loader.rb index e33f4135106..27e13106c55 100644 --- a/lib/rubocop/config_loader.rb +++ b/lib/rubocop/config_loader.rb @@ -140,22 +140,33 @@ def project_root @project_root ||= find_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. + + Please also note that can also opt-in to new cops by default by adding this to your config: + AllCops: + NewCops: enable + BANNER + def warn_on_pending_cops(pending_cops) return if pending_cops.empty? - warn Rainbow('The following cops were added to RuboCop, but are not ' \ - 'configured. Please set Enabled to either `true` or ' \ - '`false` in your `.rubocop.yml` file:').yellow + warn Rainbow(PENDING_BANNER).yellow pending_cops.each do |cop| - version = cop.metadata['VersionAdded'] || 'N/A' - - warn Rainbow(" - #{cop.name} (#{version})").yellow + warn_pending_cop cop end warn Rainbow('For more information: https://docs.rubocop.org/rubocop/versioning.html').yellow end + def warn_pending_cop(cop) + version = cop.metadata['VersionAdded'] || 'N/A' + + warn Rainbow("#{cop.name}: # (new in #{version})").yellow + warn Rainbow(' Enabled: true').yellow + end + # Merges the given configuration with the default one. def merge_with_default(config, config_file, unset_nil: true) resolver.merge_with_default(config, config_file, unset_nil: unset_nil) diff --git a/spec/rubocop/cli/cli_options_spec.rb b/spec/rubocop/cli/cli_options_spec.rb index 7c8dc969d5f..3ed5a4c5fc2 100644 --- a/spec/rubocop/cli/cli_options_spec.rb +++ b/spec/rubocop/cli/cli_options_spec.rb @@ -272,7 +272,7 @@ class SomeCop < Cop end let(:pending_cop_warning) { <<~PENDING_COP_WARNING } - The following cops were added to RuboCop, but are not configured. Please set Enabled to either `true` or `false` in your `.rubocop.yml` file: + The following cops were added to RuboCop, but are not configured. Please set Enabled to either `true` or `false` in your `.rubocop.yml` file. PENDING_COP_WARNING let(:inspected_output) { <<~INSPECTED_OUTPUT } @@ -327,9 +327,9 @@ class SomeCop < Cop remaining_range = pending_cop_warning.length..-(inspected_output.length + 1) - pending_cops = output[remaining_range].split("\n") + pending_cops = output[remaining_range] - expect(pending_cops).to include(' - Style/SomeCop (0.80)') + expect(pending_cops).to include("Style/SomeCop: # (new in 0.80)\n Enabled: true") manual_url = output[remaining_range].split("\n").last @@ -346,9 +346,9 @@ class SomeCop < Cop remaining_range = pending_cop_warning.length..-(inspected_output.length + 1) - pending_cops = output[remaining_range].split("\n") + pending_cops = output[remaining_range] - expect(pending_cops).to include(' - Style/SomeCop (N/A)') + expect(pending_cops).to include("Style/SomeCop: # (new in N/A)\n Enabled: true") manual_url = output[remaining_range].split("\n").last