From 0207a038b3d36fb1fd24554ff9ccc69baa8fa590 Mon Sep 17 00:00:00 2001 From: Phil Pirozhkov Date: Sat, 18 Jun 2022 03:19:41 +0300 Subject: [PATCH 1/3] [#8827] Change Style/FormatStringToken style to template --- ..._string_token_enforced_style_to_template.md | 1 + config/default.yml | 8 ++++---- docs/modules/ROOT/pages/cops_style.adoc | 18 +++++++++--------- lib/rubocop/cop/style/format_string_token.rb | 12 ++++++------ .../cop/style/format_string_token_spec.rb | 2 +- 5 files changed, 21 insertions(+), 20 deletions(-) create mode 100644 changelog/change_style_format_string_token_enforced_style_to_template.md diff --git a/changelog/change_style_format_string_token_enforced_style_to_template.md b/changelog/change_style_format_string_token_enforced_style_to_template.md new file mode 100644 index 000000000000..389441fcb7ce --- /dev/null +++ b/changelog/change_style_format_string_token_enforced_style_to_template.md @@ -0,0 +1 @@ +* [#8827](https://github.com/rubocop/rubocop/issues/8827): Change the enforced style of `Style/FormatStringToken` to `template`. ([@pirj][]) diff --git a/config/default.yml b/config/default.yml index da1660a16c5a..4c6df29e17d8 100644 --- a/config/default.yml +++ b/config/default.yml @@ -3635,20 +3635,20 @@ Style/FormatString: Style/FormatStringToken: Description: 'Use a consistent style for format string tokens.' Enabled: true - EnforcedStyle: annotated + EnforcedStyle: template SupportedStyles: + # Prefer simple looking "template" style tokens like `%{name}`, `%{age}` + - template # Prefer tokens which contain a sprintf like type annotation like # `%s`, `%d`, `%f` - annotated - # Prefer simple looking "template" style tokens like `%{name}`, `%{age}` - - template - unannotated # `MaxUnannotatedPlaceholdersAllowed` defines the number of `unannotated` # style token in a format string to be allowed when enforced style is not # `unannotated`. MaxUnannotatedPlaceholdersAllowed: 1 VersionAdded: '0.49' - VersionChanged: '1.0' + VersionChanged: '<>' IgnoredMethods: [] Style/FrozenStringLiteralComment: diff --git a/docs/modules/ROOT/pages/cops_style.adoc b/docs/modules/ROOT/pages/cops_style.adoc index edd43886af16..b659dd70eb00 100644 --- a/docs/modules/ROOT/pages/cops_style.adoc +++ b/docs/modules/ROOT/pages/cops_style.adoc @@ -4208,7 +4208,7 @@ puts '%10s' % 'hoge' | Yes | No | 0.49 -| 1.0 +| <> |=== Use a consistent style for named format string tokens. @@ -4227,28 +4227,28 @@ if the number of them is less than or equals to === Examples -==== EnforcedStyle: annotated (default) +==== EnforcedStyle: template (default) [source,ruby] ---- # bad -format('%{greeting}', greeting: 'Hello') +format('%s', greeting: 'Hello') format('%s', 'Hello') # good -format('%s', greeting: 'Hello') +format('%{greeting}', greeting: 'Hello') ---- -==== EnforcedStyle: template +==== EnforcedStyle: annotated [source,ruby] ---- # bad -format('%s', greeting: 'Hello') +format('%{greeting}', greeting: 'Hello') format('%s', 'Hello') # good -format('%{greeting}', greeting: 'Hello') +format('%s', greeting: 'Hello') ---- ==== EnforcedStyle: unannotated @@ -4300,8 +4300,8 @@ redirect('foo/%{bar_id}') | Name | Default value | Configurable values | EnforcedStyle -| `annotated` -| `annotated`, `template`, `unannotated` +| `template` +| `template`, `annotated`, `unannotated` | MaxUnannotatedPlaceholdersAllowed | `1` diff --git a/lib/rubocop/cop/style/format_string_token.rb b/lib/rubocop/cop/style/format_string_token.rb index 5d2256ed6443..50be13551cf9 100644 --- a/lib/rubocop/cop/style/format_string_token.rb +++ b/lib/rubocop/cop/style/format_string_token.rb @@ -13,23 +13,23 @@ module Style # # This cop can be customized ignored methods with `IgnoredMethods`. # - # @example EnforcedStyle: annotated (default) + # @example EnforcedStyle: template (default) # # # bad - # format('%{greeting}', greeting: 'Hello') + # format('%s', greeting: 'Hello') # format('%s', 'Hello') # # # good - # format('%s', greeting: 'Hello') + # format('%{greeting}', greeting: 'Hello') # - # @example EnforcedStyle: template + # @example EnforcedStyle: annotated # # # bad - # format('%s', greeting: 'Hello') + # format('%{greeting}', greeting: 'Hello') # format('%s', 'Hello') # # # good - # format('%{greeting}', greeting: 'Hello') + # format('%s', greeting: 'Hello') # # @example EnforcedStyle: unannotated # diff --git a/spec/rubocop/cop/style/format_string_token_spec.rb b/spec/rubocop/cop/style/format_string_token_spec.rb index 2e1fe1d036a5..0066c2b7df98 100644 --- a/spec/rubocop/cop/style/format_string_token_spec.rb +++ b/spec/rubocop/cop/style/format_string_token_spec.rb @@ -90,7 +90,7 @@ it_behaves_like 'maximum allowed unannotated', token end - context 'when enforced style is template' do + context 'when enforced style is template (default)' do let(:enforced_style) { :template } it 'registers offenses for annotated style' do From dfc1e99d774351e75352dd5b3072cae9553f6804 Mon Sep 17 00:00:00 2001 From: Phil Pirozhkov Date: Sat, 18 Jun 2022 03:58:04 +0300 Subject: [PATCH 2/3] Fix Style/FormatStringToken offences --- .../config_obsoletion/changed_enforced_styles.rb | 2 +- lib/rubocop/config_obsoletion/changed_parameter.rb | 2 +- lib/rubocop/config_obsoletion/extracted_cop.rb | 2 +- lib/rubocop/config_obsoletion/removed_cop.rb | 2 +- lib/rubocop/cop/bundler/duplicated_gem.rb | 4 ++-- lib/rubocop/cop/bundler/gem_filename.rb | 8 ++++---- lib/rubocop/cop/bundler/insecure_protocol_source.rb | 2 +- lib/rubocop/cop/bundler/ordered_gems.rb | 2 +- lib/rubocop/cop/correctors/each_to_for_corrector.rb | 4 ++-- lib/rubocop/cop/correctors/for_to_each_corrector.rb | 2 +- lib/rubocop/cop/gemspec/duplicated_assignment.rb | 4 ++-- lib/rubocop/cop/gemspec/ordered_dependencies.rb | 2 +- lib/rubocop/cop/gemspec/required_ruby_version.rb | 2 +- lib/rubocop/cop/generator.rb | 8 ++++---- lib/rubocop/cop/generator/configuration_injector.rb | 4 ++-- lib/rubocop/cop/internal_affairs/cop_description.rb | 2 +- ...pty_line_between_expect_offense_and_correction.rb | 2 +- .../cop/internal_affairs/example_description.rb | 2 +- .../location_line_equality_comparison.rb | 2 +- .../cop/internal_affairs/method_name_end_with.rb | 2 +- .../cop/internal_affairs/method_name_equal.rb | 2 +- .../cop/internal_affairs/node_matcher_directive.rb | 4 ++-- .../cop/internal_affairs/node_type_predicate.rb | 2 +- .../cop/internal_affairs/offense_location_keyword.rb | 2 +- .../redundant_described_class_as_subject.rb | 2 +- .../redundant_let_rubocop_config_new.rb | 2 +- lib/rubocop/cop/internal_affairs/undefined_config.rb | 2 +- .../cop/layout/access_modifier_indentation.rb | 2 +- lib/rubocop/cop/layout/block_alignment.rb | 2 +- lib/rubocop/cop/layout/block_end_newline.rb | 2 +- lib/rubocop/cop/layout/case_indentation.rb | 2 +- lib/rubocop/cop/layout/class_structure.rb | 2 +- .../cop/layout/closing_heredoc_indentation.rb | 4 ++-- .../cop/layout/closing_parenthesis_indentation.rb | 2 +- lib/rubocop/cop/layout/comment_indentation.rb | 4 ++-- lib/rubocop/cop/layout/condition_position.rb | 2 +- lib/rubocop/cop/layout/else_alignment.rb | 2 +- lib/rubocop/cop/layout/empty_line_between_defs.rb | 2 +- .../cop/layout/empty_lines_around_access_modifier.rb | 8 ++++---- ...empty_lines_around_exception_handling_keywords.rb | 2 +- lib/rubocop/cop/layout/extra_spacing.rb | 2 +- lib/rubocop/cop/layout/first_argument_indentation.rb | 2 +- .../cop/layout/first_array_element_indentation.rb | 4 ++-- .../cop/layout/first_hash_element_indentation.rb | 4 ++-- .../cop/layout/first_parameter_indentation.rb | 4 ++-- lib/rubocop/cop/layout/heredoc_indentation.rb | 6 +++--- lib/rubocop/cop/layout/indentation_style.rb | 2 +- lib/rubocop/cop/layout/indentation_width.rb | 4 ++-- lib/rubocop/cop/layout/line_length.rb | 2 +- lib/rubocop/cop/layout/rescue_ensure_alignment.rb | 6 +++--- .../space_around_equals_in_parameter_default.rb | 2 +- lib/rubocop/cop/layout/space_around_keyword.rb | 4 ++-- .../layout/space_inside_array_literal_brackets.rb | 4 ++-- .../cop/layout/space_inside_hash_literal_braces.rb | 2 +- .../cop/layout/space_inside_reference_brackets.rb | 4 ++-- lib/rubocop/cop/layout/trailing_empty_lines.rb | 2 +- lib/rubocop/cop/lint/ambiguous_assignment.rb | 2 +- lib/rubocop/cop/lint/ambiguous_block_association.rb | 4 ++-- lib/rubocop/cop/lint/ambiguous_operator.rb | 8 ++++---- lib/rubocop/cop/lint/big_decimal_new.rb | 4 ++-- .../lint/binary_operator_with_identical_operands.rb | 2 +- lib/rubocop/cop/lint/boolean_symbol.rb | 2 +- lib/rubocop/cop/lint/circular_argument_reference.rb | 2 +- lib/rubocop/cop/lint/debugger.rb | 2 +- lib/rubocop/cop/lint/deprecated_class_methods.rb | 2 +- lib/rubocop/cop/lint/deprecated_constants.rb | 4 ++-- lib/rubocop/cop/lint/deprecated_open_ssl_constant.rb | 2 +- lib/rubocop/cop/lint/duplicate_methods.rb | 2 +- lib/rubocop/cop/lint/duplicate_require.rb | 2 +- lib/rubocop/cop/lint/empty_conditional_body.rb | 2 +- lib/rubocop/cop/lint/erb_new_arguments.rb | 4 ++-- lib/rubocop/cop/lint/format_parameter_mismatch.rb | 4 ++-- .../cop/lint/implicit_string_concatenation.rb | 2 +- .../incompatible_io_select_with_fiber_scheduler.rb | 2 +- lib/rubocop/cop/lint/ineffective_access_modifier.rb | 4 ++-- lib/rubocop/cop/lint/inherit_exception.rb | 2 +- lib/rubocop/cop/lint/literal_as_condition.rb | 2 +- lib/rubocop/cop/lint/missing_cop_enable_directive.rb | 4 ++-- lib/rubocop/cop/lint/number_conversion.rb | 12 ++++++------ .../cop/lint/numbered_parameter_assignment.rb | 4 ++-- lib/rubocop/cop/lint/out_of_range_regexp_ref.rb | 2 +- .../cop/lint/parentheses_as_grouped_expression.rb | 2 +- lib/rubocop/cop/lint/rand_one.rb | 2 +- .../cop/lint/redundant_cop_enable_directive.rb | 2 +- lib/rubocop/cop/lint/refinement_import_methods.rb | 2 +- lib/rubocop/cop/lint/rescue_type.rb | 2 +- lib/rubocop/cop/lint/return_in_void_context.rb | 2 +- lib/rubocop/cop/lint/script_permission.rb | 2 +- lib/rubocop/cop/lint/send_with_mixin_argument.rb | 2 +- lib/rubocop/cop/lint/shadowed_argument.rb | 2 +- .../cop/lint/shadowing_outer_local_variable.rb | 2 +- lib/rubocop/cop/lint/struct_new_override.rb | 2 +- lib/rubocop/cop/lint/symbol_conversion.rb | 4 ++-- lib/rubocop/cop/lint/unexpected_block_arity.rb | 2 +- lib/rubocop/cop/lint/unified_integer.rb | 2 +- .../cop/lint/unmodified_reduce_accumulator.rb | 4 ++-- lib/rubocop/cop/lint/uri_escape_unescape.rb | 4 ++-- lib/rubocop/cop/lint/uri_regexp.rb | 2 +- lib/rubocop/cop/lint/useless_access_modifier.rb | 2 +- lib/rubocop/cop/lint/useless_assignment.rb | 2 +- lib/rubocop/cop/lint/useless_ruby2_keywords.rb | 2 +- lib/rubocop/cop/lint/useless_setter_call.rb | 2 +- lib/rubocop/cop/lint/useless_times.rb | 2 +- lib/rubocop/cop/lint/void.rb | 10 +++++----- lib/rubocop/cop/metrics/abc_size.rb | 4 ++-- lib/rubocop/cop/metrics/class_length.rb | 2 +- lib/rubocop/cop/metrics/cyclomatic_complexity.rb | 2 +- lib/rubocop/cop/metrics/module_length.rb | 2 +- lib/rubocop/cop/metrics/parameter_lists.rb | 4 ++-- lib/rubocop/cop/metrics/perceived_complexity.rb | 2 +- lib/rubocop/cop/mixin/code_length.rb | 2 +- lib/rubocop/cop/mixin/empty_lines_around_body.rb | 6 +++--- lib/rubocop/cop/mixin/end_keyword_alignment.rb | 4 ++-- .../cop/mixin/multiline_expression_indentation.rb | 2 +- lib/rubocop/cop/mixin/negative_conditional.rb | 2 +- lib/rubocop/cop/mixin/space_after_punctuation.rb | 2 +- lib/rubocop/cop/mixin/space_before_punctuation.rb | 2 +- lib/rubocop/cop/mixin/trailing_comma.rb | 2 +- lib/rubocop/cop/mixin/uncommunicative_name.rb | 8 ++++---- .../cop/naming/binary_operator_parameter_name.rb | 2 +- lib/rubocop/cop/naming/block_forwarding.rb | 2 +- lib/rubocop/cop/naming/file_name.rb | 6 +++--- lib/rubocop/cop/naming/heredoc_delimiter_case.rb | 2 +- lib/rubocop/cop/naming/inclusive_language.rb | 4 ++-- .../cop/naming/memoized_instance_variable_name.rb | 8 ++++---- lib/rubocop/cop/naming/method_name.rb | 2 +- .../cop/naming/rescued_exceptions_variable_name.rb | 2 +- lib/rubocop/cop/naming/variable_name.rb | 2 +- lib/rubocop/cop/naming/variable_number.rb | 2 +- lib/rubocop/cop/offense.rb | 2 +- lib/rubocop/cop/registry.rb | 4 ++-- lib/rubocop/cop/security/io_methods.rb | 2 +- lib/rubocop/cop/security/json_load.rb | 2 +- lib/rubocop/cop/security/marshal_load.rb | 2 +- lib/rubocop/cop/security/open.rb | 2 +- .../cop/style/access_modifier_declarations.rb | 4 ++-- lib/rubocop/cop/style/accessor_grouping.rb | 4 ++-- lib/rubocop/cop/style/alias.rb | 4 ++-- lib/rubocop/cop/style/and_or.rb | 2 +- lib/rubocop/cop/style/array_coercion.rb | 4 ++-- lib/rubocop/cop/style/attr.rb | 2 +- lib/rubocop/cop/style/auto_resource_cleanup.rb | 2 +- lib/rubocop/cop/style/bare_percent_literals.rb | 2 +- lib/rubocop/cop/style/bisected_attr_accessor.rb | 2 +- lib/rubocop/cop/style/block_delimiters.rb | 2 +- lib/rubocop/cop/style/class_check.rb | 2 +- lib/rubocop/cop/style/class_equality_comparison.rb | 2 +- lib/rubocop/cop/style/class_methods.rb | 2 +- lib/rubocop/cop/style/class_methods_definitions.rb | 2 +- lib/rubocop/cop/style/class_vars.rb | 2 +- lib/rubocop/cop/style/collection_compact.rb | 2 +- lib/rubocop/cop/style/collection_methods.rb | 2 +- lib/rubocop/cop/style/comment_annotation.rb | 6 +++--- lib/rubocop/cop/style/commented_keyword.rb | 2 +- lib/rubocop/cop/style/constant_visibility.rb | 2 +- lib/rubocop/cop/style/copyright.rb | 2 +- .../disable_cops_within_source_code_directive.rb | 2 +- lib/rubocop/cop/style/documentation.rb | 2 +- lib/rubocop/cop/style/each_with_object.rb | 2 +- lib/rubocop/cop/style/empty_literal.rb | 2 +- lib/rubocop/cop/style/eval_with_location.rb | 10 +++++----- lib/rubocop/cop/style/even_odd.rb | 2 +- lib/rubocop/cop/style/expand_path_arguments.rb | 4 ++-- lib/rubocop/cop/style/fetch_env_var.rb | 8 ++++---- lib/rubocop/cop/style/file_read.rb | 2 +- lib/rubocop/cop/style/file_write.rb | 2 +- lib/rubocop/cop/style/format_string.rb | 2 +- lib/rubocop/cop/style/global_std_stream.rb | 2 +- lib/rubocop/cop/style/guard_clause.rb | 2 +- lib/rubocop/cop/style/hash_each_methods.rb | 2 +- lib/rubocop/cop/style/hash_except.rb | 2 +- .../cop/style/identical_conditional_branches.rb | 2 +- lib/rubocop/cop/style/if_unless_modifier.rb | 4 ++-- .../cop/style/if_unless_modifier_of_if_unless.rb | 2 +- .../cop/style/if_with_boolean_literal_branches.rb | 2 +- lib/rubocop/cop/style/if_with_semicolon.rb | 4 ++-- lib/rubocop/cop/style/implicit_runtime_error.rb | 2 +- lib/rubocop/cop/style/in_pattern_then.rb | 2 +- lib/rubocop/cop/style/inverse_methods.rb | 2 +- lib/rubocop/cop/style/lambda.rb | 4 ++-- lib/rubocop/cop/style/lambda_call.rb | 2 +- .../cop/style/map_compact_with_conditional_block.rb | 2 +- lib/rubocop/cop/style/map_to_hash.rb | 2 +- lib/rubocop/cop/style/min_max.rb | 2 +- lib/rubocop/cop/style/missing_else.rb | 6 +++--- lib/rubocop/cop/style/mixin_grouping.rb | 2 +- lib/rubocop/cop/style/mixin_usage.rb | 2 +- lib/rubocop/cop/style/multiline_if_modifier.rb | 2 +- lib/rubocop/cop/style/multiline_if_then.rb | 2 +- lib/rubocop/cop/style/negated_if_else_condition.rb | 2 +- lib/rubocop/cop/style/nested_file_dirname.rb | 2 +- lib/rubocop/cop/style/nested_parenthesized_calls.rb | 2 +- lib/rubocop/cop/style/nil_lambda.rb | 2 +- lib/rubocop/cop/style/non_nil_check.rb | 2 +- lib/rubocop/cop/style/numbered_parameters_limit.rb | 2 +- lib/rubocop/cop/style/numeric_predicate.rb | 2 +- lib/rubocop/cop/style/object_then.rb | 2 +- lib/rubocop/cop/style/one_line_conditional.rb | 2 +- lib/rubocop/cop/style/optional_boolean_parameter.rb | 2 +- lib/rubocop/cop/style/perl_backrefs.rb | 2 +- lib/rubocop/cop/style/preferred_hash_methods.rb | 2 +- lib/rubocop/cop/style/raise_args.rb | 4 ++-- lib/rubocop/cop/style/redundant_argument.rb | 2 +- lib/rubocop/cop/style/redundant_conditional.rb | 2 +- lib/rubocop/cop/style/redundant_fetch_block.rb | 2 +- lib/rubocop/cop/style/redundant_percent_q.rb | 4 ++-- .../cop/style/redundant_regexp_character_class.rb | 2 +- lib/rubocop/cop/style/redundant_self_assignment.rb | 2 +- lib/rubocop/cop/style/redundant_sort.rb | 2 +- lib/rubocop/cop/style/redundant_sort_by.rb | 2 +- lib/rubocop/cop/style/sample.rb | 2 +- lib/rubocop/cop/style/select_by_regexp.rb | 2 +- lib/rubocop/cop/style/self_assignment.rb | 2 +- lib/rubocop/cop/style/single_argument_dig.rb | 2 +- lib/rubocop/cop/style/single_line_block_params.rb | 2 +- lib/rubocop/cop/style/sole_nested_conditional.rb | 2 +- lib/rubocop/cop/style/special_global_vars.rb | 12 ++++++------ lib/rubocop/cop/style/stderr_puts.rb | 2 +- lib/rubocop/cop/style/string_chars.rb | 2 +- lib/rubocop/cop/style/string_methods.rb | 2 +- lib/rubocop/cop/style/strip.rb | 2 +- lib/rubocop/cop/style/swap_values.rb | 4 ++-- lib/rubocop/cop/style/symbol_array.rb | 2 +- lib/rubocop/cop/style/symbol_proc.rb | 2 +- lib/rubocop/cop/style/ternary_parentheses.rb | 4 ++-- lib/rubocop/cop/style/trailing_comma_in_arguments.rb | 2 +- .../cop/style/trailing_comma_in_array_literal.rb | 2 +- .../cop/style/trailing_comma_in_hash_literal.rb | 2 +- .../cop/style/trailing_underscore_variable.rb | 2 +- lib/rubocop/cop/style/trivial_accessors.rb | 2 +- lib/rubocop/cop/style/unpack_first.rb | 4 ++-- lib/rubocop/cop/style/variable_interpolation.rb | 4 ++-- lib/rubocop/cop/style/when_then.rb | 2 +- lib/rubocop/cop/style/while_until_do.rb | 2 +- lib/rubocop/cop/style/while_until_modifier.rb | 2 +- lib/rubocop/cop/style/word_array.rb | 2 +- lib/rubocop/cop/style/yoda_condition.rb | 2 +- lib/rubocop/cop/style/zero_length_predicate.rb | 4 ++-- lib/rubocop/formatter/clang_style_formatter.rb | 2 +- lib/rubocop/formatter/disabled_config_formatter.rb | 6 +++--- lib/rubocop/formatter/emacs_style_formatter.rb | 2 +- lib/rubocop/formatter/file_list_formatter.rb | 2 +- lib/rubocop/formatter/git_hub_actions_formatter.rb | 2 +- lib/rubocop/formatter/pacman_formatter.rb | 2 +- lib/rubocop/formatter/simple_text_formatter.rb | 2 +- lib/rubocop/formatter/tap_formatter.rb | 2 +- lib/rubocop/options.rb | 6 +++--- lib/rubocop/version.rb | 6 +++--- tasks/changelog.rb | 6 +++--- 249 files changed, 353 insertions(+), 353 deletions(-) diff --git a/lib/rubocop/config_obsoletion/changed_enforced_styles.rb b/lib/rubocop/config_obsoletion/changed_enforced_styles.rb index 89e8899011af..1360843a1f30 100644 --- a/lib/rubocop/config_obsoletion/changed_enforced_styles.rb +++ b/lib/rubocop/config_obsoletion/changed_enforced_styles.rb @@ -5,7 +5,7 @@ class ConfigObsoletion # Encapsulation of a ConfigObsoletion rule for changing a parameter # @api private class ChangedEnforcedStyles < ParameterRule - BASE_MESSAGE = 'obsolete `%s: %s` (for `%s`) found in %s' + BASE_MESSAGE = 'obsolete `%{parameter}: %{value}` (for `%{cop}`) found in %{path}' def violated? super && config[cop][parameter] == value diff --git a/lib/rubocop/config_obsoletion/changed_parameter.rb b/lib/rubocop/config_obsoletion/changed_parameter.rb index 48cd576ea0e6..b47cd4185fd0 100644 --- a/lib/rubocop/config_obsoletion/changed_parameter.rb +++ b/lib/rubocop/config_obsoletion/changed_parameter.rb @@ -5,7 +5,7 @@ class ConfigObsoletion # Encapsulation of a ConfigObsoletion rule for changing a parameter # @api private class ChangedParameter < ParameterRule - BASE_MESSAGE = 'obsolete parameter `%s` (for `%s`) found in %s' + BASE_MESSAGE = 'obsolete parameter `%{parameter}` (for `%{cop}`) found in %{path}' def message base = format(BASE_MESSAGE, parameter: parameter, cop: cop, path: smart_loaded_path) diff --git a/lib/rubocop/config_obsoletion/extracted_cop.rb b/lib/rubocop/config_obsoletion/extracted_cop.rb index b744ef604fae..e0f6ca839476 100644 --- a/lib/rubocop/config_obsoletion/extracted_cop.rb +++ b/lib/rubocop/config_obsoletion/extracted_cop.rb @@ -21,7 +21,7 @@ def violated? end def rule_message - msg = '%s been extracted to the `%s` gem.' + msg = '%{name} been extracted to the `%{gem}` gem.' format(msg, name: affected_cops.size > 1 ? "`#{department}` cops have" : "`#{old_name}` has", gem: gem) diff --git a/lib/rubocop/config_obsoletion/removed_cop.rb b/lib/rubocop/config_obsoletion/removed_cop.rb index 03fa8fed4888..0e2e30be1596 100644 --- a/lib/rubocop/config_obsoletion/removed_cop.rb +++ b/lib/rubocop/config_obsoletion/removed_cop.rb @@ -8,7 +8,7 @@ class ConfigObsoletion class RemovedCop < CopRule attr_reader :old_name, :metadata - BASE_MESSAGE = 'The `%s` cop has been removed' + BASE_MESSAGE = 'The `%{old_name}` cop has been removed' def initialize(config, old_name, metadata) super(config, old_name) diff --git a/lib/rubocop/cop/bundler/duplicated_gem.rb b/lib/rubocop/cop/bundler/duplicated_gem.rb index eca531593550..9a58f2d4d71b 100644 --- a/lib/rubocop/cop/bundler/duplicated_gem.rb +++ b/lib/rubocop/cop/bundler/duplicated_gem.rb @@ -38,8 +38,8 @@ module Bundler class DuplicatedGem < Base include RangeHelp - MSG = 'Gem `%s` requirements already given on line ' \ - '%d of the Gemfile.' + MSG = 'Gem `%{gem_name}` requirements already given on line ' \ + '%{line_of_first_occurrence} of the Gemfile.' def on_new_investigation return if processed_source.blank? diff --git a/lib/rubocop/cop/bundler/gem_filename.rb b/lib/rubocop/cop/bundler/gem_filename.rb index bcb0dfc61b97..6626d08bd962 100644 --- a/lib/rubocop/cop/bundler/gem_filename.rb +++ b/lib/rubocop/cop/bundler/gem_filename.rb @@ -30,13 +30,13 @@ class GemFilename < Base include RangeHelp MSG_GEMFILE_REQUIRED = '`gems.rb` file was found but `Gemfile` is required ' \ - '(file path: %s).' + '(file path: %{file_path}).' MSG_GEMS_RB_REQUIRED = '`Gemfile` was found but `gems.rb` file is required ' \ - '(file path: %s).' + '(file path: %{file_path}).' MSG_GEMFILE_MISMATCHED = 'Expected a `Gemfile.lock` with `Gemfile` but found ' \ - '`gems.locked` file (file path: %s).' + '`gems.locked` file (file path: %{file_path}).' MSG_GEMS_RB_MISMATCHED = 'Expected a `gems.locked` file with `gems.rb` but found ' \ - '`Gemfile.lock` (file path: %s).' + '`Gemfile.lock` (file path: %{file_path}).' GEMFILE_FILES = %w[Gemfile Gemfile.lock].freeze GEMS_RB_FILES = %w[gems.rb gems.locked].freeze diff --git a/lib/rubocop/cop/bundler/insecure_protocol_source.rb b/lib/rubocop/cop/bundler/insecure_protocol_source.rb index c7b24a879a0b..56f1cbdcd7ff 100644 --- a/lib/rubocop/cop/bundler/insecure_protocol_source.rb +++ b/lib/rubocop/cop/bundler/insecure_protocol_source.rb @@ -42,7 +42,7 @@ class InsecureProtocolSource < Base include RangeHelp extend AutoCorrector - MSG = 'The source `:%s` is deprecated because HTTP requests ' \ + MSG = 'The source `:%{source}` is deprecated because HTTP requests ' \ 'are insecure. ' \ "Please change your source to 'https://rubygems.org' " \ "if possible, or 'http://rubygems.org' if not." diff --git a/lib/rubocop/cop/bundler/ordered_gems.rb b/lib/rubocop/cop/bundler/ordered_gems.rb index 4b60ba70a962..81675219cf4c 100644 --- a/lib/rubocop/cop/bundler/ordered_gems.rb +++ b/lib/rubocop/cop/bundler/ordered_gems.rb @@ -30,7 +30,7 @@ class OrderedGems < Base MSG = 'Gems should be sorted in an alphabetical order within their ' \ 'section of the Gemfile. ' \ - 'Gem `%s` should appear before `%s`.' + 'Gem `%{previous}` should appear before `%{current}`.' def on_new_investigation return if processed_source.blank? diff --git a/lib/rubocop/cop/correctors/each_to_for_corrector.rb b/lib/rubocop/cop/correctors/each_to_for_corrector.rb index aa1d299cc070..d5a3e5aefe0f 100644 --- a/lib/rubocop/cop/correctors/each_to_for_corrector.rb +++ b/lib/rubocop/cop/correctors/each_to_for_corrector.rb @@ -6,8 +6,8 @@ module Cop class EachToForCorrector extend NodePattern::Macros - CORRECTION_WITH_ARGUMENTS = 'for %s in %s do' - CORRECTION_WITHOUT_ARGUMENTS = 'for _ in %s do' + CORRECTION_WITH_ARGUMENTS = 'for %{variables} in %{collection} do' + CORRECTION_WITHOUT_ARGUMENTS = 'for _ in %{enumerable} do' def initialize(block_node) @block_node = block_node diff --git a/lib/rubocop/cop/correctors/for_to_each_corrector.rb b/lib/rubocop/cop/correctors/for_to_each_corrector.rb index e54fecd7af87..06ab60ee29c8 100644 --- a/lib/rubocop/cop/correctors/for_to_each_corrector.rb +++ b/lib/rubocop/cop/correctors/for_to_each_corrector.rb @@ -6,7 +6,7 @@ module Cop class ForToEachCorrector extend NodePattern::Macros - CORRECTION = '%s.each do |%s|' + CORRECTION = '%{collection}.each do |%{argument}|' def initialize(for_node) @for_node = for_node diff --git a/lib/rubocop/cop/gemspec/duplicated_assignment.rb b/lib/rubocop/cop/gemspec/duplicated_assignment.rb index a6118a135ca5..5ce4a7930f00 100644 --- a/lib/rubocop/cop/gemspec/duplicated_assignment.rb +++ b/lib/rubocop/cop/gemspec/duplicated_assignment.rb @@ -38,8 +38,8 @@ class DuplicatedAssignment < Base include RangeHelp include GemspecHelp - MSG = '`%s` method calls already given on line ' \ - '%d of the gemspec.' + MSG = '`%{assignment}` method calls already given on line ' \ + '%{line_of_first_occurrence} of the gemspec.' # @!method assignment_method_declarations(node) def_node_search :assignment_method_declarations, <<~PATTERN diff --git a/lib/rubocop/cop/gemspec/ordered_dependencies.rb b/lib/rubocop/cop/gemspec/ordered_dependencies.rb index 79663ce3a940..7b3fad1bc2f2 100644 --- a/lib/rubocop/cop/gemspec/ordered_dependencies.rb +++ b/lib/rubocop/cop/gemspec/ordered_dependencies.rb @@ -56,7 +56,7 @@ class OrderedDependencies < Base MSG = 'Dependencies should be sorted in an alphabetical order within ' \ 'their section of the gemspec. ' \ - 'Dependency `%s` should appear before `%s`.' + 'Dependency `%{previous}` should appear before `%{current}`.' def on_new_investigation return if processed_source.blank? diff --git a/lib/rubocop/cop/gemspec/required_ruby_version.rb b/lib/rubocop/cop/gemspec/required_ruby_version.rb index 4366269d826f..5a825d9c8518 100644 --- a/lib/rubocop/cop/gemspec/required_ruby_version.rb +++ b/lib/rubocop/cop/gemspec/required_ruby_version.rb @@ -57,7 +57,7 @@ class RequiredRubyVersion < Base RESTRICT_ON_SEND = %i[required_ruby_version=].freeze NOT_EQUAL_MSG = '`required_ruby_version` and `TargetRubyVersion` ' \ - '(%s, which may be specified in ' \ + '(%{target_ruby_version}, which may be specified in ' \ '.rubocop.yml) should be equal.' MISSING_MSG = '`required_ruby_version` should be specified.' diff --git a/lib/rubocop/cop/generator.rb b/lib/rubocop/cop/generator.rb index 01dab875907c..2f7739c0ea44 100644 --- a/lib/rubocop/cop/generator.rb +++ b/lib/rubocop/cop/generator.rb @@ -13,7 +13,7 @@ class Generator module RuboCop module Cop - module %s + module %{department} # TODO: Write cop description and example of bad / good code. For every # `SupportedStyle` and unique configuration, there needs to be examples. # Examples must have valid Ruby syntax. Do not use upticks. @@ -53,7 +53,7 @@ module %s # # good # good_foo_method(args) # - class %s < Base + class %{cop_name} < Base # TODO: Implement the cop in here. # # In many cases, you can use a node matcher for matching node pattern. @@ -81,7 +81,7 @@ def on_send(node) SPEC_TEMPLATE = <<~SPEC # frozen_string_literal: true - RSpec.describe RuboCop::Cop::%s::%s, :config do + RSpec.describe RuboCop::Cop::%{department}::%{cop_name}, :config do let(:config) { RuboCop::Config.new } # TODO: Write test code @@ -104,7 +104,7 @@ def on_send(node) CONFIGURATION_ADDED_MESSAGE = '[modify] A configuration for the cop is added into ' \ - '%s.' + '%{configuration_file_path}.' def initialize(name, output: $stdout) @badge = Badge.parse(name) diff --git a/lib/rubocop/cop/generator/configuration_injector.rb b/lib/rubocop/cop/generator/configuration_injector.rb index 882fcb333976..aeff644c0b19 100644 --- a/lib/rubocop/cop/generator/configuration_injector.rb +++ b/lib/rubocop/cop/generator/configuration_injector.rb @@ -8,10 +8,10 @@ class Generator # namespace and injects the provided one in alpha class ConfigurationInjector TEMPLATE = <<~YAML - %s: + %{badge}: Description: 'TODO: Write a description of the cop.' Enabled: pending - VersionAdded: '%s' + VersionAdded: '%{version_added}' YAML def initialize(configuration_file_path:, badge:, version_added: '<>') diff --git a/lib/rubocop/cop/internal_affairs/cop_description.rb b/lib/rubocop/cop/internal_affairs/cop_description.rb index c03899de28a3..c69b63ef1d02 100644 --- a/lib/rubocop/cop/internal_affairs/cop_description.rb +++ b/lib/rubocop/cop/internal_affairs/cop_description.rb @@ -21,7 +21,7 @@ module InternalAffairs class CopDescription < Base extend AutoCorrector - MSG = 'Description should be started with %s instead of `This cop ...`.' + MSG = 'Description should be started with %{suggestion} instead of `This cop ...`.' SPECIAL_WORDS = %w[is can could should will would must may].freeze COP_DESC_OFFENSE_REGEX = \ diff --git a/lib/rubocop/cop/internal_affairs/empty_line_between_expect_offense_and_correction.rb b/lib/rubocop/cop/internal_affairs/empty_line_between_expect_offense_and_correction.rb index 9209ee8cdb9a..7179606b5920 100644 --- a/lib/rubocop/cop/internal_affairs/empty_line_between_expect_offense_and_correction.rb +++ b/lib/rubocop/cop/internal_affairs/empty_line_between_expect_offense_and_correction.rb @@ -33,7 +33,7 @@ module InternalAffairs class EmptyLineBetweenExpectOffenseAndCorrection < Base extend AutoCorrector - MSG = 'Add empty line between `expect_offense` and `%s`.' + MSG = 'Add empty line between `expect_offense` and `%{expect_correction}`.' RESTRICT_ON_SEND = %i[expect_offense].freeze CORRECTION_EXPECTATION_METHODS = %i[expect_correction expect_no_corrections].freeze diff --git a/lib/rubocop/cop/internal_affairs/example_description.rb b/lib/rubocop/cop/internal_affairs/example_description.rb index 2de112afbcc1..4fbd6fef0cc3 100644 --- a/lib/rubocop/cop/internal_affairs/example_description.rb +++ b/lib/rubocop/cop/internal_affairs/example_description.rb @@ -30,7 +30,7 @@ class << self attr_accessor :descriptions end - MSG = 'Description does not match use of `%s`.' + MSG = 'Description does not match use of `%{method_name}`.' RESTRICT_ON_SEND = %i[ expect_offense diff --git a/lib/rubocop/cop/internal_affairs/location_line_equality_comparison.rb b/lib/rubocop/cop/internal_affairs/location_line_equality_comparison.rb index d2345f78df5c..6ac3f54e1194 100644 --- a/lib/rubocop/cop/internal_affairs/location_line_equality_comparison.rb +++ b/lib/rubocop/cop/internal_affairs/location_line_equality_comparison.rb @@ -18,7 +18,7 @@ module InternalAffairs class LocationLineEqualityComparison < Base extend AutoCorrector - MSG = 'Use `%s`.' + MSG = 'Use `%{preferred}`.' # @!method line_send(node) def_node_matcher :line_send, <<~PATTERN diff --git a/lib/rubocop/cop/internal_affairs/method_name_end_with.rb b/lib/rubocop/cop/internal_affairs/method_name_end_with.rb index 18b4fa044235..4e5e0e52e1bf 100644 --- a/lib/rubocop/cop/internal_affairs/method_name_end_with.rb +++ b/lib/rubocop/cop/internal_affairs/method_name_end_with.rb @@ -29,7 +29,7 @@ class MethodNameEndWith < Base include RangeHelp extend AutoCorrector - MSG = 'Use `%s` instead of `%s`.' + MSG = 'Use `%{method_name}` instead of `%{method_suffix}`.' SUGGEST_METHOD_FOR_SUFFIX = { '=' => 'assignment_method?', '!' => 'bang_method?', diff --git a/lib/rubocop/cop/internal_affairs/method_name_equal.rb b/lib/rubocop/cop/internal_affairs/method_name_equal.rb index da6388d8d6c2..4fe46a180db5 100644 --- a/lib/rubocop/cop/internal_affairs/method_name_equal.rb +++ b/lib/rubocop/cop/internal_affairs/method_name_equal.rb @@ -16,7 +16,7 @@ class MethodNameEqual < Base include RangeHelp extend AutoCorrector - MSG = 'Use `method?(%s)` instead of `method_name == %s`.' + MSG = 'Use `method?(%{method_name})` instead of `method_name == %{method_name}`.' RESTRICT_ON_SEND = %i[==].freeze # @!method method_name?(node) diff --git a/lib/rubocop/cop/internal_affairs/node_matcher_directive.rb b/lib/rubocop/cop/internal_affairs/node_matcher_directive.rb index f4938abcd95c..d6092f80fa1e 100644 --- a/lib/rubocop/cop/internal_affairs/node_matcher_directive.rb +++ b/lib/rubocop/cop/internal_affairs/node_matcher_directive.rb @@ -23,9 +23,9 @@ class NodeMatcherDirective < Base extend AutoCorrector include RangeHelp - MSG = 'Precede `%s` with a `@!method` YARD directive.' + MSG = 'Precede `%{method}` with a `@!method` YARD directive.' MSG_WRONG_NAME = '`@!method` YARD directive has invalid method name, ' \ - 'use `%s` instead of `%s`.' + 'use `%{expected}` instead of `%{actual}`.' MSG_TOO_MANY = 'Multiple `@!method` YARD directives found for this matcher.' RESTRICT_ON_SEND = %i[def_node_matcher def_node_search].to_set.freeze diff --git a/lib/rubocop/cop/internal_affairs/node_type_predicate.rb b/lib/rubocop/cop/internal_affairs/node_type_predicate.rb index ac188c50e332..f3c5ccb45053 100644 --- a/lib/rubocop/cop/internal_affairs/node_type_predicate.rb +++ b/lib/rubocop/cop/internal_affairs/node_type_predicate.rb @@ -16,7 +16,7 @@ module InternalAffairs class NodeTypePredicate < Base extend AutoCorrector - MSG = 'Use `#%s_type?` to check node type.' + MSG = 'Use `#%{type}_type?` to check node type.' RESTRICT_ON_SEND = %i[==].freeze # @!method node_type_check(node) diff --git a/lib/rubocop/cop/internal_affairs/offense_location_keyword.rb b/lib/rubocop/cop/internal_affairs/offense_location_keyword.rb index 2abcff8f3900..2cb85d409c79 100644 --- a/lib/rubocop/cop/internal_affairs/offense_location_keyword.rb +++ b/lib/rubocop/cop/internal_affairs/offense_location_keyword.rb @@ -16,7 +16,7 @@ module InternalAffairs class OffenseLocationKeyword < Base extend AutoCorrector - MSG = 'Use `:%s` as the location argument to `#add_offense`.' + MSG = 'Use `:%{keyword}` as the location argument to `#add_offense`.' RESTRICT_ON_SEND = %i[add_offense].freeze def on_send(node) diff --git a/lib/rubocop/cop/internal_affairs/redundant_described_class_as_subject.rb b/lib/rubocop/cop/internal_affairs/redundant_described_class_as_subject.rb index b9b6946f4fd9..11858d6ed2d1 100644 --- a/lib/rubocop/cop/internal_affairs/redundant_described_class_as_subject.rb +++ b/lib/rubocop/cop/internal_affairs/redundant_described_class_as_subject.rb @@ -19,7 +19,7 @@ class RedundantDescribedClassAsSubject < Base include RangeHelp extend AutoCorrector - MSG = 'Remove the redundant `subject`%s.' + MSG = 'Remove the redundant `subject`%{additional_message}.' # @!method described_class_subject?(node) def_node_matcher :described_class_subject?, <<~PATTERN diff --git a/lib/rubocop/cop/internal_affairs/redundant_let_rubocop_config_new.rb b/lib/rubocop/cop/internal_affairs/redundant_let_rubocop_config_new.rb index 7a7deb112e7f..89712cc9698a 100644 --- a/lib/rubocop/cop/internal_affairs/redundant_let_rubocop_config_new.rb +++ b/lib/rubocop/cop/internal_affairs/redundant_let_rubocop_config_new.rb @@ -23,7 +23,7 @@ class RedundantLetRuboCopConfigNew < Base include RangeHelp extend AutoCorrector - MSG = 'Remove `let` that is `RuboCop::Config.new` with no arguments%s.' + MSG = 'Remove `let` that is `RuboCop::Config.new` with no arguments%{additional_message}.' # @!method let_rubocop_config_new?(node) def_node_matcher :let_rubocop_config_new?, <<~PATTERN diff --git a/lib/rubocop/cop/internal_affairs/undefined_config.rb b/lib/rubocop/cop/internal_affairs/undefined_config.rb index bb248c80c4bb..b349df98f8c6 100644 --- a/lib/rubocop/cop/internal_affairs/undefined_config.rb +++ b/lib/rubocop/cop/internal_affairs/undefined_config.rb @@ -9,7 +9,7 @@ class UndefinedConfig < Base Safe SafeAutoCorrect AutoCorrect Severity StyleGuide Details Reference Include Exclude ].freeze RESTRICT_ON_SEND = %i[[] fetch].freeze - MSG = '`%s` is not defined in the configuration for `%s` ' \ + MSG = '`%{name}` is not defined in the configuration for `%{cop}` ' \ 'in `config/default.yml`.' # @!method cop_class_def(node) diff --git a/lib/rubocop/cop/layout/access_modifier_indentation.rb b/lib/rubocop/cop/layout/access_modifier_indentation.rb index 82d887e0fd08..67ef91c2c320 100644 --- a/lib/rubocop/cop/layout/access_modifier_indentation.rb +++ b/lib/rubocop/cop/layout/access_modifier_indentation.rb @@ -38,7 +38,7 @@ class AccessModifierIndentation < Base include RangeHelp extend AutoCorrector - MSG = '%