diff --git a/changelog/fix_manually_fix_the_remaining_offense_after.md b/changelog/fix_manually_fix_the_remaining_offense_after.md new file mode 100644 index 00000000000..96c0c8b8f06 --- /dev/null +++ b/changelog/fix_manually_fix_the_remaining_offense_after.md @@ -0,0 +1 @@ +* [#7592](https://github.com/rubocop/rubocop/pull/7592): Add cop `Layout/LineEndStringConcatenationIndentation`. ([@jonas054][]) diff --git a/config/default.yml b/config/default.yml index 6864a64a842..6bac2bb60eb 100644 --- a/config/default.yml +++ b/config/default.yml @@ -270,8 +270,8 @@ Layout/AccessModifierIndentation: SupportedStyles: - outdent - indent - # By default, the indentation width from Layout/IndentationWidth is used - # But it can be overridden by setting this parameter + # By default the indentation width from `Layout/IndentationWidth` is used, + # but it can be overridden by setting this parameter. IndentationWidth: ~ Layout/ArgumentAlignment: @@ -299,8 +299,8 @@ Layout/ArgumentAlignment: SupportedStyles: - with_first_argument - with_fixed_indentation - # By default, the indentation width from Layout/IndentationWidth is used - # But it can be overridden by setting this parameter + # By default the indentation width from `Layout/IndentationWidth` is used, + # but it can be overridden by setting this parameter. IndentationWidth: ~ Layout/ArrayAlignment: @@ -328,8 +328,8 @@ Layout/ArrayAlignment: SupportedStyles: - with_first_element - with_fixed_indentation - # By default, the indentation width from Layout/IndentationWidth is used - # But it can be overridden by setting this parameter + # By default the indentation width from `Layout/IndentationWidth` is used, + # but it can be overridden by setting this parameter. IndentationWidth: ~ Layout/AssignmentIndentation: @@ -339,8 +339,8 @@ Layout/AssignmentIndentation: Enabled: true VersionAdded: '0.49' VersionChanged: '0.77' - # By default, the indentation width from `Layout/IndentationWidth` is used - # But it can be overridden by setting this parameter + # By default the indentation width from `Layout/IndentationWidth` is used, + # but it can be overridden by setting this parameter. IndentationWidth: ~ Layout/BeginEndAlignment: @@ -387,9 +387,9 @@ Layout/CaseIndentation: - case - end IndentOneStep: false - # By default, the indentation width from `Layout/IndentationWidth` is used. - # But it can be overridden by setting this parameter. - # This only matters if `IndentOneStep` is `true` + # By default the indentation width from `Layout/IndentationWidth` is used, + # but it can be overridden by setting this parameter. + # This only matters if `IndentOneStep` is `true`. IndentationWidth: ~ Layout/ClassStructure: @@ -666,8 +666,8 @@ Layout/FirstArgumentIndentation: # Same as `special_for_inner_method_call` except that the special rule only # applies if the outer method call encloses its arguments in parentheses. - special_for_inner_method_call_in_parentheses - # By default, the indentation width from `Layout/IndentationWidth` is used - # But it can be overridden by setting this parameter + # By default the indentation width from `Layout/IndentationWidth` is used, + # but it can be overridden by setting this parameter. IndentationWidth: ~ Layout/FirstArrayElementIndentation: @@ -693,8 +693,8 @@ Layout/FirstArrayElementIndentation: - special_inside_parentheses - consistent - align_brackets - # By default, the indentation width from `Layout/IndentationWidth` is used - # But it can be overridden by setting this parameter + # By default the indentation width from `Layout/IndentationWidth` is used, + # but it can be overridden by setting this parameter. IndentationWidth: ~ Layout/FirstArrayElementLineBreak: @@ -725,8 +725,8 @@ Layout/FirstHashElementIndentation: - special_inside_parentheses - consistent - align_braces - # By default, the indentation width from `Layout/IndentationWidth` is used - # But it can be overridden by setting this parameter + # By default the indentation width from `Layout/IndentationWidth` is used, + # but it can be overridden by setting this parameter. IndentationWidth: ~ Layout/FirstHashElementLineBreak: @@ -761,8 +761,8 @@ Layout/FirstParameterIndentation: SupportedStyles: - consistent - align_parentheses - # By default, the indentation width from `Layout/IndentationWidth` is used - # But it can be overridden by setting this parameter + # By default the indentation width from `Layout/IndentationWidth` is used, + # but it can be overridden by setting this parameter. IndentationWidth: ~ Layout/HashAlignment: @@ -883,8 +883,8 @@ Layout/IndentationStyle: Enabled: true VersionAdded: '0.49' VersionChanged: '0.82' - # By default, the indentation width from Layout/IndentationWidth is used - # But it can be overridden by setting this parameter + # By default the indentation width from `Layout/IndentationWidth` is used, + # but it can be overridden by setting this parameter. # It is used during auto-correction to determine how many spaces should # replace each tab. IndentationWidth: ~ @@ -923,6 +923,20 @@ Layout/LeadingEmptyLines: VersionAdded: '0.57' VersionChanged: '0.77' +Layout/LineEndStringConcatenationIndentation: + Description: >- + Checks the indentation of the next line after a line that + ends with a string literal and a backslash. + Enabled: pending + VersionAdded: '<>' + EnforcedStyle: aligned + SupportedStyles: + - aligned + - indented + # By default the indentation width from `Layout/IndentationWidth` is used, + # but it can be overridden by setting this parameter. + IndentationWidth: ~ + Layout/LineLength: Description: 'Checks that line length does not exceed the configured limit.' StyleGuide: '#max-line-length' @@ -1053,8 +1067,8 @@ Layout/MultilineMethodCallIndentation: - aligned - indented - indented_relative_to_receiver - # By default, the indentation width from Layout/IndentationWidth is used - # But it can be overridden by setting this parameter + # By default the indentation width from `Layout/IndentationWidth` is used, + # but it can be overridden by setting this parameter. IndentationWidth: ~ Layout/MultilineMethodDefinitionBraceLayout: @@ -1083,8 +1097,8 @@ Layout/MultilineOperationIndentation: SupportedStyles: - aligned - indented - # By default, the indentation width from `Layout/IndentationWidth` is used - # But it can be overridden by setting this parameter + # By default the indentation width from `Layout/IndentationWidth` is used, + # but it can be overridden by setting this parameter. IndentationWidth: ~ Layout/ParameterAlignment: @@ -1112,8 +1126,8 @@ Layout/ParameterAlignment: SupportedStyles: - with_first_parameter - with_fixed_indentation - # By default, the indentation width from Layout/IndentationWidth is used - # But it can be overridden by setting this parameter + # By default the indentation width from `Layout/IndentationWidth` is used, + # but it can be overridden by setting this parameter. IndentationWidth: ~ Layout/RedundantLineBreak: diff --git a/lib/rubocop.rb b/lib/rubocop.rb index 7d31b684fff..2e945119938 100644 --- a/lib/rubocop.rb +++ b/lib/rubocop.rb @@ -211,6 +211,7 @@ require_relative 'rubocop/cop/layout/initial_indentation' require_relative 'rubocop/cop/layout/leading_comment_space' require_relative 'rubocop/cop/layout/leading_empty_lines' +require_relative 'rubocop/cop/layout/line_end_string_concatenation_indentation' require_relative 'rubocop/cop/layout/line_length' require_relative 'rubocop/cop/layout/multiline_array_brace_layout' require_relative 'rubocop/cop/layout/multiline_array_line_breaks' diff --git a/lib/rubocop/cli/command/suggest_extensions.rb b/lib/rubocop/cli/command/suggest_extensions.rb index c71fc697717..ffd531335a7 100644 --- a/lib/rubocop/cli/command/suggest_extensions.rb +++ b/lib/rubocop/cli/command/suggest_extensions.rb @@ -19,7 +19,7 @@ def run puts puts 'Tip: Based on detected gems, the following '\ - 'RuboCop extension libraries might be helpful:' + 'RuboCop extension libraries might be helpful:' extensions.sort.each do |extension| puts " * #{extension} (https://github.com/rubocop/#{extension})" @@ -27,8 +27,8 @@ def run puts puts 'You can opt out of this message by adding the following to your config '\ - '(see https://docs.rubocop.org/rubocop/extensions.html#extension-suggestions '\ - 'for more options):' + '(see https://docs.rubocop.org/rubocop/extensions.html#extension-suggestions '\ + 'for more options):' puts ' AllCops:' puts ' SuggestExtensions: false' diff --git a/lib/rubocop/config_loader.rb b/lib/rubocop/config_loader.rb index e62a5a1b0e6..13b736c9a2c 100644 --- a/lib/rubocop/config_loader.rb +++ b/lib/rubocop/config_loader.rb @@ -229,7 +229,7 @@ def check_duplication(yaml_code, absolute_path) line1 = key1.start_line + 1 line2 = key2.start_line + 1 "#{smart_path}:#{line1}: " \ - "`#{value}` is concealed by line #{line2}" + "`#{value}` is concealed by line #{line2}" else "#{smart_path}: `#{value}` is concealed by duplicate" end diff --git a/lib/rubocop/config_validator.rb b/lib/rubocop/config_validator.rb index ae8e54e785e..f8c7d3ecd1a 100644 --- a/lib/rubocop/config_validator.rb +++ b/lib/rubocop/config_validator.rb @@ -81,11 +81,11 @@ def check_target_ruby msg = if last_version "RuboCop found unsupported Ruby version #{target_ruby_version} " \ - "in #{source}. #{target_ruby_version}-compatible " \ - "analysis was dropped after version #{last_version}." + "in #{source}. #{target_ruby_version}-compatible " \ + "analysis was dropped after version #{last_version}." else 'RuboCop found unknown Ruby version ' \ - "#{target_ruby_version.inspect} in #{source}." + "#{target_ruby_version.inspect} in #{source}." end msg += "\nSupported versions: #{TargetRuby.supported_versions.join(', ')}" @@ -179,8 +179,8 @@ def validate_enforced_styles(valid_cop_names) # rubocop:todo Metrics/AbcSize next if validate_support_and_has_list(name, style, valid) msg = "invalid #{style_name} '#{style}' for #{name} found in " \ - "#{smart_loaded_path}\n" \ - "Valid choices are: #{valid.join(', ')}" + "#{smart_loaded_path}\n" \ + "Valid choices are: #{valid.join(', ')}" raise ValidationError, msg end end diff --git a/lib/rubocop/cop/base.rb b/lib/rubocop/cop/base.rb index fbbec231bdf..da74f7d55b7 100644 --- a/lib/rubocop/cop/base.rb +++ b/lib/rubocop/cop/base.rb @@ -261,7 +261,7 @@ def ready # @deprecated Make potential errors with previous API more obvious def offenses raise 'The offenses are not directly available; ' \ - 'they are returned as the result of the investigation' + 'they are returned as the result of the investigation' end ### Reserved for Commissioner @@ -441,7 +441,7 @@ def custom_severity severity.to_sym else message = "Warning: Invalid severity '#{severity}'. " \ - "Valid severities are #{Severity::NAMES.join(', ')}." + "Valid severities are #{Severity::NAMES.join(', ')}." warn(Rainbow(message).red) end end diff --git a/lib/rubocop/cop/bundler/duplicated_gem.rb b/lib/rubocop/cop/bundler/duplicated_gem.rb index 4f2e5c35e1c..6f5b4ad6748 100644 --- a/lib/rubocop/cop/bundler/duplicated_gem.rb +++ b/lib/rubocop/cop/bundler/duplicated_gem.rb @@ -39,7 +39,7 @@ class DuplicatedGem < Base include RangeHelp MSG = 'Gem `%s` requirements already given on line '\ - '%d of the Gemfile.' + '%d of the Gemfile.' def on_new_investigation return if processed_source.blank? diff --git a/lib/rubocop/cop/generator.rb b/lib/rubocop/cop/generator.rb index c1d1057bc11..c03f5da170a 100644 --- a/lib/rubocop/cop/generator.rb +++ b/lib/rubocop/cop/generator.rb @@ -104,7 +104,7 @@ def on_send(node) CONFIGURATION_ADDED_MESSAGE = '[modify] A configuration for the cop is added into ' \ - '%s.' + '%s.' def initialize(name, github_user, output: $stdout) @badge = Badge.parse(name) diff --git a/lib/rubocop/cop/internal_affairs/node_matcher_directive.rb b/lib/rubocop/cop/internal_affairs/node_matcher_directive.rb index f1956529a76..1ea2426e693 100644 --- a/lib/rubocop/cop/internal_affairs/node_matcher_directive.rb +++ b/lib/rubocop/cop/internal_affairs/node_matcher_directive.rb @@ -25,7 +25,7 @@ class NodeMatcherDirective < Base MSG = 'Preceed `%s` with a `@!method` YARD directive.' MSG_WRONG_NAME = '`@!method` YARD directive has invalid method name, ' \ - 'use `%s` instead of `%s`.' + 'use `%s` instead of `%s`.' 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/layout/argument_alignment.rb b/lib/rubocop/cop/layout/argument_alignment.rb index 1bac3d6df34..2feebfc63ea 100644 --- a/lib/rubocop/cop/layout/argument_alignment.rb +++ b/lib/rubocop/cop/layout/argument_alignment.rb @@ -50,7 +50,7 @@ class ArgumentAlignment < Base ALIGN_PARAMS_MSG = 'Align the arguments of a method call if they span more than one line.' FIXED_INDENT_MSG = 'Use one level of indentation for arguments ' \ - 'following the first line of a multi-line method call.' + 'following the first line of a multi-line method call.' def on_send(node) first_arg = node.first_argument diff --git a/lib/rubocop/cop/layout/array_alignment.rb b/lib/rubocop/cop/layout/array_alignment.rb index 654f1497b14..69c5acf36c5 100644 --- a/lib/rubocop/cop/layout/array_alignment.rb +++ b/lib/rubocop/cop/layout/array_alignment.rb @@ -38,10 +38,10 @@ class ArrayAlignment < Base extend AutoCorrector ALIGN_ELEMENTS_MSG = 'Align the elements of an array literal ' \ - 'if they span more than one line.' + 'if they span more than one line.' FIXED_INDENT_MSG = 'Use one level of indentation for elements ' \ - 'following the first line of a multi-line array.' + 'following the first line of a multi-line array.' def on_array(node) return if node.children.size < 2 diff --git a/lib/rubocop/cop/layout/block_alignment.rb b/lib/rubocop/cop/layout/block_alignment.rb index 5ad4cdd40c6..ef23db82246 100644 --- a/lib/rubocop/cop/layout/block_alignment.rb +++ b/lib/rubocop/cop/layout/block_alignment.rb @@ -210,7 +210,7 @@ def alt_start_msg(start_loc, source_line_column) def format_source_line_column(source_line_column) "`#{source_line_column[:source]}` at #{source_line_column[:line]}, " \ - "#{source_line_column[:column]}" + "#{source_line_column[:column]}" end def compute_start_col(ancestor_node, node) diff --git a/lib/rubocop/cop/layout/comment_indentation.rb b/lib/rubocop/cop/layout/comment_indentation.rb index b6722d7c849..93db4d5b1bd 100644 --- a/lib/rubocop/cop/layout/comment_indentation.rb +++ b/lib/rubocop/cop/layout/comment_indentation.rb @@ -37,7 +37,7 @@ class CommentIndentation < Base extend AutoCorrector MSG = 'Incorrect indentation detected (column %d ' \ - 'instead of %d).' + 'instead of %d).' def on_new_investigation processed_source.comments.each { |comment| check(comment) } diff --git a/lib/rubocop/cop/layout/first_array_element_indentation.rb b/lib/rubocop/cop/layout/first_array_element_indentation.rb index 599a4216e0a..f28ea82e887 100644 --- a/lib/rubocop/cop/layout/first_array_element_indentation.rb +++ b/lib/rubocop/cop/layout/first_array_element_indentation.rb @@ -161,10 +161,10 @@ def msg(left_parenthesis) 'Indent the right bracket the same as the left bracket.' elsif style == :special_inside_parentheses && left_parenthesis 'Indent the right bracket the same as the first position ' \ - 'after the preceding left parenthesis.' + 'after the preceding left parenthesis.' else 'Indent the right bracket the same as the start of the line' \ - ' where the left bracket is.' + ' where the left bracket is.' end end end diff --git a/lib/rubocop/cop/layout/first_hash_element_indentation.rb b/lib/rubocop/cop/layout/first_hash_element_indentation.rb index 42e49389c43..c25a7e641ab 100644 --- a/lib/rubocop/cop/layout/first_hash_element_indentation.rb +++ b/lib/rubocop/cop/layout/first_hash_element_indentation.rb @@ -178,10 +178,10 @@ def message_for_right_brace(left_parenthesis) 'Indent the right brace the same as the left brace.' elsif style == :special_inside_parentheses && left_parenthesis 'Indent the right brace the same as the first position ' \ - 'after the preceding left parenthesis.' + 'after the preceding left parenthesis.' else 'Indent the right brace the same as the start of the line ' \ - 'where the left brace is.' + 'where the left brace is.' end end diff --git a/lib/rubocop/cop/layout/first_parameter_indentation.rb b/lib/rubocop/cop/layout/first_parameter_indentation.rb index 33d174c2bdb..6ab0a0d34ad 100644 --- a/lib/rubocop/cop/layout/first_parameter_indentation.rb +++ b/lib/rubocop/cop/layout/first_parameter_indentation.rb @@ -48,7 +48,7 @@ class FirstParameterIndentation < Base extend AutoCorrector MSG = 'Use %d spaces for indentation ' \ - 'in method args, relative to %s.' + 'in method args, relative to %s.' def on_def(node) return if node.arguments.empty? diff --git a/lib/rubocop/cop/layout/hash_alignment.rb b/lib/rubocop/cop/layout/hash_alignment.rb index e66423fe657..33870a0b77f 100644 --- a/lib/rubocop/cop/layout/hash_alignment.rb +++ b/lib/rubocop/cop/layout/hash_alignment.rb @@ -180,14 +180,15 @@ class HashAlignment < Base include RangeHelp extend AutoCorrector - MESSAGES = { KeyAlignment => 'Align the keys of a hash literal if ' \ - 'they span more than one line.', - SeparatorAlignment => 'Align the separators of a hash ' \ - 'literal if they span more than one line.', - TableAlignment => 'Align the keys and values of a hash ' \ - 'literal if they span more than one line.', - KeywordSplatAlignment => 'Align keyword splats with the ' \ - 'rest of the hash if it spans more than one line.' }.freeze + MESSAGES = { + KeyAlignment => 'Align the keys of a hash literal if they span more than one line.', + SeparatorAlignment => 'Align the separators of a hash literal if they span more than ' \ + 'one line.', + TableAlignment => 'Align the keys and values of a hash literal if they span more than ' \ + 'one line.', + KeywordSplatAlignment => 'Align keyword splats with the rest of the hash if it spans ' \ + 'more than one line.' + }.freeze def on_send(node) return if double_splat?(node) diff --git a/lib/rubocop/cop/layout/heredoc_argument_closing_parenthesis.rb b/lib/rubocop/cop/layout/heredoc_argument_closing_parenthesis.rb index b10a3550b2d..f2af6e4a324 100644 --- a/lib/rubocop/cop/layout/heredoc_argument_closing_parenthesis.rb +++ b/lib/rubocop/cop/layout/heredoc_argument_closing_parenthesis.rb @@ -55,7 +55,7 @@ class HeredocArgumentClosingParenthesis < Base extend AutoCorrector MSG = 'Put the closing parenthesis for a method call with a ' \ - 'HEREDOC parameter on the same line as the HEREDOC opening.' + 'HEREDOC parameter on the same line as the HEREDOC opening.' def self.autocorrect_incompatible_with [Style::TrailingCommaInArguments] diff --git a/lib/rubocop/cop/layout/line_end_string_concatenation_indentation.rb b/lib/rubocop/cop/layout/line_end_string_concatenation_indentation.rb new file mode 100644 index 00000000000..f7d05840799 --- /dev/null +++ b/lib/rubocop/cop/layout/line_end_string_concatenation_indentation.rb @@ -0,0 +1,122 @@ +# frozen_string_literal: true + +module RuboCop + module Cop + module Layout + # This cop checks the indentation of the next line after a line that ends with a string + # literal and a backslash. + # + # If `EnforcedStyle: aligned` is set, the concatenated string parts shall be aligned with the + # first part. There are some exceptions, such as implicit return values, where the + # concatenated string parts shall be indented regardless of `EnforcedStyle` configuration. + # + # If `EnforcedStyle: indented` is set, it's the second line that shall be indented one step + # more than the first line. Lines 3 and forward shall be aligned with line 2. Here too there + # are exceptions. Values in a hash literal are always aligned. + # + # @example + # # bad + # def some_method + # 'x' \ + # 'y' \ + # 'z' + # end + # + # my_hash = { + # first: 'a message' \ + # 'in two parts' + # } + # + # # good + # def some_method + # 'x' \ + # 'y' \ + # 'z' + # end + # + # my_hash = { + # first: 'a message' \ + # 'in two parts' + # } + # + # @example EnforcedStyle: aligned (default) + # # bad + # puts 'x' \ + # 'y' + # + # # good + # puts 'x' \ + # 'y' + # + # @example EnforcedStyle: indented + # # bad + # result = 'x' \ + # 'y' + # + # # good + # result = 'x' \ + # 'y' + # + class LineEndStringConcatenationIndentation < Base + include ConfigurableEnforcedStyle + include Alignment + extend AutoCorrector + + MSG_ALIGN = 'Align parts of a string concatenated with backslash.' + MSG_INDENT = 'Indent the first part of a string concatenated with backslash.' + PARENT_TYPES_FOR_INDENTED = [nil, :block, :begin, :def, :defs, :if].freeze + + def on_dstr(node) + return unless strings_concatenated_with_backslash?(node) + + children = node.children + if style == :aligned && !always_indented?(node) || always_aligned?(node) + check_aligned(children, 1) + else + check_indented(children) + check_aligned(children, 2) + end + end + + def autocorrect(corrector, node) + AlignmentCorrector.correct(corrector, processed_source, node, @column_delta) + end + + private + + def strings_concatenated_with_backslash?(dstr_node) + !dstr_node.heredoc? && + dstr_node.children.length > 1 && + dstr_node.children.all? { |c| c.str_type? || c.dstr_type? } + end + + def always_indented?(dstr_node) + PARENT_TYPES_FOR_INDENTED.include?(dstr_node.parent&.type) + end + + def always_aligned?(dstr_node) + dstr_node.parent&.pair_type? + end + + def check_aligned(children, start_index) + base_column = children[start_index - 1].loc.column + children[start_index..-1].each do |child| + @column_delta = base_column - child.loc.column + add_offense_and_correction(child, MSG_ALIGN) if @column_delta != 0 + base_column = child.loc.column + end + end + + def check_indented(children) + base_column = children[0].source_range.source_line =~ /\S/ + @column_delta = base_column + configured_indentation_width - children[1].loc.column + add_offense_and_correction(children[1], MSG_INDENT) if @column_delta != 0 + end + + def add_offense_and_correction(node, message) + add_offense(node, message: message) { |corrector| autocorrect(corrector, node) } + end + end + end + end +end diff --git a/lib/rubocop/cop/layout/multiline_array_brace_layout.rb b/lib/rubocop/cop/layout/multiline_array_brace_layout.rb index 122a4d1d55e..42d1acd1a80 100644 --- a/lib/rubocop/cop/layout/multiline_array_brace_layout.rb +++ b/lib/rubocop/cop/layout/multiline_array_brace_layout.rb @@ -93,18 +93,18 @@ class MultilineArrayBraceLayout < Base extend AutoCorrector SAME_LINE_MESSAGE = 'The closing array brace must be on the same ' \ - 'line as the last array element when the opening brace is on the ' \ - 'same line as the first array element.' + 'line as the last array element when the opening brace is on the ' \ + 'same line as the first array element.' NEW_LINE_MESSAGE = 'The closing array brace must be on the line ' \ - 'after the last array element when the opening brace is on a ' \ - 'separate line from the first array element.' + 'after the last array element when the opening brace is on a ' \ + 'separate line from the first array element.' ALWAYS_NEW_LINE_MESSAGE = 'The closing array brace must be on the ' \ - 'line after the last array element.' + 'line after the last array element.' ALWAYS_SAME_LINE_MESSAGE = 'The closing array brace must be on the ' \ - 'same line as the last array element.' + 'same line as the last array element.' def on_array(node) check_brace_layout(node) diff --git a/lib/rubocop/cop/layout/multiline_assignment_layout.rb b/lib/rubocop/cop/layout/multiline_assignment_layout.rb index 4ef966ba25b..12fa451bb61 100644 --- a/lib/rubocop/cop/layout/multiline_assignment_layout.rb +++ b/lib/rubocop/cop/layout/multiline_assignment_layout.rb @@ -64,10 +64,10 @@ class MultilineAssignmentLayout < Base extend AutoCorrector NEW_LINE_OFFENSE = 'Right hand side of multi-line assignment is on ' \ - 'the same line as the assignment operator `=`.' + 'the same line as the assignment operator `=`.' SAME_LINE_OFFENSE = 'Right hand side of multi-line assignment is not ' \ - 'on the same line as the assignment operator `=`.' + 'on the same line as the assignment operator `=`.' def check_assignment(node, rhs) return if node.send_type? && node.loc.operator&.source != '=' diff --git a/lib/rubocop/cop/layout/multiline_hash_brace_layout.rb b/lib/rubocop/cop/layout/multiline_hash_brace_layout.rb index b86ff804856..ee92a9dda64 100644 --- a/lib/rubocop/cop/layout/multiline_hash_brace_layout.rb +++ b/lib/rubocop/cop/layout/multiline_hash_brace_layout.rb @@ -93,18 +93,18 @@ class MultilineHashBraceLayout < Base extend AutoCorrector SAME_LINE_MESSAGE = 'Closing hash brace must be on the same line as ' \ - 'the last hash element when opening brace is on the same line as ' \ - 'the first hash element.' + 'the last hash element when opening brace is on the same line as ' \ + 'the first hash element.' NEW_LINE_MESSAGE = 'Closing hash brace must be on the line after ' \ - 'the last hash element when opening brace is on a separate line ' \ - 'from the first hash element.' + 'the last hash element when opening brace is on a separate line ' \ + 'from the first hash element.' ALWAYS_NEW_LINE_MESSAGE = 'Closing hash brace must be on the line ' \ - 'after the last hash element.' + 'after the last hash element.' ALWAYS_SAME_LINE_MESSAGE = 'Closing hash brace must be on the same ' \ - 'line as the last hash element.' + 'line as the last hash element.' def on_hash(node) check_brace_layout(node) diff --git a/lib/rubocop/cop/layout/multiline_method_call_brace_layout.rb b/lib/rubocop/cop/layout/multiline_method_call_brace_layout.rb index 3f6821143c1..ff2c9f03932 100644 --- a/lib/rubocop/cop/layout/multiline_method_call_brace_layout.rb +++ b/lib/rubocop/cop/layout/multiline_method_call_brace_layout.rb @@ -93,18 +93,18 @@ class MultilineMethodCallBraceLayout < Base extend AutoCorrector SAME_LINE_MESSAGE = 'Closing method call brace must be on the ' \ - 'same line as the last argument when opening brace is on the same ' \ - 'line as the first argument.' + 'same line as the last argument when opening brace is on the same ' \ + 'line as the first argument.' NEW_LINE_MESSAGE = 'Closing method call brace must be on the ' \ - 'line after the last argument when opening brace is on a separate ' \ - 'line from the first argument.' + 'line after the last argument when opening brace is on a separate ' \ + 'line from the first argument.' ALWAYS_NEW_LINE_MESSAGE = 'Closing method call brace must be on ' \ - 'the line after the last argument.' + 'the line after the last argument.' ALWAYS_SAME_LINE_MESSAGE = 'Closing method call brace must be on ' \ - 'the same line as the last argument.' + 'the same line as the last argument.' def on_send(node) check_brace_layout(node) diff --git a/lib/rubocop/cop/layout/multiline_method_definition_brace_layout.rb b/lib/rubocop/cop/layout/multiline_method_definition_brace_layout.rb index d8f6b7c3629..7249f577a0b 100644 --- a/lib/rubocop/cop/layout/multiline_method_definition_brace_layout.rb +++ b/lib/rubocop/cop/layout/multiline_method_definition_brace_layout.rb @@ -105,18 +105,18 @@ class MultilineMethodDefinitionBraceLayout < Base extend AutoCorrector SAME_LINE_MESSAGE = 'Closing method definition brace must be on the ' \ - 'same line as the last parameter when opening brace is on the same ' \ - 'line as the first parameter.' + 'same line as the last parameter when opening brace is on the same ' \ + 'line as the first parameter.' NEW_LINE_MESSAGE = 'Closing method definition brace must be on the ' \ - 'line after the last parameter when opening brace is on a separate ' \ - 'line from the first parameter.' + 'line after the last parameter when opening brace is on a separate ' \ + 'line from the first parameter.' ALWAYS_NEW_LINE_MESSAGE = 'Closing method definition brace must be ' \ - 'on the line after the last parameter.' + 'on the line after the last parameter.' ALWAYS_SAME_LINE_MESSAGE = 'Closing method definition brace must be ' \ - 'on the same line as the last parameter.' + 'on the same line as the last parameter.' def on_def(node) check_brace_layout(node.arguments) diff --git a/lib/rubocop/cop/layout/multiline_operation_indentation.rb b/lib/rubocop/cop/layout/multiline_operation_indentation.rb index 62b4a4b022f..fc97b0a1c76 100644 --- a/lib/rubocop/cop/layout/multiline_operation_indentation.rb +++ b/lib/rubocop/cop/layout/multiline_operation_indentation.rb @@ -59,9 +59,9 @@ def validate_config return unless style == :aligned && cop_config['IndentationWidth'] raise ValidationError, 'The `Layout/MultilineOperationIndentation`' \ - ' cop only accepts an `IndentationWidth` ' \ - 'configuration parameter when ' \ - '`EnforcedStyle` is `indented`.' + ' cop only accepts an `IndentationWidth` ' \ + 'configuration parameter when ' \ + '`EnforcedStyle` is `indented`.' end private diff --git a/lib/rubocop/cop/layout/parameter_alignment.rb b/lib/rubocop/cop/layout/parameter_alignment.rb index 318dec1fee5..fc6db202c95 100644 --- a/lib/rubocop/cop/layout/parameter_alignment.rb +++ b/lib/rubocop/cop/layout/parameter_alignment.rb @@ -73,10 +73,10 @@ class ParameterAlignment < Base extend AutoCorrector ALIGN_PARAMS_MSG = 'Align the parameters of a method definition if ' \ - 'they span more than one line.' + 'they span more than one line.' FIXED_INDENT_MSG = 'Use one level of indentation for parameters ' \ - 'following the first line of a multi-line method definition.' + 'following the first line of a multi-line method definition.' def on_def(node) return if node.arguments.size < 2 diff --git a/lib/rubocop/cop/layout/space_around_operators.rb b/lib/rubocop/cop/layout/space_around_operators.rb index 3e826463402..3e72bb23bfa 100644 --- a/lib/rubocop/cop/layout/space_around_operators.rb +++ b/lib/rubocop/cop/layout/space_around_operators.rb @@ -198,7 +198,7 @@ def offense_message(type, operator, with_space, right_operand) elsif excess_leading_space?(type, operator, with_space) || excess_trailing_space?(right_operand, with_space) "Operator `#{operator.source}` should be surrounded " \ - 'by a single space.' + 'by a single space.' end end diff --git a/lib/rubocop/cop/lint/nested_percent_literal.rb b/lib/rubocop/cop/lint/nested_percent_literal.rb index 2e2a2ffe84d..a8bc66b6089 100644 --- a/lib/rubocop/cop/lint/nested_percent_literal.rb +++ b/lib/rubocop/cop/lint/nested_percent_literal.rb @@ -33,7 +33,7 @@ class NestedPercentLiteral < Base include PercentLiteral MSG = 'Within percent literals, nested percent literals do not ' \ - 'function and may be unwanted in the result.' + 'function and may be unwanted in the result.' # The array of regular expressions representing percent literals that, # if found within a percent literal expression, will cause a diff --git a/lib/rubocop/cop/lint/percent_string_array.rb b/lib/rubocop/cop/lint/percent_string_array.rb index f4ff49d9bb2..bf84e1a1c73 100644 --- a/lib/rubocop/cop/lint/percent_string_array.rb +++ b/lib/rubocop/cop/lint/percent_string_array.rb @@ -29,7 +29,7 @@ class PercentStringArray < Base TRAILING_QUOTE = /['"]?,?$/.freeze MSG = "Within `%w`/`%W`, quotes and ',' are unnecessary and may be " \ - 'unwanted in the resulting strings.' + 'unwanted in the resulting strings.' def on_array(node) process(node, '%w', '%W') diff --git a/lib/rubocop/cop/lint/percent_symbol_array.rb b/lib/rubocop/cop/lint/percent_symbol_array.rb index 0447a280ee1..98ff32f0e17 100644 --- a/lib/rubocop/cop/lint/percent_symbol_array.rb +++ b/lib/rubocop/cop/lint/percent_symbol_array.rb @@ -25,7 +25,7 @@ class PercentSymbolArray < Base extend AutoCorrector MSG = "Within `%i`/`%I`, ':' and ',' are unnecessary and may be " \ - 'unwanted in the resulting symbols.' + 'unwanted in the resulting symbols.' def on_array(node) process(node, '%i', '%I') diff --git a/lib/rubocop/cop/lint/symbol_conversion.rb b/lib/rubocop/cop/lint/symbol_conversion.rb index ef00d4bfd10..4a1a0bf992b 100644 --- a/lib/rubocop/cop/lint/symbol_conversion.rb +++ b/lib/rubocop/cop/lint/symbol_conversion.rb @@ -70,7 +70,7 @@ class SymbolConversion < Base MSG = 'Unnecessary symbol conversion; use `%s` instead.' MSG_CONSISTENCY = 'Symbol hash key should be quoted for consistency; ' \ - 'use `%s` instead.' + 'use `%s` instead.' RESTRICT_ON_SEND = %i[to_sym intern].freeze def on_send(node) diff --git a/lib/rubocop/cop/lint/unused_block_argument.rb b/lib/rubocop/cop/lint/unused_block_argument.rb index 7ee7b59b2bc..af42786b05e 100644 --- a/lib/rubocop/cop/lint/unused_block_argument.rb +++ b/lib/rubocop/cop/lint/unused_block_argument.rb @@ -143,7 +143,7 @@ def message_for_lambda(variable, all_arguments) def message_for_underscore_prefix(variable) "If it's necessary, use `_` or `_#{variable.name}` " \ - "as an argument name to indicate that it won't be used." + "as an argument name to indicate that it won't be used." end def define_method_call?(variable) diff --git a/lib/rubocop/cop/lint/useless_assignment.rb b/lib/rubocop/cop/lint/useless_assignment.rb index f3223ead808..63f5b46e7ec 100644 --- a/lib/rubocop/cop/lint/useless_assignment.rb +++ b/lib/rubocop/cop/lint/useless_assignment.rb @@ -85,7 +85,7 @@ def operator_assignment_message(scope, assignment) return unless assignment.meta_assignment_node.equal?(return_value_node) " Use `#{assignment.operator.sub(/=$/, '')}` " \ - "instead of `#{assignment.operator}`." + "instead of `#{assignment.operator}`." end def similar_name_message(variable) diff --git a/lib/rubocop/cop/metrics/utils/code_length_calculator.rb b/lib/rubocop/cop/metrics/utils/code_length_calculator.rb index 64974654ce0..e00504daf71 100644 --- a/lib/rubocop/cop/metrics/utils/code_length_calculator.rb +++ b/lib/rubocop/cop/metrics/utils/code_length_calculator.rb @@ -50,7 +50,7 @@ def build_foldable_checks(types) ->(node) { heredoc_node?(node) } else raise ArgumentError, "Unknown foldable type: #{type.inspect}. "\ - "Valid foldable types are: #{FOLDABLE_TYPES.join(', ')}." + "Valid foldable types are: #{FOLDABLE_TYPES.join(', ')}." end end end diff --git a/lib/rubocop/cop/naming/memoized_instance_variable_name.rb b/lib/rubocop/cop/naming/memoized_instance_variable_name.rb index ba0dd695c84..087267bd12d 100644 --- a/lib/rubocop/cop/naming/memoized_instance_variable_name.rb +++ b/lib/rubocop/cop/naming/memoized_instance_variable_name.rb @@ -147,9 +147,9 @@ class MemoizedInstanceVariableName < Base include ConfigurableEnforcedStyle MSG = 'Memoized variable `%s` does not match ' \ - 'method name `%s`. Use `@%s` instead.' + 'method name `%s`. Use `@%s` instead.' UNDERSCORE_REQUIRED = 'Memoized variable `%s` does not start ' \ - 'with `_`. Use `@%s` instead.' + 'with `_`. Use `@%s` instead.' DYNAMIC_DEFINE_METHODS = %i[define_method define_singleton_method].to_set.freeze # @!method method_definition?(node) diff --git a/lib/rubocop/cop/style/multiple_comparison.rb b/lib/rubocop/cop/style/multiple_comparison.rb index e9900ead3b3..1622ca1adc4 100644 --- a/lib/rubocop/cop/style/multiple_comparison.rb +++ b/lib/rubocop/cop/style/multiple_comparison.rb @@ -44,7 +44,7 @@ class MultipleComparison < Base extend AutoCorrector MSG = 'Avoid comparing a variable with multiple items ' \ - 'in a conditional, use `Array#include?` instead.' + 'in a conditional, use `Array#include?` instead.' def on_new_investigation @last_comparison = nil diff --git a/lib/rubocop/cop/style/percent_literal_delimiters.rb b/lib/rubocop/cop/style/percent_literal_delimiters.rb index 978577fd116..6ae6fe09cbd 100644 --- a/lib/rubocop/cop/style/percent_literal_delimiters.rb +++ b/lib/rubocop/cop/style/percent_literal_delimiters.rb @@ -68,7 +68,7 @@ def message(type) delimiters = preferred_delimiters_for(type) "`#{type}`-literals should be delimited by " \ - "`#{delimiters[0]}` and `#{delimiters[1]}`." + "`#{delimiters[0]}` and `#{delimiters[1]}`." end def preferred_delimiters_for(type) diff --git a/lib/rubocop/cop/style/quoted_symbols.rb b/lib/rubocop/cop/style/quoted_symbols.rb index d6c61571bea..a21a66d91c7 100644 --- a/lib/rubocop/cop/style/quoted_symbols.rb +++ b/lib/rubocop/cop/style/quoted_symbols.rb @@ -36,9 +36,9 @@ class QuotedSymbols < Base extend AutoCorrector MSG_SINGLE = "Prefer single-quoted symbols when you don't need string interpolation " \ - 'or special symbols.' + 'or special symbols.' MSG_DOUBLE = 'Prefer double-quoted symbols unless you need single quotes to ' \ - 'avoid extra backslashes for escaping.' + 'avoid extra backslashes for escaping.' def on_sym(node) return unless quoted?(node) diff --git a/lib/rubocop/cop/style/redundant_regexp_character_class.rb b/lib/rubocop/cop/style/redundant_regexp_character_class.rb index 05ca06bcf09..67fdf7ea388 100644 --- a/lib/rubocop/cop/style/redundant_regexp_character_class.rb +++ b/lib/rubocop/cop/style/redundant_regexp_character_class.rb @@ -32,7 +32,7 @@ class RedundantRegexpCharacterClass < Base REQUIRES_ESCAPE_OUTSIDE_CHAR_CLASS_CHARS = '.*+?{}()|$'.chars.freeze MSG_REDUNDANT_CHARACTER_CLASS = 'Redundant single-element character class, ' \ - '`%s` can be replaced with `%s`.' + '`%s` can be replaced with `%s`.' def on_regexp(node) each_redundant_character_class(node) do |loc| diff --git a/lib/rubocop/cop/style/special_global_vars.rb b/lib/rubocop/cop/style/special_global_vars.rb index 4ac40b83c13..3c7dff432aa 100644 --- a/lib/rubocop/cop/style/special_global_vars.rb +++ b/lib/rubocop/cop/style/special_global_vars.rb @@ -53,10 +53,10 @@ class SpecialGlobalVars < Base extend AutoCorrector MSG_BOTH = 'Prefer `%s` from the stdlib \'English\' ' \ - 'module (don\'t forget to require it) or `%s` over ' \ - '`%s`.' + 'module (don\'t forget to require it) or `%s` over ' \ + '`%s`.' MSG_ENGLISH = 'Prefer `%s` from the stdlib \'English\' ' \ - 'module (don\'t forget to require it) over `%s`.' + 'module (don\'t forget to require it) over `%s`.' MSG_REGULAR = 'Prefer `%s` over `%s`.' ENGLISH_VARS = { # rubocop:disable Style/MutableConstant diff --git a/lib/rubocop/cop/style/string_literals.rb b/lib/rubocop/cop/style/string_literals.rb index 46ff41b5fa9..d32951c93e2 100644 --- a/lib/rubocop/cop/style/string_literals.rb +++ b/lib/rubocop/cop/style/string_literals.rb @@ -87,10 +87,10 @@ def detect_quote_styles(node) def message(_node) if style == :single_quotes "Prefer single-quoted strings when you don't need string " \ - 'interpolation or special symbols.' + 'interpolation or special symbols.' else 'Prefer double-quoted strings unless you need single quotes to ' \ - 'avoid extra backslashes for escaping.' + 'avoid extra backslashes for escaping.' end end diff --git a/lib/rubocop/cop/style/swap_values.rb b/lib/rubocop/cop/style/swap_values.rb index 730ac212718..c16f69a88d0 100644 --- a/lib/rubocop/cop/style/swap_values.rb +++ b/lib/rubocop/cop/style/swap_values.rb @@ -21,7 +21,7 @@ class SwapValues < Base extend AutoCorrector MSG = 'Replace this and assignments at lines %d '\ - 'and %d with `%s`.' + 'and %d with `%s`.' SIMPLE_ASSIGNMENT_TYPES = %i[lvasgn ivasgn cvasgn gvasgn casgn].to_set.freeze diff --git a/lib/rubocop/cop/style/unpack_first.rb b/lib/rubocop/cop/style/unpack_first.rb index a7b7edac1ac..73821a2ecaa 100644 --- a/lib/rubocop/cop/style/unpack_first.rb +++ b/lib/rubocop/cop/style/unpack_first.rb @@ -21,7 +21,7 @@ class UnpackFirst < Base extend AutoCorrector MSG = 'Use `%s.unpack1(%s)` instead of '\ - '`%s.unpack(%s)%s`.' + '`%s.unpack(%s)%s`.' RESTRICT_ON_SEND = %i[first [] slice at].freeze # @!method unpack_and_first_element?(node) diff --git a/lib/rubocop/cop/variable_force/variable_table.rb b/lib/rubocop/cop/variable_force/variable_table.rb index d9ce3d55380..00f94fa40f8 100644 --- a/lib/rubocop/cop/variable_force/variable_table.rb +++ b/lib/rubocop/cop/variable_force/variable_table.rb @@ -58,7 +58,7 @@ def assign_to_variable(name, node) unless variable raise "Assigning to undeclared local variable \"#{name}\" " \ - "at #{node.source_range}, #{node.inspect}" + "at #{node.source_range}, #{node.inspect}" end variable.assign(node) diff --git a/lib/rubocop/options.rb b/lib/rubocop/options.rb index 3604944c188..6ad40864989 100644 --- a/lib/rubocop/options.rb +++ b/lib/rubocop/options.rb @@ -12,9 +12,9 @@ class OptionArgumentError < StandardError; end # @api private class Options E_STDIN_NO_PATH = '-s/--stdin requires exactly one path, relative to the ' \ - 'root of the project. RuboCop will use this path to determine which ' \ - 'cops are enabled (via eg. Include/Exclude), and so that certain cops ' \ - 'like Naming/FileName can be checked.' + 'root of the project. RuboCop will use this path to determine which ' \ + 'cops are enabled (via eg. Include/Exclude), and so that certain cops ' \ + 'like Naming/FileName can be checked.' EXITING_OPTIONS = %i[version verbose_version show_cops].freeze DEFAULT_MAXIMUM_EXCLUSION_ITEMS = 15 @@ -292,7 +292,7 @@ def validate_compatibility # rubocop:disable Metrics/MethodLength if display_only_fail_level_offenses_with_autocorrect? raise OptionArgumentError, '--autocorrect cannot be used with ' \ - '--display-only-fail-level-offenses' + '--display-only-fail-level-offenses' end validate_auto_gen_config validate_auto_correct diff --git a/lib/rubocop/rspec/cop_helper.rb b/lib/rubocop/rspec/cop_helper.rb index 011b040bb5c..e6a7611f6e8 100644 --- a/lib/rubocop/rspec/cop_helper.rb +++ b/lib/rubocop/rspec/cop_helper.rb @@ -15,7 +15,7 @@ def inspect_source(source, file = nil) processed_source = parse_source(source, file) unless processed_source.valid_syntax? raise 'Error parsing example code: ' \ - "#{processed_source.diagnostics.map(&:render).join("\n")}" + "#{processed_source.diagnostics.map(&:render).join("\n")}" end _investigate(cop, processed_source) diff --git a/lib/rubocop/rspec/expect_offense.rb b/lib/rubocop/rspec/expect_offense.rb index c0991b3671b..f4252262af0 100644 --- a/lib/rubocop/rspec/expect_offense.rb +++ b/lib/rubocop/rspec/expect_offense.rb @@ -195,7 +195,7 @@ def parse_processed_source(source, file = nil) return processed_source if processed_source.valid_syntax? raise 'Error parsing example code: ' \ - "#{processed_source.diagnostics.map(&:render).join("\n")}" + "#{processed_source.diagnostics.map(&:render).join("\n")}" end def set_formatter_options diff --git a/spec/rubocop/cli/autocorrect_spec.rb b/spec/rubocop/cli/autocorrect_spec.rb index abf90eaea44..b4416c266ac 100644 --- a/spec/rubocop/cli/autocorrect_spec.rb +++ b/spec/rubocop/cli/autocorrect_spec.rb @@ -1440,7 +1440,7 @@ def primes limit expect(File.read('example.rb')).to eq("{ b: 1 }\n") expect($stdout.string) .to eq("#{abs('example.rb')}:1:3: C: [Corrected] Style/HashSyntax: " \ - "Use the new Ruby 1.9 hash syntax.\n") + "Use the new Ruby 1.9 hash syntax.\n") end it 'can correct TrailingEmptyLines and TrailingWhitespace offenses' do @@ -2099,7 +2099,7 @@ def my_func end it 'consistently quotes symbol keys in a hash using `Lint/SymbolConversion` ' \ - 'with `EnforcedStyle: consistent` and `Style/QuotedSymbols`' do + 'with `EnforcedStyle: consistent` and `Style/QuotedSymbols`' do source_file = Pathname('example.rb') create_file(source_file, <<~RUBY) { diff --git a/spec/rubocop/config_loader_spec.rb b/spec/rubocop/config_loader_spec.rb index 901ade10bb9..95c55cc4e91 100644 --- a/spec/rubocop/config_loader_spec.rb +++ b/spec/rubocop/config_loader_spec.rb @@ -349,7 +349,7 @@ let(:file_path) { '.rubocop.yml' } let(:message) do '.rubocop.yml: Style/For:Exclude overrides the same parameter in ' \ - '.rubocop_todo.yml' + '.rubocop_todo.yml' end before do @@ -512,7 +512,7 @@ end it 'unions the two lists of Excludes from the parent and child configs ' \ - 'for cops that do not override the inherit_mode' do + 'for cops that do not override the inherit_mode' do expect do excludes = configuration_from_file['Style/For']['Exclude'] expect(excludes.sort) @@ -1107,7 +1107,7 @@ def cop_enabled?(cop_class) end it 'enables cops that are explicitly in the config file '\ - 'even if they are disabled by default' do + 'even if they are disabled by default' do cop_class = RuboCop::Cop::Style::Copyright expect(cop_enabled?(cop_class)).to be true end diff --git a/spec/rubocop/cop/corrector_spec.rb b/spec/rubocop/cop/corrector_spec.rb index 658d1c5bd2b..b9089667b76 100644 --- a/spec/rubocop/cop/corrector_spec.rb +++ b/spec/rubocop/cop/corrector_spec.rb @@ -73,7 +73,7 @@ def do_rewrite(corrections = nil, &block) expect do do_rewrite { |corr| corr.replace(1..3, 'oops') } end.to raise_error(TypeError, 'Expected a Parser::Source::Range, '\ - 'Comment or Rubocop::AST::Node, got Range') + 'Comment or Rubocop::AST::Node, got Range') end context 'when range is from incorrect source' do diff --git a/spec/rubocop/cop/layout/access_modifier_indentation_spec.rb b/spec/rubocop/cop/layout/access_modifier_indentation_spec.rb index 40bfbb2f999..f2fddd88e02 100644 --- a/spec/rubocop/cop/layout/access_modifier_indentation_spec.rb +++ b/spec/rubocop/cop/layout/access_modifier_indentation_spec.rb @@ -536,7 +536,7 @@ class << self end it 'registers an offense and corrects private indented to method depth ' \ - 'in class defined with Class.new' do + 'in class defined with Class.new' do expect_offense(<<~RUBY) Test = Class.new do @@ -577,7 +577,7 @@ def test; end end it 'registers an offense and corrects private indented to method depth ' \ - 'in module defined with Module.new' do + 'in module defined with Module.new' do expect_offense(<<~RUBY) Test = Module.new do diff --git a/spec/rubocop/cop/layout/empty_line_after_guard_clause_spec.rb b/spec/rubocop/cop/layout/empty_line_after_guard_clause_spec.rb index db35f3ea559..d93309b301a 100644 --- a/spec/rubocop/cop/layout/empty_line_after_guard_clause_spec.rb +++ b/spec/rubocop/cop/layout/empty_line_after_guard_clause_spec.rb @@ -64,7 +64,7 @@ def foo end it 'registers an offense and corrects a `raise` guard clause not followed ' \ - 'by empty line when `unless` condition is after heredoc' do + 'by empty line when `unless` condition is after heredoc' do expect_offense(<<~RUBY) def foo raise ArgumentError, <<-MSG unless path @@ -110,8 +110,8 @@ def foo end it 'registers an offense and corrects a next guard clause not followed by ' \ - 'empty line when guard clause is after heredoc ' \ - 'including string interpolation' do + 'empty line when guard clause is after heredoc ' \ + 'including string interpolation' do expect_offense(<<~'RUBY') raise(<<-FAIL) unless true #{1 + 1} @@ -130,7 +130,7 @@ def foo end it 'accepts a `raise` guard clause not followed by empty line when guard ' \ - 'clause is after condition without method invocation' do + 'clause is after condition without method invocation' do expect_no_offenses(<<~'RUBY') def foo raise unless $1 == o @@ -141,7 +141,7 @@ def foo end it 'registers an offense and corrects a `raise` guard clause not followed ' \ - 'by empty line when guard clause is after method call with argument' do + 'by empty line when guard clause is after method call with argument' do expect_offense(<<~'RUBY') def foo raise SerializationError.new("Unsupported argument type: #{argument.class.name}") unless serializer @@ -263,7 +263,7 @@ def method end it 'registers an offense and corrects a guard clause not followed by ' \ - 'empty line when guard clause including heredoc' do + 'empty line when guard clause including heredoc' do expect_offense(<<~RUBY) def method if truthy diff --git a/spec/rubocop/cop/layout/first_argument_indentation_spec.rb b/spec/rubocop/cop/layout/first_argument_indentation_spec.rb index 07e757d20f4..35c233abc0b 100644 --- a/spec/rubocop/cop/layout/first_argument_indentation_spec.rb +++ b/spec/rubocop/cop/layout/first_argument_indentation_spec.rb @@ -520,7 +520,7 @@ context 'for assignment' do it 'register an offense and corrects a correctly indented first ' \ - 'argument and does not care about the second argument' do + 'argument and does not care about the second argument' do expect_offense(<<~RUBY) x = run( :foo, diff --git a/spec/rubocop/cop/layout/hash_alignment_spec.rb b/spec/rubocop/cop/layout/hash_alignment_spec.rb index e747d1c741f..946c06ac3b2 100644 --- a/spec/rubocop/cop/layout/hash_alignment_spec.rb +++ b/spec/rubocop/cop/layout/hash_alignment_spec.rb @@ -972,7 +972,7 @@ def self.scenarios_order end it 'registers an offense and corrects misaligned hash values, ' \ - 'prefer table when least offenses' do + 'prefer table when least offenses' do expect_offense(<<~RUBY) hash = { 'abcdefg' => 0, diff --git a/spec/rubocop/cop/layout/indentation_consistency_spec.rb b/spec/rubocop/cop/layout/indentation_consistency_spec.rb index 77b81122267..e1a87233e74 100644 --- a/spec/rubocop/cop/layout/indentation_consistency_spec.rb +++ b/spec/rubocop/cop/layout/indentation_consistency_spec.rb @@ -640,7 +640,7 @@ def g end it 'registers an offense and corrects bad indentation ' \ - 'in def but not for outdented public, protected, and private' do + 'in def but not for outdented public, protected, and private' do expect_offense(<<~RUBY) class Test public diff --git a/spec/rubocop/cop/layout/indentation_style_spec.rb b/spec/rubocop/cop/layout/indentation_style_spec.rb index c5a9f9239f1..bfcf5f3e6a8 100644 --- a/spec/rubocop/cop/layout/indentation_style_spec.rb +++ b/spec/rubocop/cop/layout/indentation_style_spec.rb @@ -171,7 +171,7 @@ end it 'registers and corrects an offense for a line indented with fractional number of'\ - 'indentation groups by rounding down' do + 'indentation groups by rounding down' do expect_offense(<<~RUBY) x = 0 ^^^ Space detected in indentation. diff --git a/spec/rubocop/cop/layout/line_end_string_concatenation_indentation_spec.rb b/spec/rubocop/cop/layout/line_end_string_concatenation_indentation_spec.rb new file mode 100644 index 00000000000..3c9c4f606e5 --- /dev/null +++ b/spec/rubocop/cop/layout/line_end_string_concatenation_indentation_spec.rb @@ -0,0 +1,306 @@ +# frozen_string_literal: true + +RSpec.describe RuboCop::Cop::Layout::LineEndStringConcatenationIndentation, :config do + let(:config) do + merged = RuboCop::ConfigLoader + .default_configuration['Layout/LineEndStringConcatenationIndentation'] + .merge(cop_config) + .merge('IndentationWidth' => cop_indent) + RuboCop::Config + .new('Layout/LineEndStringConcatenationIndentation' => merged, + 'Layout/IndentationWidth' => { 'Width' => indentation_width }) + end + let(:indentation_width) { 2 } + let(:cop_indent) { nil } # use indentation width from Layout/IndentationWidth + + shared_examples 'common' do + it 'accepts indented strings in implicit return statement of a block' do + expect_no_offenses(<<~'RUBY') + some_method do + 'a' \ + 'b' \ + 'c' + end + RUBY + end + + it 'registers an offense for unaligned strings in hash literal values' do + expect_offense(<<~'RUBY') + MESSAGES = { KeyAlignment => 'Align the keys of a hash literal if ' \ + 'they span more than one line.', + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Align parts of a string concatenated with backslash. + SeparatorAlignment => 'Align the separators of a hash ' \ + 'literal if they span more than one line.', + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Align parts of a string concatenated with backslash. + TableAlignment => 'Align the keys and values of a hash ' \ + 'literal if they span more than one line.' }.freeze + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Align parts of a string concatenated with backslash. + RUBY + + expect_correction(<<~'RUBY') + MESSAGES = { KeyAlignment => 'Align the keys of a hash literal if ' \ + 'they span more than one line.', + SeparatorAlignment => 'Align the separators of a hash ' \ + 'literal if they span more than one line.', + TableAlignment => 'Align the keys and values of a hash ' \ + 'literal if they span more than one line.' }.freeze + RUBY + end + + it 'accepts indented strings in implicit return statement of a method definition' do + expect_no_offenses(<<~'RUBY') + def some_method + 'a' \ + 'b' \ + 'c' + end + RUBY + end + + it 'registers an offense for aligned strings in an if/elif/else statement' do + expect_offense(<<~'RUBY') + if cond1 + 'a' \ + 'b' + ^^^ Indent the first part of a string concatenated with backslash. + elif cond2 + 'c' \ + 'd' + ^^^ Indent the first part of a string concatenated with backslash. + else + 'e' \ + 'f' + ^^^ Indent the first part of a string concatenated with backslash. + end + RUBY + + expect_correction(<<~'RUBY') + if cond1 + 'a' \ + 'b' + elif cond2 + 'c' \ + 'd' + else + 'e' \ + 'f' + end + RUBY + end + + it 'accepts indented strings in implicit return statement of a singleton method definition' do + expect_no_offenses(<<~'RUBY') + def self.some_method + 'a' \ + 'b' \ + 'c' + end + RUBY + end + + it 'accepts indented strings in implicit return statement of a method definition after other statement' do + expect_no_offenses(<<~'RUBY') + def some_method + b = 'b' + 'a' \ + "#{b}" \ + 'c' + end + RUBY + end + + it 'accepts indented strings in ordinary statement' do + expect_no_offenses(<<~'RUBY') + 'a' \ + 'b' \ + 'c' + RUBY + end + + it 'accepts a heredoc string with interpolation' do + expect_no_offenses(<<~'RUBY') + warn <<~TEXT + A #{b} + TEXT + RUBY + end + + it 'accepts a heredoc string ...' do + expect_no_offenses(<<~'RUBY') + let(:source) do + <<~CODE + func({ + @abc => 0, + @xyz => 1 + }) + func( + { + abc: 0 + } + ) + func( + {}, + { + xyz: 1 + } + ) + CODE + end + RUBY + end + + it 'accepts an empty heredoc string with interpolation' do + expect_no_offenses(<<~'RUBY') + puts(<<~TEXT) + TEXT + RUBY + end + end + + context 'when EnforcedStyle is aligned' do + let(:cop_config) { { 'EnforcedStyle' => 'aligned' } } + + include_examples 'common' + + it 'accepts aligned strings in method call' do + expect_no_offenses(<<~'RUBY') + puts 'a' \ + 'b' + RUBY + end + + ['X =', '$x =', '@x =', 'x =', 'x +=', 'x ||='].each do |lhs_and_operator| + context "for assignment with #{lhs_and_operator}" do + let(:aligned_strings) do + [%(#{lhs_and_operator} "a" \\), + "#{' ' * lhs_and_operator.length} 'b'", + ''].join("\n") + end + + it 'accepts aligned strings' do + expect_no_offenses(aligned_strings) + end + + it 'registers an offense for indented strings' do + expect_offense([%(#{lhs_and_operator} "a" \\), + " 'b'", + ' ^^^ Align parts of a string concatenated with backslash.', + ''].join("\n")) + + expect_correction(aligned_strings) + end + end + end + + it 'registers an offense for indented string' do + expect_offense(<<~'RUBY') + puts 'a' \ + "b" \ + ^^^ Align parts of a string concatenated with backslash. + 'c' + RUBY + + expect_correction(<<~'RUBY') + puts 'a' \ + "b" \ + 'c' + RUBY + end + + it 'registers an offense for third part of a string if it is aligned only with the first' do + expect_offense(<<~'RUBY') + puts 'a' \ + 'b' \ + ^^^ Align parts of a string concatenated with backslash. + 'c' + ^^^ Align parts of a string concatenated with backslash. + RUBY + + expect_correction(<<~'RUBY') + puts 'a' \ + 'b' \ + 'c' + RUBY + end + end + + context 'when EnforcedStyle is indented' do + let(:cop_config) { { 'EnforcedStyle' => 'indented' } } + + include_examples 'common' + + it 'accepts indented strings' do + expect_no_offenses(<<~'RUBY') + puts 'a' \ + 'b' + RUBY + end + + ['X =', '$x =', '@x =', 'x =', 'x +=', 'x ||='].each do |lhs_and_operator| + context "for assignment with #{lhs_and_operator}" do + let(:indented_strings) do + [%(#{lhs_and_operator} "a" \\), + " 'b'", + ''].join("\n") + end + + it 'accepts indented strings' do + expect_no_offenses(indented_strings) + end + + it 'registers an offense for aligned strings' do + margin = "#{' ' * lhs_and_operator.length} " # Including spaces around operator. + expect_offense( + [%(#{lhs_and_operator} "a" \\), + "#{margin}'b'", + "#{margin}^^^ Indent the first part of a string concatenated with backslash.", + ''].join("\n") + ) + + expect_correction(indented_strings) + end + end + end + + it 'registers an offense for aligned string' do + expect_offense(<<~'RUBY') + puts %Q(a) \ + 'b' \ + ^^^ Indent the first part of a string concatenated with backslash. + 'c' + RUBY + + expect_correction(<<~'RUBY') + puts %Q(a) \ + 'b' \ + 'c' + RUBY + end + + it 'registers an offense for unaligned third part of string' do + expect_offense(<<~'RUBY') + puts 'a' \ + "#{b}" \ + "#{c}" + ^^^^^^ Align parts of a string concatenated with backslash. + RUBY + + expect_correction(<<~'RUBY') + puts 'a' \ + "#{b}" \ + "#{c}" + RUBY + end + + context 'when IndentationWidth is 1' do + let(:cop_indent) { 1 } + + it 'accepts indented strings' do + expect_no_offenses(<<~'RUBY') + puts 'a' \ + 'b' + RUBY + end + end + end +end diff --git a/spec/rubocop/cop/layout/multiline_method_call_indentation_spec.rb b/spec/rubocop/cop/layout/multiline_method_call_indentation_spec.rb index e8e689ded9f..296051c9eba 100644 --- a/spec/rubocop/cop/layout/multiline_method_call_indentation_spec.rb +++ b/spec/rubocop/cop/layout/multiline_method_call_indentation_spec.rb @@ -162,7 +162,7 @@ end it 'registers an offense and corrects the emacs ruby-mode 1.1 ' \ - 'indentation of an expression in an array' do + 'indentation of an expression in an array' do expect_offense(<<~RUBY) [ a. @@ -773,7 +773,7 @@ def foo end it 'registers an offense and corrects the emacs ruby-mode 1.1 ' \ - 'indentation of an expression in an array' do + 'indentation of an expression in an array' do expect_offense(<<~RUBY) [ a. diff --git a/spec/rubocop/cop/layout/multiline_operation_indentation_spec.rb b/spec/rubocop/cop/layout/multiline_operation_indentation_spec.rb index 2c0ce3f3fbc..2aa9ed0e222 100644 --- a/spec/rubocop/cop/layout/multiline_operation_indentation_spec.rb +++ b/spec/rubocop/cop/layout/multiline_operation_indentation_spec.rb @@ -125,7 +125,7 @@ end it 'registers an offense and corrects emacs ruby-mode 1.1 indentation of ' \ - 'an expression in an array' do + 'an expression in an array' do expect_offense(<<~RUBY) [ a + @@ -217,7 +217,7 @@ end it 'registers an offense and corrects an unindented multiline operation ' \ - 'that is the left operand in another operation' do + 'that is the left operand in another operation' do expect_offense(<<~RUBY) a + b < 3 @@ -324,7 +324,7 @@ def config_to_allow_offenses end it 'registers an offense and corrects misaligned string operand ' \ - 'when the first operand has backslash continuation' do + 'when the first operand has backslash continuation' do expect_offense(<<~'RUBY') def f flash[:error] = 'Here is a string ' \ diff --git a/spec/rubocop/cop/layout/space_after_not_spec.rb b/spec/rubocop/cop/layout/space_after_not_spec.rb index d60dc2b4698..29a0c04573c 100644 --- a/spec/rubocop/cop/layout/space_after_not_spec.rb +++ b/spec/rubocop/cop/layout/space_after_not_spec.rb @@ -32,7 +32,7 @@ end it 'registers an offense and corrects space after ! with ' \ - 'the negated receiver wrapped in parentheses' do + 'the negated receiver wrapped in parentheses' do expect_offense(<<~RUBY) ! (model) ^^^^^^^^^ Do not leave space between `!` and its argument. diff --git a/spec/rubocop/cop/layout/space_around_block_parameters_spec.rb b/spec/rubocop/cop/layout/space_around_block_parameters_spec.rb index 94b3c3a68eb..7d0421b7deb 100644 --- a/spec/rubocop/cop/layout/space_around_block_parameters_spec.rb +++ b/spec/rubocop/cop/layout/space_around_block_parameters_spec.rb @@ -382,7 +382,7 @@ end it 'registers an offense and corrects missing space ' \ - 'before first argument and after last argument' do + 'before first argument and after last argument' do expect_offense(<<~RUBY) {}.each { |x, z| puts x } ^ Space after last block parameter missing. diff --git a/spec/rubocop/cop/layout/space_around_equals_in_parameter_default_spec.rb b/spec/rubocop/cop/layout/space_around_equals_in_parameter_default_spec.rb index 54a2deb8c89..020463e9abd 100644 --- a/spec/rubocop/cop/layout/space_around_equals_in_parameter_default_spec.rb +++ b/spec/rubocop/cop/layout/space_around_equals_in_parameter_default_spec.rb @@ -19,7 +19,7 @@ def f(x, y = 0, z = 1) end it 'registers an offense and corrects default value assignment where first is partially right ' \ - 'without space' do + 'without space' do expect_offense(<<~RUBY) def f(x, y= 0, z=1) ^^ Surrounding space missing in default value assignment. diff --git a/spec/rubocop/cop/layout/space_before_block_braces_spec.rb b/spec/rubocop/cop/layout/space_before_block_braces_spec.rb index 1e22c56a39a..ec4bc161569 100644 --- a/spec/rubocop/cop/layout/space_before_block_braces_spec.rb +++ b/spec/rubocop/cop/layout/space_before_block_braces_spec.rb @@ -33,7 +33,7 @@ end it 'registers an offense and corrects multiline block where the left ' \ - 'brace has no outer space' do + 'brace has no outer space' do expect_offense(<<~RUBY) foo.map{ |a| ^ Space missing to the left of {. diff --git a/spec/rubocop/cop/layout/space_inside_array_literal_brackets_spec.rb b/spec/rubocop/cop/layout/space_inside_array_literal_brackets_spec.rb index abbd20a88a7..b7b51c23f61 100644 --- a/spec/rubocop/cop/layout/space_inside_array_literal_brackets_spec.rb +++ b/spec/rubocop/cop/layout/space_inside_array_literal_brackets_spec.rb @@ -397,7 +397,7 @@ def Vector.[](*array) end it 'registers an offense and corrects an array missing whitespace ' \ - 'when there is more than one array on a line' do + 'when there is more than one array on a line' do expect_offense(<<~RUBY) [ 'qux', 'baz'] - [ 'baz' ] ^ #{use_space_message} diff --git a/spec/rubocop/cop/layout/space_inside_reference_brackets_spec.rb b/spec/rubocop/cop/layout/space_inside_reference_brackets_spec.rb index 4fb2b4d1477..86faaf0f495 100644 --- a/spec/rubocop/cop/layout/space_inside_reference_brackets_spec.rb +++ b/spec/rubocop/cop/layout/space_inside_reference_brackets_spec.rb @@ -94,7 +94,7 @@ end it 'registers an offense and corrects when a reference bracket with a ' \ - 'leading whitespace is assigned by another reference bracket' do + 'leading whitespace is assigned by another reference bracket' do expect_offense(<<~RUBY) a[ "foo"] = b["something"] ^ Do not use space inside reference brackets. @@ -106,7 +106,7 @@ end it 'registers an offense and correcs when a reference bracket with a ' \ - 'trailing whitespace is assigned by another reference bracket' do + 'trailing whitespace is assigned by another reference bracket' do expect_offense(<<~RUBY) a["foo" ] = b["something"] ^ Do not use space inside reference brackets. @@ -118,7 +118,7 @@ end it 'registers an offense and corrects when a reference bracket is ' \ - 'assigned by another reference bracket with trailing whitespace' do + 'assigned by another reference bracket with trailing whitespace' do expect_offense(<<~RUBY) a["foo"] = b["something" ] ^ Do not use space inside reference brackets. @@ -310,7 +310,7 @@ def Vector.[](*array) end it 'registers an offense and corrects when a reference bracket with no ' \ - 'leading whitespace is assigned by another reference bracket' do + 'leading whitespace is assigned by another reference bracket' do expect_offense(<<~RUBY) a["foo" ] = b[ "something" ] ^ Use space inside reference brackets. @@ -322,7 +322,7 @@ def Vector.[](*array) end it 'registers an offense and corrects when a reference bracket with no ' \ - 'trailing whitespace is assigned by another reference bracket' do + 'trailing whitespace is assigned by another reference bracket' do expect_offense(<<~RUBY) a[ "foo"] = b[ "something" ] ^ Use space inside reference brackets. @@ -334,7 +334,7 @@ def Vector.[](*array) end it 'registers an offense and corrects when a reference bracket is ' \ - 'assigned by another reference bracket with no trailing whitespace' do + 'assigned by another reference bracket with no trailing whitespace' do expect_offense(<<~RUBY) a[ "foo" ] = b[ "something"] ^ Use space inside reference brackets. diff --git a/spec/rubocop/cop/lint/ordered_magic_comments_spec.rb b/spec/rubocop/cop/lint/ordered_magic_comments_spec.rb index 8dac898b631..fcfe4185a3d 100644 --- a/spec/rubocop/cop/lint/ordered_magic_comments_spec.rb +++ b/spec/rubocop/cop/lint/ordered_magic_comments_spec.rb @@ -2,7 +2,7 @@ RSpec.describe RuboCop::Cop::Lint::OrderedMagicComments, :config do it 'registers an offense and corrects when an `encoding` magic comment ' \ - 'does not precede all other magic comments' do + 'does not precede all other magic comments' do expect_offense(<<~RUBY) # frozen_string_literal: true # encoding: ascii @@ -44,7 +44,7 @@ end it 'registers an offense and corrects when using `frozen_string_literal` ' \ - 'magic comment is next of shebang' do + 'magic comment is next of shebang' do expect_offense(<<~RUBY) #!/usr/bin/env ruby # frozen_string_literal: true diff --git a/spec/rubocop/cop/lint/parentheses_as_grouped_expression_spec.rb b/spec/rubocop/cop/lint/parentheses_as_grouped_expression_spec.rb index 3e45c7fce34..379cd7160d0 100644 --- a/spec/rubocop/cop/lint/parentheses_as_grouped_expression_spec.rb +++ b/spec/rubocop/cop/lint/parentheses_as_grouped_expression_spec.rb @@ -49,7 +49,7 @@ end it 'does not register an offense when method argument parentheses are omitted and ' \ - 'hash argument key is enclosed in parentheses' do + 'hash argument key is enclosed in parentheses' do expect_no_offenses(<<~RUBY) transition (foo - bar) => value RUBY diff --git a/spec/rubocop/cop/lint/redundant_splat_expansion_spec.rb b/spec/rubocop/cop/lint/redundant_splat_expansion_spec.rb index 15c5563486d..ee610cb860e 100644 --- a/spec/rubocop/cop/lint/redundant_splat_expansion_spec.rb +++ b/spec/rubocop/cop/lint/redundant_splat_expansion_spec.rb @@ -254,7 +254,7 @@ context 'splat expansion inside of an array' do it 'registers an offense and corrects the expansion of an array literal' \ - 'inside of an array literal' do + 'inside of an array literal' do expect_offense(<<~RUBY) [1, 2, *[3, 4, 5], 6, 7] ^^^^^^^^^^ Pass array contents as separate arguments. diff --git a/spec/rubocop/cop/lint/redundant_with_index_spec.rb b/spec/rubocop/cop/lint/redundant_with_index_spec.rb index a82d987ccad..068f52dfb03 100644 --- a/spec/rubocop/cop/lint/redundant_with_index_spec.rb +++ b/spec/rubocop/cop/lint/redundant_with_index_spec.rb @@ -24,7 +24,7 @@ end it 'registers an offense when using `ary.each.with_index(1) { |v| v }` ' \ - 'and correct to `ary.each { |v| v }`' do + 'and correct to `ary.each { |v| v }`' do expect_offense(<<~RUBY) ary.each.with_index(1) { |v| v } ^^^^^^^^^^^^^ Remove redundant `with_index`. @@ -36,8 +36,8 @@ end it 'registers an offense when using ' \ - '`ary.each_with_object([]).with_index { |v| v }` ' \ - 'and corrects to `ary.each_with_object([]) { |v| v }`' do + '`ary.each_with_object([]).with_index { |v| v }` ' \ + 'and corrects to `ary.each_with_object([]) { |v| v }`' do expect_offense(<<~RUBY) ary.each_with_object([]).with_index { |v| v } ^^^^^^^^^^ Remove redundant `with_index`. diff --git a/spec/rubocop/cop/lint/redundant_with_object_spec.rb b/spec/rubocop/cop/lint/redundant_with_object_spec.rb index fa433b061b4..7dd5f0073e2 100644 --- a/spec/rubocop/cop/lint/redundant_with_object_spec.rb +++ b/spec/rubocop/cop/lint/redundant_with_object_spec.rb @@ -39,7 +39,7 @@ end it 'registers an offense and corrects when using ' \ - 'ary.each_with_object do-end block without parentheses' do + 'ary.each_with_object do-end block without parentheses' do expect_offense(<<~RUBY) ary.each_with_object [] do |v| ^^^^^^^^^^^^^^^^^^^ Use `each` instead of `each_with_object`. diff --git a/spec/rubocop/cop/lint/safe_navigation_consistency_spec.rb b/spec/rubocop/cop/lint/safe_navigation_consistency_spec.rb index e37ef4bf600..ce197ed57fa 100644 --- a/spec/rubocop/cop/lint/safe_navigation_consistency_spec.rb +++ b/spec/rubocop/cop/lint/safe_navigation_consistency_spec.rb @@ -118,7 +118,7 @@ end it 'registers an offense and corrects using safe navigation in conditions ' \ - 'on the right hand side' do + 'on the right hand side' do expect_offense(<<~RUBY) foobar.baz && foo&.bar && foo.qux ^^^^^^^^^^^^^^^^^^^ Ensure that safe navigation is used consistently inside of `&&` and `||`. @@ -178,7 +178,7 @@ end it 'registers an offense and corrects using unsafe navigation ' \ - 'and the safe navigation appears in a group' do + 'and the safe navigation appears in a group' do expect_offense(<<~RUBY) (foo&.bar && foo.baz) || foo.qux ^^^^^^^^^^^^^^^^^^^ Ensure that safe navigation is used consistently inside of `&&` and `||`. diff --git a/spec/rubocop/cop/lint/unused_block_argument_spec.rb b/spec/rubocop/cop/lint/unused_block_argument_spec.rb index e584b7ad09d..e6d9de7397b 100644 --- a/spec/rubocop/cop/lint/unused_block_argument_spec.rb +++ b/spec/rubocop/cop/lint/unused_block_argument_spec.rb @@ -8,8 +8,8 @@ context 'and an argument is unused' do it 'registers an offense' do message = "Unused block argument - `value`. If it's " \ - 'necessary, use `_` or `_value` as an argument ' \ - "name to indicate that it won't be used." + 'necessary, use `_` or `_value` as an argument ' \ + "name to indicate that it won't be used." expect_offense(<<~RUBY) hash.each do |key, value| @@ -107,7 +107,7 @@ it 'registers offenses and suggests omitting them' do (key_message, value_message) = %w[key value].map do |arg| "Unused block argument - `#{arg}`. You can omit all the " \ - "arguments if you don't care about them." + "arguments if you don't care about them." end expect_offense(<<~RUBY) @@ -158,7 +158,7 @@ context 'and the argument is unused' do it 'registers an offense and suggests omitting that' do message = 'Unused block argument - `index`. ' \ - "You can omit the argument if you don't care about it." + "You can omit the argument if you don't care about it." expect_offense(<<~RUBY) 1.times do |index| @@ -178,8 +178,8 @@ context 'and the method call is `define_method`' do it 'registers an offense' do message = 'Unused block argument - `bar`. ' \ - "If it's necessary, use `_` or `_bar` as an argument " \ - "name to indicate that it won't be used." + "If it's necessary, use `_` or `_bar` as an argument " \ + "name to indicate that it won't be used." expect_offense(<<~RUBY) define_method(:foo) do |bar| @@ -232,11 +232,11 @@ it 'registers offenses and suggests using a proc' do (foo_message, bar_message) = %w[foo bar].map do |arg| "Unused block argument - `#{arg}`. " \ - "If it's necessary, use `_` or `_#{arg}` as an argument name " \ - "to indicate that it won't be used. " \ - 'Also consider using a proc without arguments instead of a ' \ - "lambda if you want it to accept any arguments but don't care " \ - 'about them.' + "If it's necessary, use `_` or `_#{arg}` as an argument name " \ + "to indicate that it won't be used. " \ + 'Also consider using a proc without arguments instead of a ' \ + "lambda if you want it to accept any arguments but don't care " \ + 'about them.' end expect_offense(<<~RUBY) @@ -254,8 +254,8 @@ context 'and an argument is unused' do it 'registers an offense' do message = 'Unused block argument - `foo`. ' \ - "If it's necessary, use `_` or `_foo` as an argument " \ - "name to indicate that it won't be used." + "If it's necessary, use `_` or `_foo` as an argument " \ + "name to indicate that it won't be used." expect_offense(<<~RUBY) -> (foo, bar) { puts bar } @@ -283,8 +283,8 @@ context 'when the method call is `define_method`' do it 'registers an offense' do message = 'Unused block argument - `bar`. ' \ - "If it's necessary, use `_` or `_bar` as an argument name " \ - "to indicate that it won't be used." + "If it's necessary, use `_` or `_bar` as an argument name " \ + "to indicate that it won't be used." expect_offense(<<~RUBY) define_method(:foo) do |bar: 'default'| @@ -312,7 +312,7 @@ context 'when the method call is not `define_method`' do it 'registers an offense' do message = 'Unused block argument - `bar`. ' \ - "You can omit the argument if you don't care about it." + "You can omit the argument if you don't care about it." expect_offense(<<~RUBY) foo(:foo) do |bar: 'default'| @@ -480,9 +480,9 @@ def other(a) (arg1_message, arg2_message, others_message) = %w[arg1 arg2 others] .map do |arg| "Unused block argument - `#{arg}`. If it's necessary, use `_` or " \ - "`_#{arg}` as an argument name to indicate that it won't be used. " \ - 'Also consider using a proc without arguments instead of a lambda ' \ - "if you want it to accept any arguments but don't care about them." + "`_#{arg}` as an argument name to indicate that it won't be used. " \ + 'Also consider using a proc without arguments instead of a lambda ' \ + "if you want it to accept any arguments but don't care about them." end expect_offense(<<~RUBY) diff --git a/spec/rubocop/cop/lint/unused_method_argument_spec.rb b/spec/rubocop/cop/lint/unused_method_argument_spec.rb index 7b23b670872..4aa14251b66 100644 --- a/spec/rubocop/cop/lint/unused_method_argument_spec.rb +++ b/spec/rubocop/cop/lint/unused_method_argument_spec.rb @@ -14,8 +14,8 @@ context 'and an argument is unused' do it 'registers an offense and adds underscore-prefix' do message = 'Unused method argument - `foo`. ' \ - "If it's necessary, use `_` or `_foo` " \ - "as an argument name to indicate that it won't be used." + "If it's necessary, use `_` or `_foo` " \ + "as an argument name to indicate that it won't be used." expect_offense(<<~RUBY) def some_method(foo, bar) @@ -34,8 +34,8 @@ def some_method(_foo, bar) context 'and there is some whitespace around the unused argument' do it 'registers an offense and preserves whitespace' do message = 'Unused method argument - `bar`. ' \ - "If it's necessary, use `_` or `_bar` " \ - "as an argument name to indicate that it won't be used." + "If it's necessary, use `_` or `_bar` " \ + "as an argument name to indicate that it won't be used." expect_offense(<<~RUBY) def some_method(foo, @@ -67,8 +67,8 @@ def foo(a, b) context "and one argument is assigned to another, whilst other's value is not used" do it 'registers an offense' do message = "Unused method argument - `a`. If it's necessary, use " \ - '`_` or `_a` as an argument name to indicate that ' \ - "it won't be used." + '`_` or `_a` as an argument name to indicate that ' \ + "it won't be used." expect_offense(<<~RUBY) def foo(a, b) @@ -91,10 +91,10 @@ def foo(_a, b) 'auto-corrects to add underscore-prefix to all arguments' do (foo_message, bar_message) = %w[foo bar].map do |arg| "Unused method argument - `#{arg}`. " \ - "If it's necessary, use `_` or `_#{arg}` " \ - "as an argument name to indicate that it won't be used. " \ - 'You can also write as `some_method(*)` if you want the method ' \ - "to accept any arguments but don't care about them." + "If it's necessary, use `_` or `_#{arg}` " \ + "as an argument name to indicate that it won't be used. " \ + 'You can also write as `some_method(*)` if you want the method ' \ + "to accept any arguments but don't care about them." end expect_offense(<<~RUBY) @@ -115,8 +115,8 @@ def some_method(_foo, _bar) context 'when a splat argument is unused' do it 'registers an offense and preserves the splat' do message = 'Unused method argument - `bar`. ' \ - "If it's necessary, use `_` or `_bar` " \ - "as an argument name to indicate that it won't be used." + "If it's necessary, use `_` or `_bar` " \ + "as an argument name to indicate that it won't be used." expect_offense(<<~RUBY) def some_method(foo, *bar) @@ -136,8 +136,8 @@ def some_method(foo, *_bar) context 'when an argument with a default value is unused' do it 'registers an offense and preserves the default value' do message = 'Unused method argument - `bar`. ' \ - "If it's necessary, use `_` or `_bar` " \ - "as an argument name to indicate that it won't be used." + "If it's necessary, use `_` or `_bar` " \ + "as an argument name to indicate that it won't be used." expect_offense(<<~RUBY) def some_method(foo, bar = 1) @@ -195,8 +195,8 @@ def self.some_method(foo, bar: 1) context 'when a trailing block argument is unused' do it 'registers an offense and removes the unused block arg' do message = 'Unused method argument - `block`. ' \ - "If it's necessary, use `_` or `_block` " \ - "as an argument name to indicate that it won't be used." + "If it's necessary, use `_` or `_block` " \ + "as an argument name to indicate that it won't be used." expect_offense(<<~RUBY) def some_method(foo, bar, &block) @@ -216,10 +216,10 @@ def some_method(foo, bar) context 'when a singleton method argument is unused' do it 'registers an offense' do message = "Unused method argument - `foo`. If it's necessary, use " \ - '`_` or `_foo` as an argument name to indicate that it ' \ - "won't be used. You can also write as `some_method(*)` " \ - 'if you want the method to accept any arguments but ' \ - "don't care about them." + '`_` or `_foo` as an argument name to indicate that it ' \ + "won't be used. You can also write as `some_method(*)` " \ + 'if you want the method to accept any arguments but ' \ + "don't care about them." expect_offense(<<~RUBY) def self.some_method(foo) @@ -297,10 +297,10 @@ def some_method(foo) context 'when a method argument is unused' do it 'registers an offense' do message = "Unused method argument - `foo`. If it's necessary, use " \ - '`_` or `_foo` as an argument name to indicate that ' \ - "it won't be used. You can also write as " \ - '`some_method(*)` if you want the method to accept any ' \ - "arguments but don't care about them." + '`_` or `_foo` as an argument name to indicate that ' \ + "it won't be used. You can also write as " \ + '`some_method(*)` if you want the method to accept any ' \ + "arguments but don't care about them." expect_offense(<<~RUBY) def some_method(foo) @@ -332,9 +332,9 @@ def some_method(foo, bar) context 'inside another method definition' do (foo_message, bar_message) = %w[foo bar].map do |arg| "Unused method argument - `#{arg}`. If it's necessary, use `_` or " \ - "`_#{arg}` as an argument name to indicate that it won't be " \ - 'used. You can also write as `some_method(*)` if you want the ' \ - "method to accept any arguments but don't care about them." + "`_#{arg}` as an argument name to indicate that it won't be " \ + 'used. You can also write as `some_method(*)` if you want the ' \ + "method to accept any arguments but don't care about them." end it 'registers offenses' do @@ -363,10 +363,10 @@ def other(a) context 'when a method argument is unused' do it 'registers an offense' do message = "Unused method argument - `foo`. If it's necessary, use " \ - '`_` or `_foo` as an argument name to indicate that it ' \ - "won't be used. You can also write as `some_method(*)` " \ - 'if you want the method to accept any arguments but ' \ - "don't care about them." + '`_` or `_foo` as an argument name to indicate that it ' \ + "won't be used. You can also write as `some_method(*)` " \ + 'if you want the method to accept any arguments but ' \ + "don't care about them." expect_offense(<<~RUBY) def some_method(foo) @@ -404,10 +404,10 @@ def self.method(unused) it 'registers an offense for a non-empty method with a single unused parameter' do message = "Unused method argument - `arg`. If it's necessary, use " \ - '`_` or `_arg` as an argument name to indicate that it ' \ - "won't be used. You can also write as `method(*)` if you " \ - "want the method to accept any arguments but don't care " \ - 'about them.' + '`_` or `_arg` as an argument name to indicate that it ' \ + "won't be used. You can also write as `method(*)` if you " \ + "want the method to accept any arguments but don't care " \ + 'about them.' expect_offense(<<~RUBY) def method(arg) @@ -433,9 +433,9 @@ def method(a, b, *others) it 'registers an offense for a non-empty method with multiple unused parameters' do (a_message, b_message, others_message) = %w[a b others].map do |arg| "Unused method argument - `#{arg}`. If it's necessary, use `_` or " \ - "`_#{arg}` as an argument name to indicate that it won't be used. " \ - 'You can also write as `method(*)` if you want the method ' \ - "to accept any arguments but don't care about them." + "`_#{arg}` as an argument name to indicate that it won't be used. " \ + 'You can also write as `method(*)` if you want the method ' \ + "to accept any arguments but don't care about them." end expect_offense(<<~RUBY) @@ -501,10 +501,10 @@ def self.method(unused) it 'registers an offense for a non-empty method with a single unused parameter' do message = "Unused method argument - `arg`. If it's necessary, use " \ - '`_` or `_arg` as an argument name to indicate that it ' \ - "won't be used. You can also write as `method(*)` if you " \ - "want the method to accept any arguments but don't care " \ - 'about them.' + '`_` or `_arg` as an argument name to indicate that it ' \ + "won't be used. You can also write as `method(*)` if you " \ + "want the method to accept any arguments but don't care " \ + 'about them.' expect_offense(<<~RUBY) def method(arg) @@ -531,9 +531,9 @@ def method(a, b, *others) it 'registers an offense for a non-empty method with multiple unused parameters' do (a_message, b_message, others_message) = %w[a b others].map do |arg| "Unused method argument - `#{arg}`. If it's necessary, use `_` or " \ - "`_#{arg}` as an argument name to indicate that it won't be used. " \ - 'You can also write as `method(*)` if you want the method ' \ - "to accept any arguments but don't care about them." + "`_#{arg}` as an argument name to indicate that it won't be used. " \ + 'You can also write as `method(*)` if you want the method ' \ + "to accept any arguments but don't care about them." end expect_offense(<<~RUBY) diff --git a/spec/rubocop/cop/lint/useless_access_modifier_spec.rb b/spec/rubocop/cop/lint/useless_access_modifier_spec.rb index 0dd8661fc88..29ebd1e7a2b 100644 --- a/spec/rubocop/cop/lint/useless_access_modifier_spec.rb +++ b/spec/rubocop/cop/lint/useless_access_modifier_spec.rb @@ -816,7 +816,7 @@ def method1 context 'inside a class' do it 'registers an offense when a modifier is ouside the block and a ' \ - 'method is defined only inside the block' do + 'method is defined only inside the block' do expect_offense(<<~RUBY, modifier: modifier) class A %{modifier} @@ -830,7 +830,7 @@ def method1 end it 'registers two offenses when a modifier is inside and outside the ' \ - ' block and no method is defined' do + ' block and no method is defined' do expect_offense(<<~RUBY, modifier: modifier) class A %{modifier} @@ -888,7 +888,7 @@ def foo context 'inside a class' do it 'registers an offense when a modifier is ouside the block and a ' \ - 'method is defined only inside the block' do + 'method is defined only inside the block' do expect_offense(<<~RUBY, modifier: modifier) class A %{modifier} @@ -902,7 +902,7 @@ def method1 end it 'registers two offenses when a modifier is inside and outside the ' \ - ' and no method is defined' do + ' and no method is defined' do expect_offense(<<~RUBY, modifier: modifier) class A %{modifier} diff --git a/spec/rubocop/cop/lint/useless_assignment_spec.rb b/spec/rubocop/cop/lint/useless_assignment_spec.rb index b0e0ee29e9b..3cc5128cc58 100644 --- a/spec/rubocop/cop/lint/useless_assignment_spec.rb +++ b/spec/rubocop/cop/lint/useless_assignment_spec.rb @@ -761,8 +761,8 @@ def some_method end context 'when a variable is reassigned with binary operator ' \ - 'assignment while assigning to itself in rhs ' \ - 'then referenced' do + 'assignment while assigning to itself in rhs ' \ + 'then referenced' do it 'registers an offense for the assignment in rhs' do expect_offense(<<~RUBY) def some_method diff --git a/spec/rubocop/cop/style/conditional_assignment_assign_to_condition_spec.rb b/spec/rubocop/cop/style/conditional_assignment_assign_to_condition_spec.rb index bf2e2263292..6598633fa75 100644 --- a/spec/rubocop/cop/style/conditional_assignment_assign_to_condition_spec.rb +++ b/spec/rubocop/cop/style/conditional_assignment_assign_to_condition_spec.rb @@ -1717,8 +1717,8 @@ end it 'registers an offense in if elsif else with some branches only ' \ - 'containing variable assignment and others containing more than ' \ - 'variable assignment' do + 'containing variable assignment and others containing more than ' \ + 'variable assignment' do expect_offense(<<~RUBY) if foo ^^^^^^ Use the return of the conditional for variable assignment and comparison. diff --git a/spec/rubocop/cop/style/empty_literal_spec.rb b/spec/rubocop/cop/style/empty_literal_spec.rb index e5d457a5a07..f784a4bf1ac 100644 --- a/spec/rubocop/cop/style/empty_literal_spec.rb +++ b/spec/rubocop/cop/style/empty_literal_spec.rb @@ -174,7 +174,7 @@ end it 'auto-correct changes Hash.new to {} and wraps it in parentheses ' \ - 'when it is the only argument to super' do + 'when it is the only argument to super' do expect_offense(<<~RUBY) def foo super Hash.new @@ -190,7 +190,7 @@ def foo end it 'auto-correct changes Hash.new to {} and wraps all arguments in ' \ - 'parentheses when it is the first argument to super' do + 'parentheses when it is the first argument to super' do expect_offense(<<~RUBY) def foo super Hash.new, something diff --git a/spec/rubocop/cop/style/frozen_string_literal_comment_spec.rb b/spec/rubocop/cop/style/frozen_string_literal_comment_spec.rb index 1550ef23957..dfbd4a9d526 100644 --- a/spec/rubocop/cop/style/frozen_string_literal_comment_spec.rb +++ b/spec/rubocop/cop/style/frozen_string_literal_comment_spec.rb @@ -386,7 +386,7 @@ end it 'allows not having a frozen string literal comment ' \ - 'under a shebang and an encoding comment' do + 'under a shebang and an encoding comment' do expect_no_offenses(<<~RUBY) #!/usr/bin/env ruby # encoding: utf-8 @@ -395,7 +395,7 @@ end it 'registers an offense for a frozen string literal comment ' \ - 'below shebang and encoding comments' do + 'below shebang and encoding comments' do expect_offense(<<~RUBY) #!/usr/bin/env ruby # encoding: utf-8 @@ -412,7 +412,7 @@ end it 'registers an offense for a disabled frozen string literal comment ' \ - 'below shebang and encoding comments' do + 'below shebang and encoding comments' do expect_offense(<<~RUBY) #!/usr/bin/env ruby # encoding: utf-8 @@ -429,7 +429,7 @@ end it 'registers an offense for a frozen string literal comment ' \ - 'below shebang above an encoding comments' do + 'below shebang above an encoding comments' do expect_offense(<<~RUBY) #!/usr/bin/env ruby # frozen_string_literal: true @@ -446,7 +446,7 @@ end it 'registers an offense for a disabled frozen string literal comment ' \ - 'below shebang above an encoding comments' do + 'below shebang above an encoding comments' do expect_offense(<<~RUBY) #!/usr/bin/env ruby # frozen_string_literal: false diff --git a/spec/rubocop/cop/style/keyword_parameters_order_spec.rb b/spec/rubocop/cop/style/keyword_parameters_order_spec.rb index 2a145917391..02e749b9bff 100644 --- a/spec/rubocop/cop/style/keyword_parameters_order_spec.rb +++ b/spec/rubocop/cop/style/keyword_parameters_order_spec.rb @@ -60,7 +60,7 @@ def m(arg, required1:, required2:, optional1: 1, optional2: 2, **rest, &block) end it 'registers an offense and corrects when multiple `kwoptarg`s are interleaved with `kwarg`s' \ - 'and last argument is `kwrestarg` and argument parentheses omitted' do + 'and last argument is `kwrestarg` and argument parentheses omitted' do expect_offense(<<~RUBY) def m arg, optional1: 1, required1:, optional2: 2, required2:, **rest ^^^^^^^^^^^^ Place optional keyword parameters at the end of the parameters list. @@ -77,7 +77,7 @@ def m arg, required1:, required2:, optional1: 1, optional2: 2, **rest end it 'registers an offense and corrects when multiple `kwoptarg`s are interleaved with `kwarg`s' \ - 'and last argument is `blockarg` and argument parentheses omitted' do + 'and last argument is `blockarg` and argument parentheses omitted' do expect_offense(<<~RUBY) def m arg, optional1: 1, required1:, optional2: 2, required2:, **rest, &block ^^^^^^^^^^^^ Place optional keyword parameters at the end of the parameters list. diff --git a/spec/rubocop/cop/style/missing_respond_to_missing_spec.rb b/spec/rubocop/cop/style/missing_respond_to_missing_spec.rb index 69cf67f97fb..c490103ebc4 100644 --- a/spec/rubocop/cop/style/missing_respond_to_missing_spec.rb +++ b/spec/rubocop/cop/style/missing_respond_to_missing_spec.rb @@ -71,7 +71,7 @@ def method_missing end it 'registers an offense respond_to_missing? is implemented as ' \ - 'an instance method and method_missing is implemented as a class method' do + 'an instance method and method_missing is implemented as a class method' do expect_offense(<<~RUBY) class Test def self.method_missing @@ -85,7 +85,7 @@ def respond_to_missing? end it 'registers an offense respond_to_missing? is implemented as ' \ - 'a class method and method_missing is implemented as an instance method' do + 'a class method and method_missing is implemented as an instance method' do expect_offense(<<~RUBY) class Test def self.respond_to_missing? diff --git a/spec/rubocop/cop/style/multiple_comparison_spec.rb b/spec/rubocop/cop/style/multiple_comparison_spec.rb index 843649a6aec..6232faab8e2 100644 --- a/spec/rubocop/cop/style/multiple_comparison_spec.rb +++ b/spec/rubocop/cop/style/multiple_comparison_spec.rb @@ -62,7 +62,7 @@ end it 'registers an offense and corrects when `a` is compared three times, once on the ' \ - 'righthand side' do + 'righthand side' do expect_offense(<<~RUBY) a = "a" if a == "a" || "b" == a || a == "c" diff --git a/spec/rubocop/cop/style/one_line_conditional_spec.rb b/spec/rubocop/cop/style/one_line_conditional_spec.rb index f1f4cf7d282..be8a5fbabf5 100644 --- a/spec/rubocop/cop/style/one_line_conditional_spec.rb +++ b/spec/rubocop/cop/style/one_line_conditional_spec.rb @@ -12,11 +12,11 @@ end let(:if_offense_message) do 'Favor the ternary operator (`?:`) or multi-line constructs over single-line ' \ - '`if/then/else/end` constructs.' + '`if/then/else/end` constructs.' end let(:unless_offense_message) do 'Favor the ternary operator (`?:`) or multi-line constructs over single-line ' \ - '`unless/then/else/end` constructs.' + '`unless/then/else/end` constructs.' end context 'when AlwaysCorrectToMultiline is false' do diff --git a/spec/rubocop/cop/style/parallel_assignment_spec.rb b/spec/rubocop/cop/style/parallel_assignment_spec.rb index f351528a9a5..5b7a2782106 100644 --- a/spec/rubocop/cop/style/parallel_assignment_spec.rb +++ b/spec/rubocop/cop/style/parallel_assignment_spec.rb @@ -572,7 +572,7 @@ def bar end it 'corrects when the expression uses a modifier rescue statement ' \ - 'as the only thing inside of a method' do + 'as the only thing inside of a method' do expect_offense(<<~RUBY) def foo a, b = 1, 2 rescue foo diff --git a/spec/rubocop/cop/style/redundant_condition_spec.rb b/spec/rubocop/cop/style/redundant_condition_spec.rb index 9e62ef76cbf..820b69fb30b 100644 --- a/spec/rubocop/cop/style/redundant_condition_spec.rb +++ b/spec/rubocop/cop/style/redundant_condition_spec.rb @@ -190,7 +190,7 @@ end it 'registers an offense and corrects when `if` condition and `then` ' \ - 'branch are the same and it has no `else` branch' do + 'branch are the same and it has no `else` branch' do expect_offense(<<~RUBY) if do_something ^^^^^^^^^^^^^^^ This condition is not needed. diff --git a/spec/rubocop/cop/style/redundant_self_spec.rb b/spec/rubocop/cop/style/redundant_self_spec.rb index 7d4d6f975fc..ac89d8e67e9 100644 --- a/spec/rubocop/cop/style/redundant_self_spec.rb +++ b/spec/rubocop/cop/style/redundant_self_spec.rb @@ -213,7 +213,7 @@ def foo(bar) end it 'accepts a self receiver used to distinguish from an argument' \ - ' when an inner method is defined' do + ' when an inner method is defined' do expect_no_offenses(<<~RUBY) def foo(bar) def inner_method(); end diff --git a/spec/rubocop/cop/style/safe_navigation_spec.rb b/spec/rubocop/cop/style/safe_navigation_spec.rb index 4f0eb9167a6..a69e10d4f6e 100644 --- a/spec/rubocop/cop/style/safe_navigation_spec.rb +++ b/spec/rubocop/cop/style/safe_navigation_spec.rb @@ -370,7 +370,7 @@ end it 'registers an offense for a chained method call safeguarded ' \ - 'with an unless nil check for the object' do + 'with an unless nil check for the object' do expect_offense(<<~RUBY, variable: variable) %{variable}.one.two(baz) { |e| e.qux } unless %{variable}.nil? ^{variable}^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^{variable}^^^^^ Use safe navigation (`&.`) instead [...] diff --git a/spec/rubocop/cop/style/trailing_comma_in_arguments_spec.rb b/spec/rubocop/cop/style/trailing_comma_in_arguments_spec.rb index 42d4a8997a4..7af979ba916 100644 --- a/spec/rubocop/cop/style/trailing_comma_in_arguments_spec.rb +++ b/spec/rubocop/cop/style/trailing_comma_in_arguments_spec.rb @@ -47,7 +47,7 @@ end it 'accepts method call without trailing comma with single element hash' \ - ' parameters at the end' do + ' parameters at the end' do expect_no_offenses('some_method(a: 1)') end @@ -83,7 +83,7 @@ end it 'registers an offense for trailing comma in a method call with hash' \ - ' parameters at the end' do + ' parameters at the end' do expect_offense(<<~RUBY) receiver&.some_method(a, b, c: 0, d: 1, ) ^ Avoid comma after the last parameter of a method call#{extra_info}. @@ -468,7 +468,7 @@ end it 'registers an offense for no trailing comma in a method call with' \ - 'two parameters on the same line' do + 'two parameters on the same line' do expect_offense(<<~RUBY) some_method(a, b ^ Put a comma after the last parameter of a multiline method call. diff --git a/spec/rubocop/cop/team_spec.rb b/spec/rubocop/cop/team_spec.rb index 0bba1b2b29d..2be4406a87c 100644 --- a/spec/rubocop/cop/team_spec.rb +++ b/spec/rubocop/cop/team_spec.rb @@ -172,7 +172,7 @@ def a let(:error_message) do 'An error occurred while Style/NumericLiterals cop was inspecting ' \ - '/tmp/example.rb:1:0.' + '/tmp/example.rb:1:0.' end it 'records Team#errors' do @@ -206,7 +206,7 @@ def a let(:error_message) do 'An error occurred while Bundler/OrderedGems cop was inspecting ' \ - '/tmp/Gemfile.' + '/tmp/Gemfile.' end it 'records Team#errors' do diff --git a/spec/rubocop/runner_spec.rb b/spec/rubocop/runner_spec.rb index af432599056..d8db03d34bc 100644 --- a/spec/rubocop/runner_spec.rb +++ b/spec/rubocop/runner_spec.rb @@ -217,7 +217,7 @@ class Klass end.to raise_error( RuboCop::Runner::InfiniteCorrectionLoop, "Infinite loop detected in #{source_file_path} and caused by " \ - 'Test/ClassMustBeAModuleCop -> Test/ModuleMustBeAClassCop' + 'Test/ClassMustBeAModuleCop -> Test/ModuleMustBeAClassCop' ) end end @@ -237,7 +237,7 @@ class AnotherKlass end.to raise_error( RuboCop::Runner::InfiniteCorrectionLoop, "Infinite loop detected in #{source_file_path} and caused by " \ - 'Test/ClassMustBeAModuleCop -> Test/ModuleMustBeAClassCop' + 'Test/ClassMustBeAModuleCop -> Test/ModuleMustBeAClassCop' ) end end @@ -273,8 +273,8 @@ class A_A end.to raise_error( RuboCop::Runner::InfiniteCorrectionLoop, "Infinite loop detected in #{source_file_path} and caused by " \ - 'Test/ClassMustBeAModuleCop, Test/AtoB ' \ - '-> Test/ModuleMustBeAClassCop, Test/BtoA' + 'Test/ClassMustBeAModuleCop, Test/AtoB ' \ + '-> Test/ModuleMustBeAClassCop, Test/BtoA' ) end end @@ -308,7 +308,7 @@ class A end.to raise_error( RuboCop::Runner::InfiniteCorrectionLoop, "Infinite loop detected in #{source_file_path} and caused by " \ - 'Test/AtoB -> Test/BtoC -> Test/CtoA' + 'Test/AtoB -> Test/BtoC -> Test/CtoA' ) end end diff --git a/spec/support/empty_lines_around_body_shared_examples.rb b/spec/support/empty_lines_around_body_shared_examples.rb index 426525569f3..cdc7460bd7f 100644 --- a/spec/support/empty_lines_around_body_shared_examples.rb +++ b/spec/support/empty_lines_around_body_shared_examples.rb @@ -37,7 +37,7 @@ def do_something; end context "when #{type} has a namespace" do it 'requires no empty lines for namespace but '\ - "requires blank line at the beginning and ending of #{type} body" do + "requires blank line at the beginning and ending of #{type} body" do expect_no_offenses(<<~RUBY) #{type} Parent #{type} SomeObject @@ -147,8 +147,8 @@ def do_something; end context 'when first child is NOT a method' do it "does not require blank line at the beginning of #{type} body "\ - 'but requires blank line before first def definition '\ - "and requires blank line at the end of #{type} body" do + 'but requires blank line before first def definition '\ + "and requires blank line at the end of #{type} body" do expect_no_offenses(<<~RUBY) #{type} SomeObject include Something @@ -233,8 +233,8 @@ def do_something; end context "when #{type} has a namespace" do it 'requires no empty lines for namespace '\ - "and does not require blank line at the beginning of #{type} body "\ - "but requires blank line at the end of #{type} body" do + "and does not require blank line at the beginning of #{type} body "\ + "but requires blank line at the end of #{type} body" do expect_no_offenses(<<~RUBY) #{type} Parent #{type} SomeObject diff --git a/tasks/cut_release.rake b/tasks/cut_release.rake index 4425ce4e61f..055711edb03 100644 --- a/tasks/cut_release.rake +++ b/tasks/cut_release.rake @@ -74,7 +74,7 @@ namespace :cut_release do def add_header_to_changelog(version) update_file('CHANGELOG.md') do |changelog| changelog.sub("## master (unreleased)\n\n", '\0' \ - "## #{version} (#{Time.now.strftime('%F')})\n\n") + "## #{version} (#{Time.now.strftime('%F')})\n\n") end end