From 6ea08332ff13531e363773124ee108c350fe918d Mon Sep 17 00:00:00 2001 From: Maruth Goyal Date: Mon, 22 Jan 2024 11:28:39 -0800 Subject: [PATCH] Update error message on incorrect badge --- changelog/change_error_message_on_incorrect_namespace.md | 1 + lib/rubocop/cop/registry.rb | 2 +- spec/rubocop/cli_spec.rb | 2 +- spec/rubocop/config_loader_spec.rb | 2 +- spec/rubocop/cop/registry_spec.rb | 2 +- 5 files changed, 5 insertions(+), 4 deletions(-) create mode 100644 changelog/change_error_message_on_incorrect_namespace.md diff --git a/changelog/change_error_message_on_incorrect_namespace.md b/changelog/change_error_message_on_incorrect_namespace.md new file mode 100644 index 000000000000..2a319ba5b644 --- /dev/null +++ b/changelog/change_error_message_on_incorrect_namespace.md @@ -0,0 +1 @@ +* [#12641](https://github.com/rubocop/rubocop/pull/12641): Make error message clearer when the namespace is incorrect. ([@maruth-stripe][]) diff --git a/lib/rubocop/cop/registry.rb b/lib/rubocop/cop/registry.rb index 7196ea87e61d..12189c2caec1 100644 --- a/lib/rubocop/cop/registry.rb +++ b/lib/rubocop/cop/registry.rb @@ -300,7 +300,7 @@ def resolve_badge(given_badge, real_badge, source_path) unless given_badge.match?(real_badge) path = PathUtil.smart_path(source_path) warn "#{path}: #{given_badge} has the wrong namespace - " \ - "should be #{real_badge.department}" + "replace it with #{given_badge.with_department(real_badge.department)}" end real_badge.to_s diff --git a/spec/rubocop/cli_spec.rb b/spec/rubocop/cli_spec.rb index 2725b21f1803..22cad73ca1a8 100644 --- a/spec/rubocop/cli_spec.rb +++ b/spec/rubocop/cli_spec.rb @@ -469,7 +469,7 @@ def and_with_args expect(cli.run(['--format', 'emacs', 'example.rb'])).to eq(1) expect($stderr.string) .to eq(['example.rb: Style/LineLength has the wrong ' \ - 'namespace - should be Layout', + 'namespace - replace it with Layout/LineLength', ''].join("\n")) # 2 real cops were disabled, and 1 that was incorrect # 2 real cops was enabled, but only 1 had been disabled correctly diff --git a/spec/rubocop/config_loader_spec.rb b/spec/rubocop/config_loader_spec.rb index 22197bb235d4..4eeda18cfb2a 100644 --- a/spec/rubocop/config_loader_spec.rb +++ b/spec/rubocop/config_loader_spec.rb @@ -854,7 +854,7 @@ def enabled?(cop) .to output( a_string_including( '.rubocop.yml: Custom/Loop has the ' \ - "wrong namespace - should be Lint\n" + "wrong namespace - replace it with Lint/Loop\n" ) ).to_stderr end diff --git a/spec/rubocop/cop/registry_spec.rb b/spec/rubocop/cop/registry_spec.rb index b24feb3320b8..c4ae4aada9bc 100644 --- a/spec/rubocop/cop/registry_spec.rb +++ b/spec/rubocop/cop/registry_spec.rb @@ -114,7 +114,7 @@ it 'emits a warning when namespace is incorrect' do warning = '/app/.rubocop.yml: Style/MethodLength has the wrong ' \ - "namespace - should be Metrics\n" + "namespace - replace it with Metrics/MethodLength\n" qualified = nil expect do