Skip to content

Commit

Permalink
[Fix #8413] Adjust pending cop warning to be copy&pastable and inform…
Browse files Browse the repository at this point in the history
… about NewCops: enable (#8414)

Co-authored-by: Bozhidar Batsov <bozhidar@batsov.com>
  • Loading branch information
colszowka and bbatsov committed Aug 27, 2020
1 parent 1788a26 commit 190834e
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 12 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Expand Up @@ -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][])
Expand Down Expand Up @@ -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
23 changes: 17 additions & 6 deletions lib/rubocop/config_loader.rb
Expand Up @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions spec/rubocop/cli/cli_options_spec.rb
Expand Up @@ -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 }
Expand Down Expand Up @@ -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

Expand All @@ -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

Expand Down

0 comments on commit 190834e

Please sign in to comment.