rubocop 0.77.0 → 0.79.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/config/default.yml +39 -26
- data/lib/rubocop.rb +11 -2
- data/lib/rubocop/ast/builder.rb +43 -42
- data/lib/rubocop/ast/node/def_node.rb +11 -0
- data/lib/rubocop/ast/node/forward_args_node.rb +18 -0
- data/lib/rubocop/ast/traversal.rb +11 -3
- data/lib/rubocop/cli/command/auto_genenerate_config.rb +7 -7
- data/lib/rubocop/cli/command/show_cops.rb +11 -4
- data/lib/rubocop/config.rb +1 -1
- data/lib/rubocop/config_loader.rb +19 -19
- data/lib/rubocop/config_obsoletion.rb +3 -3
- data/lib/rubocop/config_validator.rb +55 -95
- data/lib/rubocop/cop/autocorrect_logic.rb +7 -4
- data/lib/rubocop/cop/bundler/insecure_protocol_source.rb +2 -2
- data/lib/rubocop/cop/cop.rb +3 -1
- data/lib/rubocop/cop/gemspec/ordered_dependencies.rb +1 -1
- data/lib/rubocop/cop/generator.rb +3 -4
- data/lib/rubocop/cop/generator/configuration_injector.rb +1 -1
- data/lib/rubocop/cop/layout/first_argument_indentation.rb +2 -2
- data/lib/rubocop/cop/layout/hash_alignment.rb +8 -4
- data/lib/rubocop/cop/layout/heredoc_indentation.rb +4 -4
- data/lib/rubocop/cop/{metrics → layout}/line_length.rb +5 -78
- data/lib/rubocop/cop/layout/multiline_block_layout.rb +14 -5
- data/lib/rubocop/cop/layout/space_around_operators.rb +31 -6
- data/lib/rubocop/cop/layout/space_before_block_braces.rb +17 -0
- data/lib/rubocop/cop/lint/debugger.rb +2 -2
- data/lib/rubocop/cop/lint/each_with_object_argument.rb +1 -1
- data/lib/rubocop/cop/lint/non_deterministic_require_order.rb +89 -0
- data/lib/rubocop/cop/lint/redundant_cop_disable_directive.rb +3 -3
- data/lib/rubocop/cop/lint/redundant_cop_enable_directive.rb +4 -4
- data/lib/rubocop/cop/migration/department_name.rb +16 -1
- data/lib/rubocop/cop/mixin/alignment.rb +1 -1
- data/lib/rubocop/cop/mixin/frozen_string_literal.rb +1 -7
- data/lib/rubocop/cop/mixin/line_length_help.rb +88 -0
- data/lib/rubocop/cop/mixin/rational_literal.rb +18 -0
- data/lib/rubocop/cop/mixin/statement_modifier.rb +2 -2
- data/lib/rubocop/cop/mixin/trailing_comma.rb +6 -3
- data/lib/rubocop/cop/naming/method_parameter_name.rb +1 -1
- data/lib/rubocop/cop/offense.rb +11 -0
- data/lib/rubocop/cop/registry.rb +7 -2
- data/lib/rubocop/cop/style/attr.rb +8 -0
- data/lib/rubocop/cop/style/conditional_assignment.rb +2 -2
- data/lib/rubocop/cop/style/guard_clause.rb +3 -2
- data/lib/rubocop/cop/style/if_unless_modifier.rb +38 -3
- data/lib/rubocop/cop/style/infinite_loop.rb +1 -1
- data/lib/rubocop/cop/style/method_call_with_args_parentheses.rb +4 -207
- data/lib/rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses.rb +168 -0
- data/lib/rubocop/cop/style/method_call_with_args_parentheses/require_parentheses.rb +54 -0
- data/lib/rubocop/cop/style/multiline_method_signature.rb +1 -1
- data/lib/rubocop/cop/style/multiline_when_then.rb +5 -1
- data/lib/rubocop/cop/style/numeric_predicate.rb +4 -3
- data/lib/rubocop/cop/style/percent_literal_delimiters.rb +7 -7
- data/lib/rubocop/cop/style/trailing_underscore_variable.rb +7 -1
- data/lib/rubocop/cop/style/while_until_modifier.rb +1 -1
- data/lib/rubocop/cop/style/yoda_condition.rb +16 -1
- data/lib/rubocop/formatter/base_formatter.rb +2 -2
- data/lib/rubocop/formatter/json_formatter.rb +6 -5
- data/lib/rubocop/node_pattern.rb +1 -1
- data/lib/rubocop/options.rb +8 -8
- data/lib/rubocop/result_cache.rb +2 -0
- data/lib/rubocop/rspec/shared_contexts.rb +5 -0
- data/lib/rubocop/runner.rb +5 -1
- data/lib/rubocop/target_ruby.rb +151 -0
- data/lib/rubocop/version.rb +1 -1
- metadata +12 -5
data/lib/rubocop/config.rb
CHANGED
@@ -115,7 +115,7 @@ module RuboCop
|
|
115
115
|
relative_file_path = path_relative_to_config(file)
|
116
116
|
|
117
117
|
# Optimization to quickly decide if the given file is hidden (on the top
|
118
|
-
# level) and
|
118
|
+
# level) and cannot be matched by any pattern.
|
119
119
|
is_hidden = relative_file_path.start_with?('.') &&
|
120
120
|
!relative_file_path.start_with?('..')
|
121
121
|
return false if is_hidden && !possibly_include_hidden?
|
@@ -91,7 +91,9 @@ module RuboCop
|
|
91
91
|
else
|
92
92
|
add_excludes_from_files(config, config_file)
|
93
93
|
end
|
94
|
-
merge_with_default(config, config_file)
|
94
|
+
merge_with_default(config, config_file).tap do |merged_config|
|
95
|
+
warn_on_pending_cops(merged_config)
|
96
|
+
end
|
95
97
|
end
|
96
98
|
|
97
99
|
def add_excludes_from_files(config, config_file)
|
@@ -114,6 +116,22 @@ module RuboCop
|
|
114
116
|
end
|
115
117
|
end
|
116
118
|
|
119
|
+
def warn_on_pending_cops(config)
|
120
|
+
pending_cops = config.keys.select do |key|
|
121
|
+
config[key]['Enabled'] == 'pending'
|
122
|
+
end
|
123
|
+
|
124
|
+
return if pending_cops.none?
|
125
|
+
|
126
|
+
warn Rainbow('The following cops were added to RuboCop, but are not ' \
|
127
|
+
'configured. Please set Enabled to either `true` or ' \
|
128
|
+
'`false` in your `.rubocop.yml` file:').yellow
|
129
|
+
|
130
|
+
pending_cops.each do |cop|
|
131
|
+
warn Rainbow(" - #{cop}").yellow
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
117
135
|
# Merges the given configuration with the default one. If
|
118
136
|
# AllCops:DisabledByDefault is true, it changes the Enabled params so
|
119
137
|
# that only cops from user configuration are enabled.
|
@@ -199,8 +217,6 @@ module RuboCop
|
|
199
217
|
raise(TypeError, "Malformed configuration in #{absolute_path}")
|
200
218
|
end
|
201
219
|
|
202
|
-
check_cop_config_value(hash)
|
203
|
-
|
204
220
|
hash
|
205
221
|
end
|
206
222
|
|
@@ -222,22 +238,6 @@ module RuboCop
|
|
222
238
|
end
|
223
239
|
end
|
224
240
|
|
225
|
-
def check_cop_config_value(hash, parent = nil)
|
226
|
-
hash.each do |key, value|
|
227
|
-
check_cop_config_value(value, key) if value.is_a?(Hash)
|
228
|
-
|
229
|
-
next unless %w[Enabled
|
230
|
-
Safe
|
231
|
-
SafeAutoCorrect
|
232
|
-
AutoCorrect].include?(key) && value.is_a?(String)
|
233
|
-
|
234
|
-
abort(
|
235
|
-
"Property #{Rainbow(key).yellow} of cop #{Rainbow(parent).yellow}" \
|
236
|
-
" is supposed to be a boolean and #{Rainbow(value).yellow} is not."
|
237
|
-
)
|
238
|
-
end
|
239
|
-
end
|
240
|
-
|
241
241
|
# Read the specified file, or exit with a friendly, concise message on
|
242
242
|
# stderr. Care is taken to use the standard OS exit code for a "file not
|
243
243
|
# found" error.
|
@@ -48,7 +48,7 @@ module RuboCop
|
|
48
48
|
Style/VariableName Style/VariableNumber
|
49
49
|
Style/AccessorMethodName Style/AsciiIdentifiers],
|
50
50
|
'Layout' => %w[Lint/BlockAlignment Lint/EndAlignment
|
51
|
-
Lint/DefEndAlignment],
|
51
|
+
Lint/DefEndAlignment Metrics/LineLength],
|
52
52
|
'Lint' => 'Style/FlipFlop'
|
53
53
|
}.map do |new_department, old_names|
|
54
54
|
Array(old_names).map do |old_name|
|
@@ -114,13 +114,13 @@ module RuboCop
|
|
114
114
|
cops: 'Style/IfUnlessModifier',
|
115
115
|
parameters: 'MaxLineLength',
|
116
116
|
alternative: '`Style/IfUnlessModifier: MaxLineLength` has been ' \
|
117
|
-
'removed. Use `
|
117
|
+
'removed. Use `Layout/LineLength: Max` instead'
|
118
118
|
},
|
119
119
|
{
|
120
120
|
cops: 'Style/WhileUntilModifier',
|
121
121
|
parameters: 'MaxLineLength',
|
122
122
|
alternative: '`Style/WhileUntilModifier: MaxLineLength` has been ' \
|
123
|
-
'removed. Use `
|
123
|
+
'removed. Use `Layout/LineLength: Max` instead'
|
124
124
|
},
|
125
125
|
{
|
126
126
|
cops: 'AllCops',
|
@@ -14,25 +14,19 @@ module RuboCop
|
|
14
14
|
VersionAdded VersionChanged VersionRemoved
|
15
15
|
Reference Safe SafeAutoCorrect].freeze
|
16
16
|
|
17
|
-
|
18
|
-
DEFAULT_RUBY_VERSION = 2.3
|
19
|
-
KNOWN_RUBIES = [2.3, 2.4, 2.5, 2.6, 2.7].freeze
|
20
|
-
OBSOLETE_RUBIES = {
|
21
|
-
1.9 => '0.50', 2.0 => '0.50', 2.1 => '0.58', 2.2 => '0.69'
|
22
|
-
}.freeze
|
23
|
-
RUBY_VERSION_FILENAME = '.ruby-version'
|
24
|
-
|
25
|
-
def_delegators :@config,
|
26
|
-
:smart_loaded_path, :for_all_cops, :find_file_upwards,
|
27
|
-
:base_dir_for_path_parameters, :bundler_lock_file_path
|
17
|
+
def_delegators :@config, :smart_loaded_path, :for_all_cops
|
28
18
|
|
29
19
|
def initialize(config)
|
30
20
|
@config = config
|
31
21
|
@config_obsoletion = ConfigObsoletion.new(config)
|
22
|
+
@target_ruby = TargetRuby.new(config)
|
32
23
|
end
|
33
24
|
|
34
25
|
def validate
|
35
|
-
|
26
|
+
check_cop_config_value(@config)
|
27
|
+
reject_conflicting_safe_settings
|
28
|
+
|
29
|
+
# Don't validate RuboCop's own files further. Avoids infinite recursion.
|
36
30
|
return if @config.internal?
|
37
31
|
|
38
32
|
valid_cop_names, invalid_cop_names = @config.keys.partition do |key|
|
@@ -41,7 +35,7 @@ module RuboCop
|
|
41
35
|
|
42
36
|
@config_obsoletion.reject_obsolete_cops_and_parameters
|
43
37
|
|
44
|
-
|
38
|
+
alert_about_unrecognized_cops(invalid_cop_names)
|
45
39
|
check_target_ruby
|
46
40
|
validate_parameter_names(valid_cop_names)
|
47
41
|
validate_enforced_styles(valid_cop_names)
|
@@ -50,23 +44,7 @@ module RuboCop
|
|
50
44
|
end
|
51
45
|
|
52
46
|
def target_ruby_version
|
53
|
-
|
54
|
-
if for_all_cops['TargetRubyVersion']
|
55
|
-
@target_ruby_version_source = :rubocop_yml
|
56
|
-
|
57
|
-
for_all_cops['TargetRubyVersion'].to_f
|
58
|
-
elsif target_ruby_version_from_version_file
|
59
|
-
@target_ruby_version_source = :ruby_version_file
|
60
|
-
|
61
|
-
target_ruby_version_from_version_file
|
62
|
-
elsif target_ruby_version_from_bundler_lock_file
|
63
|
-
@target_ruby_version_source = :bundler_lock_file
|
64
|
-
|
65
|
-
target_ruby_version_from_bundler_lock_file
|
66
|
-
else
|
67
|
-
DEFAULT_RUBY_VERSION
|
68
|
-
end
|
69
|
-
end
|
47
|
+
target_ruby.version
|
70
48
|
end
|
71
49
|
|
72
50
|
def validate_section_presence(name)
|
@@ -78,25 +56,30 @@ module RuboCop
|
|
78
56
|
|
79
57
|
private
|
80
58
|
|
59
|
+
attr_reader :target_ruby
|
60
|
+
|
81
61
|
def check_target_ruby
|
82
|
-
return if
|
62
|
+
return if target_ruby.supported?
|
83
63
|
|
84
|
-
|
64
|
+
source = target_ruby.source
|
65
|
+
last_version = target_ruby.rubocop_version_with_support
|
66
|
+
|
67
|
+
msg = if last_version
|
85
68
|
"RuboCop found unsupported Ruby version #{target_ruby_version} " \
|
86
|
-
"in #{
|
87
|
-
|
88
|
-
"#{OBSOLETE_RUBIES[target_ruby_version]}."
|
69
|
+
"in #{source}. #{target_ruby_version}-compatible " \
|
70
|
+
"analysis was dropped after version #{last_version}."
|
89
71
|
else
|
90
72
|
'RuboCop found unknown Ruby version ' \
|
91
|
-
"#{target_ruby_version.inspect} in #{
|
73
|
+
"#{target_ruby_version.inspect} in #{source}."
|
92
74
|
end
|
93
75
|
|
94
|
-
msg += "\nSupported versions: #{
|
76
|
+
msg += "\nSupported versions: #{TargetRuby.supported_versions.join(', ')}"
|
95
77
|
|
96
78
|
raise ValidationError, msg
|
97
79
|
end
|
98
80
|
|
99
|
-
def
|
81
|
+
def alert_about_unrecognized_cops(invalid_cop_names)
|
82
|
+
unknown_cops = []
|
100
83
|
invalid_cop_names.each do |name|
|
101
84
|
# There could be a custom cop with this name. If so, don't warn
|
102
85
|
next if Cop::Cop.registry.contains_cop_matching?([name])
|
@@ -106,9 +89,10 @@ module RuboCop
|
|
106
89
|
# to do so than to pass the value around to various methods.
|
107
90
|
next if name == 'inherit_mode'
|
108
91
|
|
109
|
-
|
110
|
-
|
92
|
+
unknown_cops << "unrecognized cop #{name} found in " \
|
93
|
+
"#{smart_loaded_path}"
|
111
94
|
end
|
95
|
+
raise ValidationError, unknown_cops.join(', ') if unknown_cops.any?
|
112
96
|
end
|
113
97
|
|
114
98
|
def validate_syntax_cop
|
@@ -176,71 +160,47 @@ module RuboCop
|
|
176
160
|
formats.all? { |format| valid.include?(format) }
|
177
161
|
end
|
178
162
|
|
179
|
-
def
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
when :bundler_lock_file
|
184
|
-
"`#{bundler_lock_file_path}`"
|
185
|
-
when :rubocop_yml
|
186
|
-
"`TargetRubyVersion` parameter (in #{smart_loaded_path})"
|
187
|
-
end
|
188
|
-
end
|
163
|
+
def reject_mutually_exclusive_defaults
|
164
|
+
disabled_by_default = for_all_cops['DisabledByDefault']
|
165
|
+
enabled_by_default = for_all_cops['EnabledByDefault']
|
166
|
+
return unless disabled_by_default && enabled_by_default
|
189
167
|
|
190
|
-
|
191
|
-
|
192
|
-
find_file_upwards(RUBY_VERSION_FILENAME, base_dir_for_path_parameters)
|
168
|
+
msg = 'Cops cannot be both enabled by default and disabled by default'
|
169
|
+
raise ValidationError, msg
|
193
170
|
end
|
194
171
|
|
195
|
-
def
|
196
|
-
|
197
|
-
|
172
|
+
def reject_conflicting_safe_settings
|
173
|
+
@config.each do |name, cop_config|
|
174
|
+
next unless cop_config.is_a?(Hash)
|
175
|
+
next unless cop_config['Safe'] == false &&
|
176
|
+
cop_config['SafeAutoCorrect'] == true
|
198
177
|
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
178
|
+
msg = 'Unsafe cops cannot have a safe auto-correction ' \
|
179
|
+
"(section #{name} in #{smart_loaded_path})"
|
180
|
+
raise ValidationError, msg
|
181
|
+
end
|
203
182
|
end
|
204
183
|
|
205
|
-
def
|
206
|
-
|
207
|
-
|
208
|
-
|
184
|
+
def check_cop_config_value(hash, parent = nil)
|
185
|
+
hash.each do |key, value|
|
186
|
+
check_cop_config_value(value, key) if value.is_a?(Hash)
|
187
|
+
|
188
|
+
next unless %w[Enabled
|
189
|
+
Safe
|
190
|
+
SafeAutoCorrect
|
191
|
+
AutoCorrect].include?(key) && value.is_a?(String)
|
192
|
+
|
193
|
+
next if key == 'Enabled' && value == 'pending'
|
209
194
|
|
210
|
-
|
211
|
-
lock_file_path = bundler_lock_file_path
|
212
|
-
return nil unless lock_file_path
|
213
|
-
|
214
|
-
in_ruby_section = false
|
215
|
-
File.foreach(lock_file_path) do |line|
|
216
|
-
# If ruby is in Gemfile.lock or gems.lock, there should be two lines
|
217
|
-
# towards the bottom of the file that look like:
|
218
|
-
# RUBY VERSION
|
219
|
-
# ruby W.X.YpZ
|
220
|
-
# We ultimately want to match the "ruby W.X.Y.pZ" line, but there's
|
221
|
-
# extra logic to make sure we only start looking once we've seen the
|
222
|
-
# "RUBY VERSION" line.
|
223
|
-
in_ruby_section ||= line.match(/^\s*RUBY\s*VERSION\s*$/)
|
224
|
-
next unless in_ruby_section
|
225
|
-
|
226
|
-
# We currently only allow this feature to work with MRI ruby. If jruby
|
227
|
-
# (or something else) is used by the project, it's lock file will have a
|
228
|
-
# line that looks like:
|
229
|
-
# RUBY VERSION
|
230
|
-
# ruby W.X.YpZ (jruby x.x.x.x)
|
231
|
-
# The regex won't match in this situation.
|
232
|
-
result = line.match(/^\s*ruby\s+(\d+\.\d+)[p.\d]*\s*$/)
|
233
|
-
return result.captures.first.to_f if result
|
195
|
+
raise ValidationError, msg_not_boolean(parent, key, value)
|
234
196
|
end
|
235
197
|
end
|
236
198
|
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
msg = 'Cops cannot be both enabled by default and disabled by default'
|
243
|
-
raise ValidationError, msg
|
199
|
+
# FIXME: Handling colors in exception messages like this is ugly.
|
200
|
+
def msg_not_boolean(parent, key, value)
|
201
|
+
"#{Rainbow('').reset}" \
|
202
|
+
"Property #{Rainbow(key).yellow} of cop #{Rainbow(parent).yellow}" \
|
203
|
+
" is supposed to be a boolean and #{Rainbow(value).yellow} is not."
|
244
204
|
end
|
245
205
|
end
|
246
206
|
end
|
@@ -24,15 +24,18 @@ module RuboCop
|
|
24
24
|
@options[:disable_uncorrectable] == true
|
25
25
|
end
|
26
26
|
|
27
|
+
def safe_autocorrect?
|
28
|
+
cop_config.fetch('Safe', true) &&
|
29
|
+
cop_config.fetch('SafeAutoCorrect', true)
|
30
|
+
end
|
31
|
+
|
27
32
|
def autocorrect_enabled?
|
28
33
|
# allow turning off autocorrect on a cop by cop basis
|
29
34
|
return true unless cop_config
|
30
35
|
|
31
36
|
return false if cop_config['AutoCorrect'] == false
|
32
37
|
|
33
|
-
if @options.fetch(:safe_auto_correct, false)
|
34
|
-
return cop_config.fetch('SafeAutoCorrect', true)
|
35
|
-
end
|
38
|
+
return safe_autocorrect? if @options.fetch(:safe_auto_correct, false)
|
36
39
|
|
37
40
|
true
|
38
41
|
end
|
@@ -76,7 +79,7 @@ module RuboCop
|
|
76
79
|
end
|
77
80
|
|
78
81
|
def max_line_length
|
79
|
-
config.for_cop('
|
82
|
+
config.for_cop('Layout/LineLength')['Max'] || 80
|
80
83
|
end
|
81
84
|
|
82
85
|
def disable_offense_at_end_of_line(range, eol_comment)
|
@@ -13,8 +13,8 @@ module RuboCop
|
|
13
13
|
#
|
14
14
|
# However, it don't replace all `sources` of `http://` with `https://`.
|
15
15
|
# For example, when specifying an internal gem server using HTTP on the
|
16
|
-
# intranet, a use case where HTTPS
|
17
|
-
# Consider using HTTP only if you
|
16
|
+
# intranet, a use case where HTTPS cannot be specified was considered.
|
17
|
+
# Consider using HTTP only if you cannot use HTTPS.
|
18
18
|
#
|
19
19
|
# @example
|
20
20
|
# # bad
|
data/lib/rubocop/cop/cop.rb
CHANGED
@@ -172,6 +172,8 @@ module RuboCop
|
|
172
172
|
end
|
173
173
|
|
174
174
|
def disable_uncorrectable(node)
|
175
|
+
return unless node
|
176
|
+
|
175
177
|
@disabled_lines ||= {}
|
176
178
|
line = node.location.line
|
177
179
|
return if @disabled_lines.key?(line)
|
@@ -217,7 +219,7 @@ module RuboCop
|
|
217
219
|
!relevant_file?(file)
|
218
220
|
end
|
219
221
|
|
220
|
-
# This method should be
|
222
|
+
# This method should be overridden when a cop's behavior depends
|
221
223
|
# on state that lives outside of these locations:
|
222
224
|
#
|
223
225
|
# (1) the file under inspection
|
@@ -98,7 +98,7 @@ module RuboCop
|
|
98
98
|
end
|
99
99
|
|
100
100
|
def_node_search :dependency_declarations, <<~PATTERN
|
101
|
-
(send (lvar _) {:add_dependency :add_runtime_dependency :add_development_dependency} ...)
|
101
|
+
(send (lvar _) {:add_dependency :add_runtime_dependency :add_development_dependency} (str _) ...)
|
102
102
|
PATTERN
|
103
103
|
end
|
104
104
|
end
|
@@ -104,10 +104,9 @@ module RuboCop
|
|
104
104
|
end
|
105
105
|
SPEC
|
106
106
|
|
107
|
-
CONFIGURATION_ADDED_MESSAGE =
|
108
|
-
[modify] A configuration for the cop is added into
|
109
|
-
|
110
|
-
MESSAGE
|
107
|
+
CONFIGURATION_ADDED_MESSAGE =
|
108
|
+
'[modify] A configuration for the cop is added into ' \
|
109
|
+
'%<configuration_file_path>s.'
|
111
110
|
|
112
111
|
def initialize(name, github_user, output: $stdout)
|
113
112
|
@badge = Badge.parse(name)
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
module RuboCop
|
4
4
|
module Cop
|
5
|
-
# rubocop:disable
|
5
|
+
# rubocop:disable Layout/LineLength
|
6
6
|
module Layout
|
7
7
|
# This cop checks the indentation of the first argument in a method call.
|
8
8
|
# Arguments after the first one are checked by Layout/ArgumentAlignment,
|
@@ -143,7 +143,7 @@ module RuboCop
|
|
143
143
|
# second_param
|
144
144
|
#
|
145
145
|
class FirstArgumentIndentation < Cop
|
146
|
-
# rubocop:enable
|
146
|
+
# rubocop:enable Layout/LineLength
|
147
147
|
include Alignment
|
148
148
|
include ConfigurableEnforcedStyle
|
149
149
|
include RangeHelp
|
@@ -179,8 +179,12 @@ module RuboCop
|
|
179
179
|
include HashAlignmentStyles
|
180
180
|
include RangeHelp
|
181
181
|
|
182
|
-
|
183
|
-
|
182
|
+
MESSAGES = { KeyAlignment => 'Align the keys of a hash literal if ' \
|
183
|
+
'they span more than one line.',
|
184
|
+
SeparatorAlignment => 'Align the separators of a hash ' \
|
185
|
+
'literal if they span more than one line.',
|
186
|
+
TableAlignment => 'Align the keys and values of a hash ' \
|
187
|
+
'literal if they span more than one line.' }.freeze
|
184
188
|
|
185
189
|
def on_send(node)
|
186
190
|
return if double_splat?(node)
|
@@ -249,9 +253,9 @@ module RuboCop
|
|
249
253
|
end
|
250
254
|
|
251
255
|
def add_offences
|
252
|
-
|
256
|
+
format, offences = offences_by.min_by { |_, v| v.length }
|
253
257
|
(offences || []).each do |offence|
|
254
|
-
add_offense
|
258
|
+
add_offense(offence, message: MESSAGES[format])
|
255
259
|
end
|
256
260
|
end
|
257
261
|
|