rubocop 0.75.1 → 0.80.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.
Files changed (199) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE.txt +1 -1
  3. data/README.md +4 -4
  4. data/config/default.yml +374 -335
  5. data/lib/rubocop.rb +53 -32
  6. data/lib/rubocop/ast/builder.rb +43 -41
  7. data/lib/rubocop/ast/node.rb +5 -13
  8. data/lib/rubocop/ast/node/block_node.rb +2 -0
  9. data/lib/rubocop/ast/node/def_node.rb +11 -0
  10. data/lib/rubocop/ast/node/forward_args_node.rb +18 -0
  11. data/lib/rubocop/ast/node/regexp_node.rb +2 -4
  12. data/lib/rubocop/ast/node/return_node.rb +24 -0
  13. data/lib/rubocop/ast/traversal.rb +20 -3
  14. data/lib/rubocop/cli.rb +11 -227
  15. data/lib/rubocop/cli/command.rb +21 -0
  16. data/lib/rubocop/cli/command/auto_genenerate_config.rb +105 -0
  17. data/lib/rubocop/cli/command/base.rb +33 -0
  18. data/lib/rubocop/cli/command/execute_runner.rb +76 -0
  19. data/lib/rubocop/cli/command/init_dotfile.rb +45 -0
  20. data/lib/rubocop/cli/command/show_cops.rb +80 -0
  21. data/lib/rubocop/cli/command/version.rb +17 -0
  22. data/lib/rubocop/cli/environment.rb +21 -0
  23. data/lib/rubocop/comment_config.rb +8 -3
  24. data/lib/rubocop/config.rb +8 -1
  25. data/lib/rubocop/config_loader.rb +20 -20
  26. data/lib/rubocop/config_loader_resolver.rb +2 -1
  27. data/lib/rubocop/config_obsoletion.rb +73 -10
  28. data/lib/rubocop/config_validator.rb +77 -110
  29. data/lib/rubocop/cop/autocorrect_logic.rb +7 -4
  30. data/lib/rubocop/cop/bundler/gem_comment.rb +4 -4
  31. data/lib/rubocop/cop/bundler/insecure_protocol_source.rb +2 -2
  32. data/lib/rubocop/cop/commissioner.rb +15 -7
  33. data/lib/rubocop/cop/cop.rb +31 -6
  34. data/lib/rubocop/cop/corrector.rb +8 -7
  35. data/lib/rubocop/cop/correctors/space_corrector.rb +1 -2
  36. data/lib/rubocop/cop/gemspec/ordered_dependencies.rb +1 -1
  37. data/lib/rubocop/cop/generator.rb +3 -4
  38. data/lib/rubocop/cop/generator/configuration_injector.rb +2 -2
  39. data/lib/rubocop/cop/internal_affairs.rb +1 -0
  40. data/lib/rubocop/cop/internal_affairs/method_name_equal.rb +59 -0
  41. data/lib/rubocop/cop/layout/{align_arguments.rb → argument_alignment.rb} +1 -1
  42. data/lib/rubocop/cop/layout/{align_array.rb → array_alignment.rb} +1 -1
  43. data/lib/rubocop/cop/layout/{indent_assignment.rb → assignment_indentation.rb} +1 -1
  44. data/lib/rubocop/cop/layout/comment_indentation.rb +10 -13
  45. data/lib/rubocop/cop/layout/empty_comment.rb +7 -16
  46. data/lib/rubocop/cop/layout/empty_line_between_defs.rb +2 -1
  47. data/lib/rubocop/cop/layout/end_of_line.rb +8 -3
  48. data/lib/rubocop/cop/layout/extra_spacing.rb +1 -1
  49. data/lib/rubocop/cop/layout/{indent_first_argument.rb → first_argument_indentation.rb} +14 -12
  50. data/lib/rubocop/cop/layout/{indent_first_array_element.rb → first_array_element_indentation.rb} +4 -4
  51. data/lib/rubocop/cop/layout/{indent_first_hash_element.rb → first_hash_element_indentation.rb} +4 -4
  52. data/lib/rubocop/cop/layout/{indent_first_parameter.rb → first_parameter_indentation.rb} +3 -3
  53. data/lib/rubocop/cop/layout/{align_hash.rb → hash_alignment.rb} +16 -8
  54. data/lib/rubocop/cop/layout/{indent_heredoc.rb → heredoc_indentation.rb} +5 -5
  55. data/lib/rubocop/cop/layout/leading_comment_space.rb +33 -2
  56. data/lib/rubocop/cop/layout/{leading_blank_lines.rb → leading_empty_lines.rb} +1 -1
  57. data/lib/rubocop/cop/{metrics → layout}/line_length.rb +68 -112
  58. data/lib/rubocop/cop/layout/multiline_assignment_layout.rb +1 -1
  59. data/lib/rubocop/cop/layout/multiline_block_layout.rb +14 -5
  60. data/lib/rubocop/cop/layout/multiline_hash_brace_layout.rb +0 -4
  61. data/lib/rubocop/cop/layout/multiline_method_argument_line_breaks.rb +1 -1
  62. data/lib/rubocop/cop/layout/{align_parameters.rb → parameter_alignment.rb} +1 -1
  63. data/lib/rubocop/cop/layout/rescue_ensure_alignment.rb +2 -0
  64. data/lib/rubocop/cop/layout/space_around_keyword.rb +12 -0
  65. data/lib/rubocop/cop/layout/space_around_operators.rb +50 -7
  66. data/lib/rubocop/cop/layout/space_before_block_braces.rb +17 -0
  67. data/lib/rubocop/cop/layout/space_before_first_arg.rb +8 -0
  68. data/lib/rubocop/cop/layout/space_in_lambda_literal.rb +9 -7
  69. data/lib/rubocop/cop/layout/space_inside_array_literal_brackets.rb +7 -4
  70. data/lib/rubocop/cop/layout/space_inside_hash_literal_braces.rb +2 -9
  71. data/lib/rubocop/cop/layout/space_inside_parens.rb +6 -6
  72. data/lib/rubocop/cop/layout/{trailing_blank_lines.rb → trailing_empty_lines.rb} +1 -1
  73. data/lib/rubocop/cop/layout/trailing_whitespace.rb +18 -2
  74. data/lib/rubocop/cop/lint/debugger.rb +1 -1
  75. data/lib/rubocop/cop/lint/disjunctive_assignment_in_constructor.rb +1 -1
  76. data/lib/rubocop/cop/lint/{duplicated_key.rb → duplicate_hash_key.rb} +1 -1
  77. data/lib/rubocop/cop/lint/each_with_object_argument.rb +1 -1
  78. data/lib/rubocop/cop/lint/erb_new_arguments.rb +9 -8
  79. data/lib/rubocop/cop/lint/ineffective_access_modifier.rb +1 -1
  80. data/lib/rubocop/cop/lint/missing_cop_enable_directive.rb +2 -2
  81. data/lib/rubocop/cop/lint/{multiple_compare.rb → multiple_comparison.rb} +1 -1
  82. data/lib/rubocop/cop/lint/non_deterministic_require_order.rb +89 -0
  83. data/lib/rubocop/cop/lint/{unneeded_cop_disable_directive.rb → redundant_cop_disable_directive.rb} +26 -26
  84. data/lib/rubocop/cop/lint/{unneeded_cop_enable_directive.rb → redundant_cop_enable_directive.rb} +18 -15
  85. data/lib/rubocop/cop/lint/{unneeded_require_statement.rb → redundant_require_statement.rb} +1 -1
  86. data/lib/rubocop/cop/lint/{unneeded_splat_expansion.rb → redundant_splat_expansion.rb} +6 -6
  87. data/lib/rubocop/cop/lint/{string_conversion_in_interpolation.rb → redundant_string_coercion.rb} +1 -1
  88. data/lib/rubocop/cop/lint/redundant_with_index.rb +2 -2
  89. data/lib/rubocop/cop/lint/redundant_with_object.rb +2 -2
  90. data/lib/rubocop/cop/lint/safe_navigation_chain.rb +5 -6
  91. data/lib/rubocop/cop/lint/{handle_exceptions.rb → suppressed_exception.rb} +1 -1
  92. data/lib/rubocop/cop/lint/useless_access_modifier.rb +57 -23
  93. data/lib/rubocop/cop/lint/useless_setter_call.rb +5 -1
  94. data/lib/rubocop/cop/lint/void.rb +4 -4
  95. data/lib/rubocop/cop/metrics/abc_size.rb +1 -1
  96. data/lib/rubocop/cop/metrics/method_length.rb +1 -1
  97. data/lib/rubocop/cop/metrics/utils/abc_size_calculator.rb +23 -6
  98. data/lib/rubocop/cop/migration/department_name.rb +30 -2
  99. data/lib/rubocop/cop/mixin/alignment.rb +1 -1
  100. data/lib/rubocop/cop/mixin/configurable_enforced_style.rb +4 -0
  101. data/lib/rubocop/cop/mixin/frozen_string_literal.rb +7 -7
  102. data/lib/rubocop/cop/mixin/{hash_alignment.rb → hash_alignment_styles.rb} +1 -1
  103. data/lib/rubocop/cop/mixin/hash_transform_method.rb +172 -0
  104. data/lib/rubocop/cop/mixin/line_length_help.rb +88 -0
  105. data/lib/rubocop/cop/mixin/method_complexity.rb +2 -1
  106. data/lib/rubocop/cop/mixin/nil_methods.rb +4 -4
  107. data/lib/rubocop/cop/mixin/rational_literal.rb +18 -0
  108. data/lib/rubocop/cop/mixin/statement_modifier.rb +7 -4
  109. data/lib/rubocop/cop/mixin/trailing_comma.rb +16 -18
  110. data/lib/rubocop/cop/naming/{uncommunicative_block_param_name.rb → block_parameter_name.rb} +3 -3
  111. data/lib/rubocop/cop/naming/file_name.rb +12 -5
  112. data/lib/rubocop/cop/naming/heredoc_delimiter_naming.rb +5 -5
  113. data/lib/rubocop/cop/naming/memoized_instance_variable_name.rb +1 -1
  114. data/lib/rubocop/cop/naming/{uncommunicative_method_param_name.rb → method_parameter_name.rb} +4 -4
  115. data/lib/rubocop/cop/naming/predicate_name.rb +6 -6
  116. data/lib/rubocop/cop/offense.rb +11 -0
  117. data/lib/rubocop/cop/registry.rb +8 -3
  118. data/lib/rubocop/cop/style/alias.rb +1 -1
  119. data/lib/rubocop/cop/style/array_join.rb +1 -1
  120. data/lib/rubocop/cop/style/attr.rb +10 -2
  121. data/lib/rubocop/cop/style/block_delimiters.rb +60 -1
  122. data/lib/rubocop/cop/style/comment_annotation.rb +5 -5
  123. data/lib/rubocop/cop/style/conditional_assignment.rb +2 -2
  124. data/lib/rubocop/cop/style/copyright.rb +11 -7
  125. data/lib/rubocop/cop/style/double_cop_disable_directive.rb +2 -2
  126. data/lib/rubocop/cop/style/empty_case_condition.rb +2 -2
  127. data/lib/rubocop/cop/style/empty_literal.rb +2 -2
  128. data/lib/rubocop/cop/style/empty_method.rb +5 -5
  129. data/lib/rubocop/cop/style/eval_with_location.rb +1 -1
  130. data/lib/rubocop/cop/style/even_odd.rb +1 -1
  131. data/lib/rubocop/cop/style/format_string.rb +10 -7
  132. data/lib/rubocop/cop/style/format_string_token.rb +2 -0
  133. data/lib/rubocop/cop/style/frozen_string_literal_comment.rb +99 -11
  134. data/lib/rubocop/cop/style/guard_clause.rb +3 -2
  135. data/lib/rubocop/cop/style/hash_each_methods.rb +87 -0
  136. data/lib/rubocop/cop/style/hash_syntax.rb +2 -2
  137. data/lib/rubocop/cop/style/hash_transform_keys.rb +79 -0
  138. data/lib/rubocop/cop/style/hash_transform_values.rb +79 -0
  139. data/lib/rubocop/cop/style/if_unless_modifier.rb +45 -3
  140. data/lib/rubocop/cop/style/infinite_loop.rb +5 -4
  141. data/lib/rubocop/cop/style/inverse_methods.rb +19 -13
  142. data/lib/rubocop/cop/style/ip_addresses.rb +4 -4
  143. data/lib/rubocop/cop/style/line_end_concatenation.rb +14 -10
  144. data/lib/rubocop/cop/style/method_call_with_args_parentheses.rb +7 -205
  145. data/lib/rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses.rb +169 -0
  146. data/lib/rubocop/cop/style/method_call_with_args_parentheses/require_parentheses.rb +54 -0
  147. data/lib/rubocop/cop/style/method_def_parentheses.rb +17 -9
  148. data/lib/rubocop/cop/style/mixin_grouping.rb +1 -1
  149. data/lib/rubocop/cop/style/multiline_method_signature.rb +1 -1
  150. data/lib/rubocop/cop/style/multiline_when_then.rb +6 -2
  151. data/lib/rubocop/cop/style/nested_modifier.rb +4 -2
  152. data/lib/rubocop/cop/style/nested_parenthesized_calls.rb +5 -5
  153. data/lib/rubocop/cop/style/next.rb +5 -5
  154. data/lib/rubocop/cop/style/non_nil_check.rb +21 -9
  155. data/lib/rubocop/cop/style/numeric_literals.rb +7 -3
  156. data/lib/rubocop/cop/style/numeric_predicate.rb +4 -3
  157. data/lib/rubocop/cop/style/option_hash.rb +3 -3
  158. data/lib/rubocop/cop/style/or_assignment.rb +3 -2
  159. data/lib/rubocop/cop/style/percent_literal_delimiters.rb +7 -7
  160. data/lib/rubocop/cop/style/{unneeded_capital_w.rb → redundant_capital_w.rb} +1 -1
  161. data/lib/rubocop/cop/style/{unneeded_condition.rb → redundant_condition.rb} +3 -3
  162. data/lib/rubocop/cop/style/{unneeded_interpolation.rb → redundant_interpolation.rb} +1 -1
  163. data/lib/rubocop/cop/style/redundant_parentheses.rb +3 -3
  164. data/lib/rubocop/cop/style/{unneeded_percent_q.rb → redundant_percent_q.rb} +1 -1
  165. data/lib/rubocop/cop/style/redundant_return.rb +27 -29
  166. data/lib/rubocop/cop/style/{unneeded_sort.rb → redundant_sort.rb} +5 -5
  167. data/lib/rubocop/cop/style/safe_navigation.rb +13 -10
  168. data/lib/rubocop/cop/style/semicolon.rb +2 -2
  169. data/lib/rubocop/cop/style/special_global_vars.rb +5 -7
  170. data/lib/rubocop/cop/style/symbol_array.rb +2 -2
  171. data/lib/rubocop/cop/style/ternary_parentheses.rb +1 -1
  172. data/lib/rubocop/cop/style/trailing_comma_in_arguments.rb +0 -22
  173. data/lib/rubocop/cop/style/trailing_underscore_variable.rb +7 -1
  174. data/lib/rubocop/cop/style/trivial_accessors.rb +5 -5
  175. data/lib/rubocop/cop/style/while_until_modifier.rb +1 -1
  176. data/lib/rubocop/cop/style/yoda_condition.rb +16 -1
  177. data/lib/rubocop/cop/team.rb +5 -0
  178. data/lib/rubocop/cop/util.rb +1 -1
  179. data/lib/rubocop/cop/utils/format_string.rb +10 -18
  180. data/lib/rubocop/cop/variable_force.rb +11 -6
  181. data/lib/rubocop/formatter/base_formatter.rb +2 -2
  182. data/lib/rubocop/formatter/clang_style_formatter.rb +1 -3
  183. data/lib/rubocop/formatter/formatter_set.rb +1 -0
  184. data/lib/rubocop/formatter/json_formatter.rb +6 -5
  185. data/lib/rubocop/formatter/junit_formatter.rb +63 -0
  186. data/lib/rubocop/formatter/tap_formatter.rb +1 -3
  187. data/lib/rubocop/node_pattern.rb +100 -12
  188. data/lib/rubocop/options.rb +17 -11
  189. data/lib/rubocop/processed_source.rb +1 -1
  190. data/lib/rubocop/rake_task.rb +1 -0
  191. data/lib/rubocop/result_cache.rb +24 -8
  192. data/lib/rubocop/rspec/shared_contexts.rb +5 -0
  193. data/lib/rubocop/runner.rb +50 -29
  194. data/lib/rubocop/target_finder.rb +12 -6
  195. data/lib/rubocop/target_ruby.rb +151 -0
  196. data/lib/rubocop/version.rb +1 -1
  197. metadata +69 -35
  198. data/lib/rubocop/cop/mixin/safe_mode.rb +0 -24
  199. data/lib/rubocop/cop/style/braces_around_hash_parameters.rb +0 -209
@@ -1,24 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module RuboCop
4
- module Cop
5
- # Common functionality for Rails safe mode.
6
- #
7
- # This module can be removed from RuboCop 0.76.
8
- module SafeMode
9
- private
10
-
11
- def rails_safe_mode?
12
- safe_mode? || rails?
13
- end
14
-
15
- def safe_mode?
16
- cop_config['SafeMode']
17
- end
18
-
19
- def rails?
20
- config['Rails']&.fetch('Enabled')
21
- end
22
- end
23
- end
24
- end
@@ -1,209 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module RuboCop
4
- module Cop
5
- module Style
6
- # This cop checks for braces around the last parameter in a method call
7
- # if the last parameter is a hash.
8
- # It supports `braces`, `no_braces` and `context_dependent` styles.
9
- #
10
- # @example EnforcedStyle: braces
11
- # # The `braces` style enforces braces around all method
12
- # # parameters that are hashes.
13
- #
14
- # # bad
15
- # some_method(x, y, a: 1, b: 2)
16
- #
17
- # # good
18
- # some_method(x, y, {a: 1, b: 2})
19
- #
20
- # @example EnforcedStyle: no_braces (default)
21
- # # The `no_braces` style checks that the last parameter doesn't
22
- # # have braces around it.
23
- #
24
- # # bad
25
- # some_method(x, y, {a: 1, b: 2})
26
- #
27
- # # good
28
- # some_method(x, y, a: 1, b: 2)
29
- #
30
- # @example EnforcedStyle: context_dependent
31
- # # The `context_dependent` style checks that the last parameter
32
- # # doesn't have braces around it, but requires braces if the
33
- # # second to last parameter is also a hash literal.
34
- #
35
- # # bad
36
- # some_method(x, y, {a: 1, b: 2})
37
- # some_method(x, y, {a: 1, b: 2}, a: 1, b: 2)
38
- #
39
- # # good
40
- # some_method(x, y, a: 1, b: 2)
41
- # some_method(x, y, {a: 1, b: 2}, {a: 1, b: 2})
42
- class BracesAroundHashParameters < Cop
43
- include ConfigurableEnforcedStyle
44
- include RangeHelp
45
-
46
- MSG = '%<type>s curly braces around a hash parameter.'
47
-
48
- def on_send(node)
49
- return if node.assignment_method? || node.operator_method?
50
-
51
- return unless node.arguments? && node.last_argument.hash_type? &&
52
- !node.last_argument.empty?
53
-
54
- check(node.last_argument, node.arguments)
55
- end
56
- alias on_csend on_send
57
-
58
- def autocorrect(send_node)
59
- hash_node = send_node.last_argument
60
-
61
- lambda do |corrector|
62
- if hash_node.braces?
63
- remove_braces_with_whitespace(corrector,
64
- hash_node,
65
- extra_space(hash_node))
66
- else
67
- add_braces(corrector, hash_node)
68
- end
69
- end
70
- end
71
-
72
- private
73
-
74
- def check(arg, args)
75
- case style
76
- when :braces
77
- check_braces(arg)
78
- when :no_braces
79
- check_no_braces(arg)
80
- when :context_dependent
81
- check_context_dependent(arg, args)
82
- end
83
- end
84
-
85
- def check_braces(arg)
86
- add_arg_offense(arg, :missing) unless arg.braces?
87
- end
88
-
89
- def check_no_braces(arg)
90
- return unless arg.braces? && !braces_needed_for_semantics?(arg)
91
-
92
- add_arg_offense(arg, :redundant)
93
- end
94
-
95
- def check_context_dependent(arg, args)
96
- braces_around_second_from_end = args.size > 1 && args[-2].hash_type?
97
-
98
- if arg.braces?
99
- unless braces_around_second_from_end ||
100
- braces_needed_for_semantics?(arg)
101
- add_arg_offense(arg, :redundant)
102
- end
103
- elsif braces_around_second_from_end
104
- add_arg_offense(arg, :missing)
105
- end
106
- end
107
-
108
- # Returns true if there's block inside the braces of the given hash arg
109
- # and that block uses do..end. The reason for wanting to check this is
110
- # that the do..end could bind to a different method invocation if the
111
- # hash braces were removed.
112
- def braces_needed_for_semantics?(arg)
113
- arg.each_pair do |_key, value|
114
- return true if value.block_type? && !value.braces?
115
- end
116
- false
117
- end
118
-
119
- def add_arg_offense(arg, type)
120
- add_offense(arg.parent, location: arg.source_range,
121
- message: format(MSG,
122
- type: type.to_s.capitalize))
123
- end
124
-
125
- def extra_space(hash_node)
126
- {
127
- newlines: extra_left_space?(hash_node) &&
128
- extra_right_space?(hash_node),
129
- left: extra_left_space?(hash_node),
130
- right: extra_right_space?(hash_node)
131
- }
132
- end
133
-
134
- def extra_left_space?(hash_node)
135
- @extra_left_space ||= begin
136
- top_line = hash_node.source_range.source_line
137
- top_line.delete(' ') == '{'
138
- end
139
- end
140
-
141
- def extra_right_space?(hash_node)
142
- @extra_right_space ||= begin
143
- bottom_line_number = hash_node.source_range.last_line
144
- bottom_line = processed_source.lines[bottom_line_number - 1]
145
- bottom_line.delete(' ') == '}'
146
- end
147
- end
148
-
149
- def remove_braces_with_whitespace(corrector, node, space)
150
- if node.multiline?
151
- remove_braces_with_range(corrector,
152
- left_whole_line_range(node.loc.begin),
153
- right_whole_line_range(node.loc.end))
154
- else
155
- right_brace_and_space = right_brace_and_space(node.loc.end, space)
156
- left_brace_and_space = left_brace_and_space(node.loc.begin, space)
157
- remove_braces_with_range(corrector,
158
- left_brace_and_space,
159
- right_brace_and_space)
160
- end
161
- end
162
-
163
- def remove_braces_with_range(corrector, left_range, right_range)
164
- corrector.remove(left_range)
165
- corrector.remove(right_range)
166
- end
167
-
168
- def left_whole_line_range(loc_begin)
169
- if range_by_whole_lines(loc_begin).source.strip == '{'
170
- range_by_whole_lines(loc_begin, include_final_newline: true)
171
- else
172
- loc_begin
173
- end
174
- end
175
-
176
- def right_whole_line_range(loc_end)
177
- if range_by_whole_lines(loc_end).source.strip =~ /\A}\s*,?\z/
178
- range_by_whole_lines(loc_end, include_final_newline: true)
179
- else
180
- loc_end
181
- end
182
- end
183
-
184
- def left_brace_and_space(loc_begin, space)
185
- range_with_surrounding_space(range: loc_begin,
186
- side: :right,
187
- newlines: space[:newlines],
188
- whitespace: space[:left])
189
- end
190
-
191
- def right_brace_and_space(loc_end, space)
192
- brace_and_space =
193
- range_with_surrounding_space(
194
- range: loc_end,
195
- side: :left,
196
- newlines: space[:newlines],
197
- whitespace: space[:right]
198
- )
199
- range_with_surrounding_comma(brace_and_space, :left)
200
- end
201
-
202
- def add_braces(corrector, node)
203
- corrector.insert_before(node.source_range, '{')
204
- corrector.insert_after(node.source_range, '}')
205
- end
206
- end
207
- end
208
- end
209
- end