rubocop 0.75.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 +2 -2
- data/config/default.yml +341 -316
- data/lib/rubocop.rb +48 -31
- data/lib/rubocop/ast/builder.rb +43 -41
- data/lib/rubocop/ast/node.rb +5 -1
- data/lib/rubocop/ast/node/block_node.rb +2 -0
- 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/node/return_node.rb +24 -0
- data/lib/rubocop/ast/traversal.rb +11 -3
- data/lib/rubocop/cli.rb +11 -227
- data/lib/rubocop/cli/command.rb +21 -0
- data/lib/rubocop/cli/command/auto_genenerate_config.rb +105 -0
- data/lib/rubocop/cli/command/base.rb +33 -0
- data/lib/rubocop/cli/command/execute_runner.rb +76 -0
- data/lib/rubocop/cli/command/init_dotfile.rb +45 -0
- data/lib/rubocop/cli/command/show_cops.rb +80 -0
- data/lib/rubocop/cli/command/version.rb +17 -0
- data/lib/rubocop/cli/environment.rb +21 -0
- data/lib/rubocop/comment_config.rb +2 -2
- data/lib/rubocop/config.rb +8 -1
- data/lib/rubocop/config_loader.rb +20 -20
- data/lib/rubocop/config_loader_resolver.rb +2 -1
- data/lib/rubocop/config_obsoletion.rb +73 -11
- data/lib/rubocop/config_validator.rb +77 -110
- data/lib/rubocop/cop/autocorrect_logic.rb +7 -4
- data/lib/rubocop/cop/bundler/gem_comment.rb +4 -4
- data/lib/rubocop/cop/bundler/insecure_protocol_source.rb +2 -2
- data/lib/rubocop/cop/commissioner.rb +15 -7
- data/lib/rubocop/cop/cop.rb +31 -6
- data/lib/rubocop/cop/corrector.rb +8 -7
- data/lib/rubocop/cop/correctors/percent_literal_corrector.rb +1 -1
- data/lib/rubocop/cop/correctors/space_corrector.rb +1 -2
- 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 +2 -2
- data/lib/rubocop/cop/internal_affairs.rb +1 -0
- data/lib/rubocop/cop/internal_affairs/method_name_equal.rb +59 -0
- data/lib/rubocop/cop/layout/{align_arguments.rb → argument_alignment.rb} +1 -1
- data/lib/rubocop/cop/layout/{align_array.rb → array_alignment.rb} +1 -1
- data/lib/rubocop/cop/layout/{indent_assignment.rb → assignment_indentation.rb} +3 -2
- data/lib/rubocop/cop/layout/comment_indentation.rb +10 -13
- data/lib/rubocop/cop/layout/empty_comment.rb +7 -16
- data/lib/rubocop/cop/layout/empty_line_after_guard_clause.rb +22 -7
- data/lib/rubocop/cop/layout/empty_line_after_magic_comment.rb +2 -2
- data/lib/rubocop/cop/layout/empty_lines_around_class_body.rb +2 -2
- data/lib/rubocop/cop/layout/end_of_line.rb +8 -3
- data/lib/rubocop/cop/layout/extra_spacing.rb +1 -1
- data/lib/rubocop/cop/layout/{indent_first_argument.rb → first_argument_indentation.rb} +14 -12
- data/lib/rubocop/cop/layout/{indent_first_array_element.rb → first_array_element_indentation.rb} +4 -4
- data/lib/rubocop/cop/layout/{indent_first_hash_element.rb → first_hash_element_indentation.rb} +4 -4
- data/lib/rubocop/cop/layout/{indent_first_parameter.rb → first_parameter_indentation.rb} +3 -3
- data/lib/rubocop/cop/layout/{align_hash.rb → hash_alignment.rb} +16 -8
- data/lib/rubocop/cop/layout/{indent_heredoc.rb → heredoc_indentation.rb} +5 -5
- data/lib/rubocop/cop/layout/{leading_blank_lines.rb → leading_empty_lines.rb} +1 -1
- data/lib/rubocop/cop/{metrics → layout}/line_length.rb +41 -114
- data/lib/rubocop/cop/layout/multiline_assignment_layout.rb +1 -1
- data/lib/rubocop/cop/layout/multiline_block_layout.rb +14 -5
- data/lib/rubocop/cop/layout/multiline_method_argument_line_breaks.rb +1 -1
- data/lib/rubocop/cop/layout/{align_parameters.rb → parameter_alignment.rb} +1 -1
- data/lib/rubocop/cop/layout/rescue_ensure_alignment.rb +2 -0
- data/lib/rubocop/cop/layout/space_around_keyword.rb +12 -0
- data/lib/rubocop/cop/layout/space_around_operators.rb +32 -7
- data/lib/rubocop/cop/layout/space_before_block_braces.rb +17 -0
- data/lib/rubocop/cop/layout/space_in_lambda_literal.rb +9 -7
- data/lib/rubocop/cop/layout/space_inside_array_literal_brackets.rb +7 -4
- data/lib/rubocop/cop/layout/space_inside_parens.rb +6 -6
- data/lib/rubocop/cop/layout/{trailing_blank_lines.rb → trailing_empty_lines.rb} +1 -1
- data/lib/rubocop/cop/layout/trailing_whitespace.rb +18 -2
- data/lib/rubocop/cop/lint/debugger.rb +2 -2
- data/lib/rubocop/cop/lint/disjunctive_assignment_in_constructor.rb +1 -1
- data/lib/rubocop/cop/lint/{duplicated_key.rb → duplicate_hash_key.rb} +1 -1
- data/lib/rubocop/cop/lint/each_with_object_argument.rb +1 -1
- data/lib/rubocop/cop/lint/erb_new_arguments.rb +9 -8
- data/lib/rubocop/cop/lint/ineffective_access_modifier.rb +1 -1
- data/lib/rubocop/cop/lint/missing_cop_enable_directive.rb +2 -2
- data/lib/rubocop/cop/lint/{multiple_compare.rb → multiple_comparison.rb} +1 -1
- data/lib/rubocop/cop/lint/non_deterministic_require_order.rb +89 -0
- data/lib/rubocop/cop/lint/{unneeded_cop_disable_directive.rb → redundant_cop_disable_directive.rb} +26 -26
- data/lib/rubocop/cop/lint/{unneeded_cop_enable_directive.rb → redundant_cop_enable_directive.rb} +10 -12
- data/lib/rubocop/cop/lint/{unneeded_require_statement.rb → redundant_require_statement.rb} +1 -1
- data/lib/rubocop/cop/lint/{unneeded_splat_expansion.rb → redundant_splat_expansion.rb} +6 -6
- data/lib/rubocop/cop/lint/{string_conversion_in_interpolation.rb → redundant_string_coercion.rb} +1 -1
- data/lib/rubocop/cop/lint/redundant_with_index.rb +2 -2
- data/lib/rubocop/cop/lint/redundant_with_object.rb +2 -2
- data/lib/rubocop/cop/lint/safe_navigation_chain.rb +5 -6
- data/lib/rubocop/cop/lint/{handle_exceptions.rb → suppressed_exception.rb} +1 -1
- data/lib/rubocop/cop/lint/unused_block_argument.rb +22 -6
- data/lib/rubocop/cop/lint/unused_method_argument.rb +23 -5
- data/lib/rubocop/cop/lint/useless_access_modifier.rb +57 -23
- data/lib/rubocop/cop/lint/useless_setter_call.rb +1 -1
- data/lib/rubocop/cop/lint/void.rb +7 -26
- data/lib/rubocop/cop/metrics/abc_size.rb +1 -1
- data/lib/rubocop/cop/metrics/method_length.rb +1 -1
- data/lib/rubocop/cop/metrics/utils/abc_size_calculator.rb +23 -6
- 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/{hash_alignment.rb → hash_alignment_styles.rb} +1 -1
- data/lib/rubocop/cop/mixin/line_length_help.rb +88 -0
- data/lib/rubocop/cop/mixin/method_complexity.rb +2 -1
- data/lib/rubocop/cop/mixin/nil_methods.rb +4 -4
- data/lib/rubocop/cop/mixin/rational_literal.rb +18 -0
- data/lib/rubocop/cop/mixin/statement_modifier.rb +7 -4
- data/lib/rubocop/cop/mixin/trailing_comma.rb +14 -9
- data/lib/rubocop/cop/naming/{uncommunicative_block_param_name.rb → block_parameter_name.rb} +3 -3
- data/lib/rubocop/cop/naming/file_name.rb +12 -5
- data/lib/rubocop/cop/naming/heredoc_delimiter_naming.rb +5 -5
- data/lib/rubocop/cop/naming/{uncommunicative_method_param_name.rb → method_parameter_name.rb} +4 -4
- data/lib/rubocop/cop/naming/predicate_name.rb +6 -6
- data/lib/rubocop/cop/offense.rb +11 -0
- data/lib/rubocop/cop/registry.rb +8 -3
- data/lib/rubocop/cop/style/alias.rb +1 -1
- data/lib/rubocop/cop/style/array_join.rb +1 -1
- data/lib/rubocop/cop/style/attr.rb +10 -2
- data/lib/rubocop/cop/style/braces_around_hash_parameters.rb +6 -6
- data/lib/rubocop/cop/style/comment_annotation.rb +5 -5
- data/lib/rubocop/cop/style/conditional_assignment.rb +2 -2
- data/lib/rubocop/cop/style/copyright.rb +11 -7
- data/lib/rubocop/cop/style/documentation_method.rb +44 -0
- data/lib/rubocop/cop/style/double_cop_disable_directive.rb +2 -2
- data/lib/rubocop/cop/style/empty_case_condition.rb +2 -2
- data/lib/rubocop/cop/style/empty_literal.rb +2 -2
- data/lib/rubocop/cop/style/empty_method.rb +5 -5
- data/lib/rubocop/cop/style/eval_with_location.rb +1 -1
- data/lib/rubocop/cop/style/even_odd.rb +1 -1
- data/lib/rubocop/cop/style/expand_path_arguments.rb +1 -1
- data/lib/rubocop/cop/style/format_string.rb +10 -7
- data/lib/rubocop/cop/style/format_string_token.rb +15 -34
- data/lib/rubocop/cop/style/frozen_string_literal_comment.rb +10 -0
- data/lib/rubocop/cop/style/guard_clause.rb +3 -2
- data/lib/rubocop/cop/style/hash_syntax.rb +2 -2
- data/lib/rubocop/cop/style/if_unless_modifier.rb +45 -3
- data/lib/rubocop/cop/style/infinite_loop.rb +5 -4
- data/lib/rubocop/cop/style/inverse_methods.rb +19 -13
- data/lib/rubocop/cop/style/ip_addresses.rb +4 -4
- data/lib/rubocop/cop/style/line_end_concatenation.rb +14 -10
- data/lib/rubocop/cop/style/method_call_with_args_parentheses.rb +24 -227
- 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/method_def_parentheses.rb +17 -9
- data/lib/rubocop/cop/style/mixin_grouping.rb +1 -1
- data/lib/rubocop/cop/style/multiline_method_signature.rb +1 -1
- data/lib/rubocop/cop/style/multiline_when_then.rb +6 -2
- data/lib/rubocop/cop/style/nested_modifier.rb +4 -2
- data/lib/rubocop/cop/style/nested_parenthesized_calls.rb +5 -5
- data/lib/rubocop/cop/style/next.rb +5 -5
- data/lib/rubocop/cop/style/non_nil_check.rb +21 -9
- data/lib/rubocop/cop/style/numeric_literals.rb +7 -3
- data/lib/rubocop/cop/style/numeric_predicate.rb +4 -3
- data/lib/rubocop/cop/style/option_hash.rb +3 -3
- data/lib/rubocop/cop/style/percent_literal_delimiters.rb +7 -7
- data/lib/rubocop/cop/style/{unneeded_capital_w.rb → redundant_capital_w.rb} +1 -1
- data/lib/rubocop/cop/style/{unneeded_condition.rb → redundant_condition.rb} +3 -3
- data/lib/rubocop/cop/style/{unneeded_interpolation.rb → redundant_interpolation.rb} +1 -1
- data/lib/rubocop/cop/style/redundant_parentheses.rb +3 -3
- data/lib/rubocop/cop/style/{unneeded_percent_q.rb → redundant_percent_q.rb} +1 -1
- data/lib/rubocop/cop/style/redundant_return.rb +39 -29
- data/lib/rubocop/cop/style/{unneeded_sort.rb → redundant_sort.rb} +5 -5
- data/lib/rubocop/cop/style/safe_navigation.rb +19 -8
- data/lib/rubocop/cop/style/semicolon.rb +13 -2
- data/lib/rubocop/cop/style/special_global_vars.rb +5 -7
- data/lib/rubocop/cop/style/trailing_underscore_variable.rb +7 -1
- data/lib/rubocop/cop/style/trivial_accessors.rb +5 -5
- data/lib/rubocop/cop/style/while_until_modifier.rb +1 -1
- data/lib/rubocop/cop/style/yoda_condition.rb +16 -1
- data/lib/rubocop/cop/team.rb +5 -0
- data/lib/rubocop/cop/util.rb +1 -1
- data/lib/rubocop/cop/utils/format_string.rb +10 -18
- data/lib/rubocop/cop/variable_force.rb +7 -5
- data/lib/rubocop/formatter/base_formatter.rb +2 -2
- data/lib/rubocop/formatter/clang_style_formatter.rb +9 -6
- data/lib/rubocop/formatter/emacs_style_formatter.rb +22 -12
- data/lib/rubocop/formatter/file_list_formatter.rb +1 -1
- data/lib/rubocop/formatter/formatter_set.rb +16 -16
- data/lib/rubocop/formatter/json_formatter.rb +6 -5
- data/lib/rubocop/formatter/pacman_formatter.rb +3 -3
- data/lib/rubocop/formatter/simple_text_formatter.rb +7 -3
- data/lib/rubocop/formatter/tap_formatter.rb +9 -6
- data/lib/rubocop/node_pattern.rb +4 -2
- data/lib/rubocop/options.rb +20 -26
- data/lib/rubocop/processed_source.rb +1 -1
- data/lib/rubocop/rake_task.rb +1 -0
- data/lib/rubocop/result_cache.rb +24 -8
- data/lib/rubocop/rspec/shared_contexts.rb +5 -0
- data/lib/rubocop/runner.rb +50 -29
- data/lib/rubocop/target_finder.rb +12 -6
- data/lib/rubocop/target_ruby.rb +151 -0
- data/lib/rubocop/version.rb +1 -1
- metadata +50 -34
- data/lib/rubocop/cop/mixin/safe_mode.rb +0 -24
@@ -5,7 +5,7 @@ module RuboCop
|
|
5
5
|
module Style
|
6
6
|
# Checks for while and until statements that would fit on one line
|
7
7
|
# if written as a modifier while/until. The maximum line length is
|
8
|
-
# configured in the `
|
8
|
+
# configured in the `Layout/LineLength` cop.
|
9
9
|
#
|
10
10
|
# @example
|
11
11
|
# # bad
|
@@ -67,9 +67,16 @@ module RuboCop
|
|
67
67
|
|
68
68
|
NONCOMMUTATIVE_OPERATORS = %i[===].freeze
|
69
69
|
|
70
|
+
PROGRAM_NAMES = %i[$0 $PROGRAM_NAME].freeze
|
71
|
+
|
72
|
+
def_node_matcher :file_constant_equal_program_name?, <<~PATTERN
|
73
|
+
(send #source_file_path_constant? {:== :!=} (gvar #program_name?))
|
74
|
+
PATTERN
|
75
|
+
|
70
76
|
def on_send(node)
|
71
77
|
return unless yoda_compatible_condition?(node)
|
72
|
-
return if equality_only? && non_equality_operator?(node)
|
78
|
+
return if equality_only? && non_equality_operator?(node) ||
|
79
|
+
file_constant_equal_program_name?(node)
|
73
80
|
|
74
81
|
valid_yoda?(node) || add_offense(node)
|
75
82
|
end
|
@@ -135,6 +142,14 @@ module RuboCop
|
|
135
142
|
def noncommutative_operator?(node)
|
136
143
|
NONCOMMUTATIVE_OPERATORS.include?(node.method_name)
|
137
144
|
end
|
145
|
+
|
146
|
+
def source_file_path_constant?(node)
|
147
|
+
node.source == '__FILE__'
|
148
|
+
end
|
149
|
+
|
150
|
+
def program_name?(name)
|
151
|
+
PROGRAM_NAMES.include?(name)
|
152
|
+
end
|
138
153
|
end
|
139
154
|
end
|
140
155
|
end
|
data/lib/rubocop/cop/team.rb
CHANGED
data/lib/rubocop/cop/util.rb
CHANGED
@@ -9,7 +9,7 @@ module RuboCop
|
|
9
9
|
# Match literal regex characters, not including anchors, character
|
10
10
|
# classes, alternatives, groups, repetitions, references, etc
|
11
11
|
LITERAL_REGEX =
|
12
|
-
|
12
|
+
%r{[\w\s\-,"'!#%&<>=;:`~/]|\\[^AbBdDgGhHkpPRwWXsSzZ0-9]}.freeze
|
13
13
|
|
14
14
|
module_function
|
15
15
|
|
@@ -44,15 +44,15 @@ module RuboCop
|
|
44
44
|
attr_reader :begin_pos, :end_pos
|
45
45
|
attr_reader :flags, :width, :precision, :name, :type
|
46
46
|
|
47
|
-
def initialize(
|
48
|
-
@source =
|
49
|
-
@begin_pos =
|
50
|
-
@end_pos =
|
51
|
-
@flags =
|
52
|
-
@width =
|
53
|
-
@precision =
|
54
|
-
@name =
|
55
|
-
@type =
|
47
|
+
def initialize(match)
|
48
|
+
@source = match[0]
|
49
|
+
@begin_pos = match.begin(0)
|
50
|
+
@end_pos = match.end(0)
|
51
|
+
@flags = match[:flags].to_s + match[:more_flags].to_s
|
52
|
+
@width = match[:width]
|
53
|
+
@precision = match[:precision]
|
54
|
+
@name = match[:name]
|
55
|
+
@type = match[:type]
|
56
56
|
end
|
57
57
|
|
58
58
|
def percent?
|
@@ -109,16 +109,8 @@ module RuboCop
|
|
109
109
|
|
110
110
|
def parse
|
111
111
|
@source.to_enum(:scan, SEQUENCE).map do
|
112
|
-
match = Regexp.last_match
|
113
112
|
FormatSequence.new(
|
114
|
-
|
115
|
-
begin_pos: match.begin(0),
|
116
|
-
end_pos: match.end(0),
|
117
|
-
flags: match[:flags].to_s + match[:more_flags].to_s,
|
118
|
-
width: match[:width],
|
119
|
-
precision: match[:precision],
|
120
|
-
name: match[:name],
|
121
|
-
type: match[:type]
|
113
|
+
Regexp.last_match
|
122
114
|
)
|
123
115
|
end
|
124
116
|
end
|
@@ -284,11 +284,7 @@ module RuboCop
|
|
284
284
|
def process_scope(node)
|
285
285
|
if TWISTED_SCOPE_TYPES.include?(node.type)
|
286
286
|
# See the comment at the end of file for this behavior.
|
287
|
-
twisted_nodes
|
288
|
-
twisted_nodes << node.children[1] if node.class_type?
|
289
|
-
twisted_nodes.compact!
|
290
|
-
|
291
|
-
twisted_nodes.each do |twisted_node|
|
287
|
+
twisted_nodes(node).each do |twisted_node|
|
292
288
|
process_node(twisted_node)
|
293
289
|
scanned_nodes << twisted_node
|
294
290
|
end
|
@@ -298,6 +294,12 @@ module RuboCop
|
|
298
294
|
skip_children!
|
299
295
|
end
|
300
296
|
|
297
|
+
def twisted_nodes(node)
|
298
|
+
twisted_nodes = [node.children[0]]
|
299
|
+
twisted_nodes << node.children[1] if node.class_type?
|
300
|
+
twisted_nodes.compact
|
301
|
+
end
|
302
|
+
|
301
303
|
def process_send(node)
|
302
304
|
_receiver, method_name, args = *node
|
303
305
|
return unless method_name == :binding
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# rubocop:disable
|
3
|
+
# rubocop:disable Layout/LineLength
|
4
4
|
|
5
5
|
module RuboCop
|
6
6
|
module Formatter
|
@@ -41,7 +41,7 @@ module RuboCop
|
|
41
41
|
# * `#finished`
|
42
42
|
#
|
43
43
|
class BaseFormatter
|
44
|
-
# rubocop:enable
|
44
|
+
# rubocop:enable Layout/LineLength
|
45
45
|
|
46
46
|
# @api public
|
47
47
|
#
|
@@ -15,20 +15,23 @@ module RuboCop
|
|
15
15
|
private
|
16
16
|
|
17
17
|
def report_offense(file, offense)
|
18
|
-
output.printf(
|
19
|
-
|
20
|
-
|
18
|
+
output.printf(
|
19
|
+
"%<path>s:%<line>d:%<column>d: %<severity>s: %<message>s\n",
|
20
|
+
path: cyan(smart_path(file)),
|
21
|
+
line: offense.line,
|
22
|
+
column: offense.real_column,
|
23
|
+
severity: colored_severity_code(offense),
|
24
|
+
message: message(offense)
|
25
|
+
)
|
21
26
|
|
22
|
-
# rubocop:disable Lint/HandleExceptions
|
23
27
|
begin
|
24
28
|
return unless valid_line?(offense)
|
25
29
|
|
26
30
|
report_line(offense.location)
|
27
31
|
report_highlighted_area(offense.highlighted_area)
|
28
|
-
rescue IndexError
|
32
|
+
rescue IndexError # rubocop:disable Lint/SuppressedException
|
29
33
|
# range is not on a valid line; perhaps the source file is empty
|
30
34
|
end
|
31
|
-
# rubocop:enable Lint/HandleExceptions
|
32
35
|
end
|
33
36
|
|
34
37
|
def valid_line?(offense)
|
@@ -8,20 +8,30 @@ module RuboCop
|
|
8
8
|
class EmacsStyleFormatter < BaseFormatter
|
9
9
|
def file_finished(file, offenses)
|
10
10
|
offenses.each do |o|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
output.printf("%s:%d:%d: %s: %s\n",
|
21
|
-
file, o.line, o.real_column, o.severity.code,
|
22
|
-
message.tr("\n", ' '))
|
11
|
+
output.printf(
|
12
|
+
"%<path>s:%<line>d:%<column>d: %<severity>s: %<message>s\n",
|
13
|
+
path: file,
|
14
|
+
line: o.line,
|
15
|
+
column: o.real_column,
|
16
|
+
severity: o.severity.code,
|
17
|
+
message: message(o)
|
18
|
+
)
|
23
19
|
end
|
24
20
|
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def message(offense)
|
25
|
+
message =
|
26
|
+
if offense.corrected_with_todo?
|
27
|
+
"[Todo] #{offense.message}"
|
28
|
+
elsif offense.corrected?
|
29
|
+
"[Corrected] #{offense.message}"
|
30
|
+
else
|
31
|
+
offense.message
|
32
|
+
end
|
33
|
+
message.tr("\n", ' ')
|
34
|
+
end
|
25
35
|
end
|
26
36
|
end
|
27
37
|
end
|
@@ -9,21 +9,21 @@ module RuboCop
|
|
9
9
|
# which invoke same method of each formatters.
|
10
10
|
class FormatterSet < Array
|
11
11
|
BUILTIN_FORMATTERS_FOR_KEYS = {
|
12
|
-
'
|
13
|
-
'
|
14
|
-
'
|
15
|
-
'
|
16
|
-
'
|
17
|
-
'
|
18
|
-
'
|
19
|
-
'
|
20
|
-
'
|
21
|
-
'
|
22
|
-
'
|
23
|
-
'
|
24
|
-
'
|
25
|
-
'
|
26
|
-
'
|
12
|
+
'[a]utogenconf' => AutoGenConfigFormatter,
|
13
|
+
'[c]lang' => ClangStyleFormatter,
|
14
|
+
'[d]isabled' => DisabledLinesFormatter,
|
15
|
+
'[e]macs' => EmacsStyleFormatter,
|
16
|
+
'[fi]les' => FileListFormatter,
|
17
|
+
'[fu]ubar' => FuubarStyleFormatter,
|
18
|
+
'[h]tml' => HTMLFormatter,
|
19
|
+
'[j]son' => JSONFormatter,
|
20
|
+
'[o]ffenses' => OffenseCountFormatter,
|
21
|
+
'[pa]cman' => PacmanFormatter,
|
22
|
+
'[p]rogress' => ProgressFormatter,
|
23
|
+
'[q]uiet' => QuietFormatter,
|
24
|
+
'[s]imple' => SimpleTextFormatter,
|
25
|
+
'[t]ap' => TapFormatter,
|
26
|
+
'[w]orst' => WorstOffendersFormatter
|
27
27
|
}.freeze
|
28
28
|
|
29
29
|
FORMATTER_APIS = %i[started finished].freeze
|
@@ -82,7 +82,7 @@ module RuboCop
|
|
82
82
|
|
83
83
|
def builtin_formatter_class(specified_key)
|
84
84
|
matching_keys = BUILTIN_FORMATTERS_FOR_KEYS.keys.select do |key|
|
85
|
-
key.
|
85
|
+
key =~ /^\[#{specified_key}\]/ || specified_key == key.delete('[]')
|
86
86
|
end
|
87
87
|
|
88
88
|
raise %(No formatter for "#{specified_key}") if matching_keys.empty?
|
@@ -53,11 +53,12 @@ module RuboCop
|
|
53
53
|
|
54
54
|
def hash_for_offense(offense)
|
55
55
|
{
|
56
|
-
severity:
|
57
|
-
message:
|
58
|
-
cop_name:
|
59
|
-
corrected:
|
60
|
-
|
56
|
+
severity: offense.severity.name,
|
57
|
+
message: offense.message,
|
58
|
+
cop_name: offense.cop_name,
|
59
|
+
corrected: offense.corrected?,
|
60
|
+
correctable: offense.correctable?,
|
61
|
+
location: hash_for_location(offense)
|
61
62
|
}
|
62
63
|
end
|
63
64
|
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
module RuboCop
|
4
4
|
module Formatter
|
5
|
-
# This formatter prints a PACDOT per every file to be
|
5
|
+
# This formatter prints a PACDOT per every file to be analyzed.
|
6
6
|
# Pacman will "eat" one PACDOT per file when no offense is detected.
|
7
7
|
# Otherwise it will print a Ghost.
|
8
8
|
# This is inspired by the Pacman formatter for RSpec by Carlos Rojas.
|
@@ -49,7 +49,7 @@ module RuboCop
|
|
49
49
|
|
50
50
|
def cols
|
51
51
|
@cols ||= begin
|
52
|
-
width =
|
52
|
+
_height, width = $stdout.winsize
|
53
53
|
width.nil? || width.zero? ? FALLBACK_TERMINAL_WIDTH : width
|
54
54
|
end
|
55
55
|
end
|
@@ -68,7 +68,7 @@ module RuboCop
|
|
68
68
|
def step(character)
|
69
69
|
regex = /#{Regexp.quote(PACMAN)}|#{Regexp.quote(PACDOT)}/
|
70
70
|
@progress_line = @progress_line.sub(regex, character)
|
71
|
-
output.printf("
|
71
|
+
output.printf("%<line>s\r", line: @progress_line)
|
72
72
|
return unless @progress_line[-1] =~ /ᗣ|\./
|
73
73
|
|
74
74
|
@repetitions += 1
|
@@ -42,9 +42,13 @@ module RuboCop
|
|
42
42
|
output.puts yellow("== #{smart_path(file)} ==")
|
43
43
|
|
44
44
|
offenses.each do |o|
|
45
|
-
output.printf(
|
46
|
-
|
47
|
-
|
45
|
+
output.printf(
|
46
|
+
"%<severity>s:%3<line>d:%3<column>d: %<message>s\n",
|
47
|
+
severity: colored_severity_code(o),
|
48
|
+
line: o.line,
|
49
|
+
column: o.real_column,
|
50
|
+
message: message(o)
|
51
|
+
)
|
48
52
|
end
|
49
53
|
end
|
50
54
|
|
@@ -42,20 +42,23 @@ module RuboCop
|
|
42
42
|
end
|
43
43
|
|
44
44
|
def report_offense(file, offense)
|
45
|
-
output.printf(
|
46
|
-
|
47
|
-
|
45
|
+
output.printf(
|
46
|
+
"# %<path>s:%<line>d:%<column>d: %<severity>s: %<message>s\n",
|
47
|
+
path: cyan(smart_path(file)),
|
48
|
+
line: offense.line,
|
49
|
+
column: offense.real_column,
|
50
|
+
severity: colored_severity_code(offense),
|
51
|
+
message: message(offense)
|
52
|
+
)
|
48
53
|
|
49
|
-
# rubocop:disable Lint/HandleExceptions
|
50
54
|
begin
|
51
55
|
return unless valid_line?(offense)
|
52
56
|
|
53
57
|
report_line(offense.location)
|
54
58
|
report_highlighted_area(offense.highlighted_area)
|
55
|
-
rescue IndexError
|
59
|
+
rescue IndexError # rubocop:disable Lint/SuppressedException
|
56
60
|
# range is not on a valid line; perhaps the source file is empty
|
57
61
|
end
|
58
|
-
# rubocop:enable Lint/HandleExceptions
|
59
62
|
end
|
60
63
|
|
61
64
|
def annotate_message(msg)
|
data/lib/rubocop/node_pattern.rb
CHANGED
@@ -380,7 +380,7 @@ module RuboCop
|
|
380
380
|
def compile_seq_head
|
381
381
|
return unless seq_head?
|
382
382
|
|
383
|
-
fail_due_to 'sequences
|
383
|
+
fail_due_to 'sequences cannot start with <' \
|
384
384
|
if @terms[0].respond_to? :call
|
385
385
|
|
386
386
|
with_seq_head_context(@terms[0])
|
@@ -429,12 +429,13 @@ module RuboCop
|
|
429
429
|
[0..Float::INFINITY, 'true']
|
430
430
|
end
|
431
431
|
|
432
|
+
# rubocop:disable Metrics/AbcSize
|
432
433
|
# rubocop:disable Metrics/MethodLength
|
433
434
|
def compile_any_order(capture_all = nil)
|
434
435
|
rest = capture_rest = nil
|
435
436
|
patterns = []
|
436
437
|
with_temp_variables do |child, matched|
|
437
|
-
tokens_until('>', 'any child')
|
438
|
+
tokens_until('>', 'any child') do
|
438
439
|
fail_due_to 'ellipsis must be at the end of <>' if rest
|
439
440
|
token = tokens.shift
|
440
441
|
case token
|
@@ -448,6 +449,7 @@ module RuboCop
|
|
448
449
|
end
|
449
450
|
end
|
450
451
|
# rubocop:enable Metrics/MethodLength
|
452
|
+
# rubocop:enable Metrics/AbcSize
|
451
453
|
|
452
454
|
def insure_same_captures(enum, what)
|
453
455
|
return to_enum __method__, enum, what unless block_given?
|
data/lib/rubocop/options.rb
CHANGED
@@ -255,21 +255,27 @@ module RuboCop
|
|
255
255
|
@options = options
|
256
256
|
end
|
257
257
|
|
258
|
+
def validate_cop_options
|
259
|
+
%i[only except].each do |opt|
|
260
|
+
OptionsValidator.validate_cop_list(@options[opt])
|
261
|
+
end
|
262
|
+
end
|
263
|
+
|
258
264
|
# rubocop:disable Metrics/AbcSize
|
259
265
|
def validate_compatibility # rubocop:disable Metrics/MethodLength
|
260
|
-
if
|
261
|
-
raise OptionArgumentError, 'Lint/
|
266
|
+
if only_includes_redundant_disable?
|
267
|
+
raise OptionArgumentError, 'Lint/RedundantCopDisableDirective cannot ' \
|
262
268
|
'be used with --only.'
|
263
269
|
end
|
264
270
|
if except_syntax?
|
265
|
-
raise OptionArgumentError, 'Syntax checking
|
271
|
+
raise OptionArgumentError, 'Syntax checking cannot be turned off.'
|
266
272
|
end
|
267
273
|
unless boolean_or_empty_cache?
|
268
274
|
raise OptionArgumentError, '-C/--cache argument must be true or false'
|
269
275
|
end
|
270
276
|
|
271
277
|
if display_only_fail_level_offenses_with_autocorrect?
|
272
|
-
raise OptionArgumentError, '--autocorrect
|
278
|
+
raise OptionArgumentError, '--autocorrect cannot be used with ' \
|
273
279
|
'--display-only-fail-level-offenses'
|
274
280
|
end
|
275
281
|
validate_auto_gen_config
|
@@ -323,8 +329,8 @@ module RuboCop
|
|
323
329
|
auto_gen_config: '-P/--parallel uses caching to speed up execution, ' \
|
324
330
|
'while --auto-gen-config needs a non-cached run, ' \
|
325
331
|
'so they cannot be combined.',
|
326
|
-
fail_fast: '-P/--parallel
|
327
|
-
auto_correct: '-P/--parallel
|
332
|
+
fail_fast: '-P/--parallel cannot be combined with -F/--fail-fast.',
|
333
|
+
auto_correct: '-P/--parallel cannot be combined with --auto-correct.'
|
328
334
|
}
|
329
335
|
|
330
336
|
combos.each do |key, msg|
|
@@ -332,10 +338,10 @@ module RuboCop
|
|
332
338
|
end
|
333
339
|
end
|
334
340
|
|
335
|
-
def
|
341
|
+
def only_includes_redundant_disable?
|
336
342
|
@options.key?(:only) &&
|
337
|
-
(@options[:only] & %w[Lint/
|
338
|
-
|
343
|
+
(@options[:only] & %w[Lint/RedundantCopDisableDirective
|
344
|
+
RedundantCopDisableDirective]).any?
|
339
345
|
end
|
340
346
|
|
341
347
|
def display_only_fail_level_offenses_with_autocorrect?
|
@@ -367,8 +373,9 @@ module RuboCop
|
|
367
373
|
# This module contains help texts for command line options.
|
368
374
|
module OptionsHelp
|
369
375
|
MAX_EXCL = RuboCop::Options::DEFAULT_MAXIMUM_EXCLUSION_ITEMS.to_s
|
376
|
+
# rubocop:disable Layout/LineLength
|
377
|
+
FORMATTER_OPTION_LIST = RuboCop::Formatter::FormatterSet::BUILTIN_FORMATTERS_FOR_KEYS.keys
|
370
378
|
|
371
|
-
# rubocop:disable Metrics/LineLength
|
372
379
|
TEXT = {
|
373
380
|
only: 'Run only the given cop(s).',
|
374
381
|
only_guide_cops: ['Run only cops for rules that link to a',
|
@@ -407,21 +414,8 @@ module RuboCop
|
|
407
414
|
format: ['Choose an output formatter. This option',
|
408
415
|
'can be specified multiple times to enable',
|
409
416
|
'multiple formatters at the same time.',
|
410
|
-
'
|
411
|
-
|
412
|
-
' [c]lang',
|
413
|
-
' [d]isabled cops via inline comments',
|
414
|
-
' [fu]ubar',
|
415
|
-
' [pa]cman',
|
416
|
-
' [e]macs',
|
417
|
-
' [j]son',
|
418
|
-
' [h]tml',
|
419
|
-
' [fi]les',
|
420
|
-
' [o]ffenses',
|
421
|
-
' [w]orst',
|
422
|
-
' [t]ap',
|
423
|
-
' [q]uiet',
|
424
|
-
' [a]utogenconf',
|
417
|
+
'[p]rogress is used by default',
|
418
|
+
*FORMATTER_OPTION_LIST.map { |item| " #{item}" },
|
425
419
|
' custom formatter class name'],
|
426
420
|
out: ['Write output to a file instead of STDOUT.',
|
427
421
|
'This option applies to the previously',
|
@@ -461,6 +455,6 @@ module RuboCop
|
|
461
455
|
'reports. This is useful for editor integration.'],
|
462
456
|
init: 'Generate a .rubocop.yml file in the current directory.'
|
463
457
|
}.freeze
|
464
|
-
# rubocop:enable
|
458
|
+
# rubocop:enable Layout/LineLength
|
465
459
|
end
|
466
460
|
end
|