rubocop 1.20.0 → 1.22.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/config/default.yml +64 -15
- data/lib/rubocop/config.rb +5 -0
- data/lib/rubocop/config_loader.rb +3 -1
- data/lib/rubocop/config_validator.rb +9 -1
- data/lib/rubocop/cop/base.rb +3 -3
- data/lib/rubocop/cop/bundler/gem_comment.rb +3 -3
- data/lib/rubocop/cop/bundler/insecure_protocol_source.rb +45 -21
- data/lib/rubocop/cop/bundler/ordered_gems.rb +3 -12
- data/lib/rubocop/cop/correctors/lambda_literal_to_method_corrector.rb +2 -2
- data/lib/rubocop/cop/correctors/line_break_corrector.rb +1 -1
- data/lib/rubocop/cop/correctors/ordered_gem_corrector.rb +11 -10
- data/lib/rubocop/cop/gemspec/ordered_dependencies.rb +3 -12
- data/lib/rubocop/cop/gemspec/required_ruby_version.rb +31 -24
- data/lib/rubocop/cop/generator.rb +14 -8
- data/lib/rubocop/cop/internal_affairs/location_line_equality_comparison.rb +60 -0
- data/lib/rubocop/cop/internal_affairs/node_matcher_directive.rb +1 -1
- data/lib/rubocop/cop/internal_affairs.rb +1 -0
- data/lib/rubocop/cop/layout/argument_alignment.rb +1 -1
- data/lib/rubocop/cop/layout/assignment_indentation.rb +1 -1
- data/lib/rubocop/cop/layout/class_structure.rb +2 -1
- data/lib/rubocop/cop/layout/dot_position.rb +30 -5
- data/lib/rubocop/cop/layout/empty_comment.rb +1 -1
- data/lib/rubocop/cop/layout/empty_lines_around_exception_handling_keywords.rb +7 -4
- data/lib/rubocop/cop/layout/end_alignment.rb +2 -3
- data/lib/rubocop/cop/layout/first_array_element_indentation.rb +1 -1
- data/lib/rubocop/cop/layout/first_hash_element_indentation.rb +1 -1
- data/lib/rubocop/cop/layout/first_parameter_indentation.rb +1 -1
- data/lib/rubocop/cop/layout/hash_alignment.rb +1 -1
- data/lib/rubocop/cop/layout/heredoc_argument_closing_parenthesis.rb +1 -1
- data/lib/rubocop/cop/layout/indentation_width.rb +1 -1
- data/lib/rubocop/cop/layout/leading_comment_space.rb +1 -1
- data/lib/rubocop/cop/layout/line_length.rb +9 -7
- data/lib/rubocop/cop/layout/multiline_assignment_layout.rb +1 -1
- data/lib/rubocop/cop/layout/multiline_block_layout.rb +3 -3
- data/lib/rubocop/cop/layout/multiline_method_call_indentation.rb +1 -1
- data/lib/rubocop/cop/layout/redundant_line_break.rb +1 -0
- data/lib/rubocop/cop/layout/rescue_ensure_alignment.rb +1 -1
- data/lib/rubocop/cop/layout/single_line_block_chain.rb +15 -4
- data/lib/rubocop/cop/layout/space_after_not.rb +1 -0
- data/lib/rubocop/cop/layout/space_around_equals_in_parameter_default.rb +2 -1
- data/lib/rubocop/cop/layout/space_around_keyword.rb +2 -2
- data/lib/rubocop/cop/layout/space_before_brackets.rb +1 -0
- data/lib/rubocop/cop/layout/space_before_comment.rb +1 -1
- data/lib/rubocop/cop/layout/space_inside_parens.rb +74 -28
- data/lib/rubocop/cop/layout/space_inside_reference_brackets.rb +1 -1
- data/lib/rubocop/cop/lint/ambiguous_operator_precedence.rb +111 -0
- data/lib/rubocop/cop/lint/ambiguous_range.rb +9 -9
- data/lib/rubocop/cop/lint/assignment_in_condition.rb +7 -5
- data/lib/rubocop/cop/lint/binary_operator_with_identical_operands.rb +18 -5
- data/lib/rubocop/cop/lint/boolean_symbol.rb +5 -0
- data/lib/rubocop/cop/lint/debugger.rb +0 -2
- data/lib/rubocop/cop/lint/deprecated_class_methods.rb +4 -4
- data/lib/rubocop/cop/lint/disjunctive_assignment_in_constructor.rb +24 -1
- data/lib/rubocop/cop/lint/else_layout.rb +10 -6
- data/lib/rubocop/cop/lint/empty_in_pattern.rb +1 -1
- data/lib/rubocop/cop/lint/erb_new_arguments.rb +1 -1
- data/lib/rubocop/cop/lint/float_out_of_range.rb +1 -1
- data/lib/rubocop/cop/lint/hash_compare_by_identity.rb +12 -3
- data/lib/rubocop/cop/lint/incompatible_io_select_with_fiber_scheduler.rb +67 -0
- data/lib/rubocop/cop/lint/interpolation_check.rb +5 -0
- data/lib/rubocop/cop/lint/loop.rb +4 -3
- data/lib/rubocop/cop/lint/non_deterministic_require_order.rb +5 -1
- data/lib/rubocop/cop/lint/number_conversion.rb +12 -1
- data/lib/rubocop/cop/lint/numbered_parameter_assignment.rb +1 -1
- data/lib/rubocop/cop/lint/or_assignment_to_constant.rb +4 -2
- data/lib/rubocop/cop/lint/out_of_range_regexp_ref.rb +17 -0
- data/lib/rubocop/cop/lint/percent_string_array.rb +10 -0
- data/lib/rubocop/cop/lint/raise_exception.rb +4 -0
- data/lib/rubocop/cop/lint/redundant_safe_navigation.rb +5 -4
- data/lib/rubocop/cop/lint/require_relative_self_path.rb +50 -0
- data/lib/rubocop/cop/lint/shadowing_outer_local_variable.rb +1 -1
- data/lib/rubocop/cop/lint/symbol_conversion.rb +1 -1
- data/lib/rubocop/cop/lint/triple_quotes.rb +1 -1
- data/lib/rubocop/cop/lint/unexpected_block_arity.rb +8 -3
- data/lib/rubocop/cop/lint/unused_method_argument.rb +2 -3
- data/lib/rubocop/cop/lint/useless_method_definition.rb +3 -2
- data/lib/rubocop/cop/lint/useless_setter_call.rb +7 -4
- data/lib/rubocop/cop/lint/useless_times.rb +4 -3
- data/lib/rubocop/cop/metrics/abc_size.rb +6 -0
- data/lib/rubocop/cop/metrics/parameter_lists.rb +5 -2
- data/lib/rubocop/cop/metrics/perceived_complexity.rb +1 -1
- data/lib/rubocop/cop/metrics/utils/abc_size_calculator.rb +1 -1
- data/lib/rubocop/cop/metrics/utils/code_length_calculator.rb +1 -1
- data/lib/rubocop/cop/mixin/code_length.rb +1 -1
- data/lib/rubocop/cop/mixin/end_keyword_alignment.rb +1 -2
- data/lib/rubocop/cop/mixin/frozen_string_literal.rb +15 -6
- data/lib/rubocop/cop/mixin/hash_transform_method.rb +3 -3
- data/lib/rubocop/cop/mixin/heredoc.rb +1 -3
- data/lib/rubocop/cop/mixin/multiline_element_indentation.rb +1 -1
- data/lib/rubocop/cop/mixin/multiline_expression_indentation.rb +2 -2
- data/lib/rubocop/cop/mixin/multiline_literal_brace_layout.rb +1 -1
- data/lib/rubocop/cop/mixin/ordered_gem_node.rb +9 -1
- data/lib/rubocop/cop/mixin/percent_array.rb +6 -1
- data/lib/rubocop/cop/mixin/preceding_following_alignment.rb +9 -1
- data/lib/rubocop/cop/mixin/space_after_punctuation.rb +1 -1
- data/lib/rubocop/cop/mixin/space_before_punctuation.rb +1 -1
- data/lib/rubocop/cop/mixin/statement_modifier.rb +1 -1
- data/lib/rubocop/cop/mixin/string_literals_help.rb +5 -1
- data/lib/rubocop/cop/mixin/trailing_body.rb +1 -1
- data/lib/rubocop/cop/naming/ascii_identifiers.rb +0 -3
- data/lib/rubocop/cop/naming/block_parameter_name.rb +1 -1
- data/lib/rubocop/cop/naming/constant_name.rb +1 -1
- data/lib/rubocop/cop/naming/inclusive_language.rb +9 -9
- data/lib/rubocop/cop/naming/memoized_instance_variable_name.rb +5 -4
- data/lib/rubocop/cop/naming/rescued_exceptions_variable_name.rb +7 -0
- data/lib/rubocop/cop/security/io_methods.rb +49 -0
- data/lib/rubocop/cop/security/json_load.rb +8 -7
- data/lib/rubocop/cop/security/open.rb +4 -0
- data/lib/rubocop/cop/security/yaml_load.rb +4 -0
- data/lib/rubocop/cop/style/accessor_grouping.rb +2 -2
- data/lib/rubocop/cop/style/and_or.rb +5 -0
- data/lib/rubocop/cop/style/arguments_forwarding.rb +13 -2
- data/lib/rubocop/cop/style/array_coercion.rb +21 -3
- data/lib/rubocop/cop/style/ascii_comments.rb +0 -3
- data/lib/rubocop/cop/style/case_equality.rb +6 -9
- data/lib/rubocop/cop/style/case_like_if.rb +5 -0
- data/lib/rubocop/cop/style/class_and_module_children.rb +9 -0
- data/lib/rubocop/cop/style/collection_compact.rb +7 -5
- data/lib/rubocop/cop/style/collection_methods.rb +8 -6
- data/lib/rubocop/cop/style/combinable_loops.rb +3 -2
- data/lib/rubocop/cop/style/commented_keyword.rb +9 -4
- data/lib/rubocop/cop/style/date_time.rb +5 -0
- data/lib/rubocop/cop/style/document_dynamic_eval_definition.rb +1 -1
- data/lib/rubocop/cop/style/documentation.rb +23 -8
- data/lib/rubocop/cop/style/double_negation.rb +15 -5
- data/lib/rubocop/cop/style/empty_method.rb +1 -1
- data/lib/rubocop/cop/style/explicit_block_argument.rb +21 -11
- data/lib/rubocop/cop/style/float_division.rb +10 -2
- data/lib/rubocop/cop/style/frozen_string_literal_comment.rb +6 -1
- data/lib/rubocop/cop/style/global_std_stream.rb +4 -0
- data/lib/rubocop/cop/style/hash_each_methods.rb +5 -0
- data/lib/rubocop/cop/style/hash_transform_keys.rb +4 -6
- data/lib/rubocop/cop/style/hash_transform_values.rb +4 -6
- data/lib/rubocop/cop/style/identical_conditional_branches.rb +18 -16
- data/lib/rubocop/cop/style/if_with_boolean_literal_branches.rb +18 -4
- data/lib/rubocop/cop/style/infinite_loop.rb +4 -3
- data/lib/rubocop/cop/style/inverse_methods.rb +9 -2
- data/lib/rubocop/cop/style/lambda_call.rb +1 -1
- data/lib/rubocop/cop/style/line_end_concatenation.rb +14 -1
- data/lib/rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses.rb +6 -6
- data/lib/rubocop/cop/style/module_function.rb +8 -9
- data/lib/rubocop/cop/style/multiline_in_pattern_then.rb +1 -1
- data/lib/rubocop/cop/style/multiline_when_then.rb +1 -1
- data/lib/rubocop/cop/style/mutable_constant.rb +13 -8
- data/lib/rubocop/cop/style/negated_if.rb +1 -1
- data/lib/rubocop/cop/style/negated_unless.rb +1 -1
- data/lib/rubocop/cop/style/non_nil_check.rb +2 -2
- data/lib/rubocop/cop/style/not.rb +2 -2
- data/lib/rubocop/cop/style/numbered_parameters.rb +46 -0
- data/lib/rubocop/cop/style/numbered_parameters_limit.rb +50 -0
- data/lib/rubocop/cop/style/numeric_literals.rb +7 -8
- data/lib/rubocop/cop/style/numeric_predicate.rb +5 -0
- data/lib/rubocop/cop/style/optional_arguments.rb +4 -0
- data/lib/rubocop/cop/style/optional_boolean_parameter.rb +14 -4
- data/lib/rubocop/cop/style/parallel_assignment.rb +1 -1
- data/lib/rubocop/cop/style/percent_q_literals.rb +2 -2
- data/lib/rubocop/cop/style/preferred_hash_methods.rb +9 -4
- data/lib/rubocop/cop/style/quoted_symbols.rb +10 -6
- data/lib/rubocop/cop/style/raise_args.rb +1 -1
- data/lib/rubocop/cop/style/redundant_argument.rb +19 -9
- data/lib/rubocop/cop/style/redundant_condition.rb +2 -3
- data/lib/rubocop/cop/style/redundant_fetch_block.rb +4 -0
- data/lib/rubocop/cop/style/redundant_file_extension_in_require.rb +12 -3
- data/lib/rubocop/cop/style/redundant_freeze.rb +0 -1
- data/lib/rubocop/cop/style/redundant_interpolation.rb +1 -1
- data/lib/rubocop/cop/style/redundant_percent_q.rb +2 -3
- data/lib/rubocop/cop/style/redundant_self.rb +10 -0
- data/lib/rubocop/cop/style/redundant_self_assignment.rb +4 -3
- data/lib/rubocop/cop/style/redundant_self_assignment_branch.rb +1 -1
- data/lib/rubocop/cop/style/redundant_sort.rb +51 -18
- data/lib/rubocop/cop/style/regexp_literal.rb +3 -3
- data/lib/rubocop/cop/style/return_nil.rb +2 -1
- data/lib/rubocop/cop/style/safe_navigation.rb +13 -2
- data/lib/rubocop/cop/style/select_by_regexp.rb +138 -0
- data/lib/rubocop/cop/style/single_argument_dig.rb +5 -0
- data/lib/rubocop/cop/style/slicing_with_range.rb +13 -0
- data/lib/rubocop/cop/style/special_global_vars.rb +4 -0
- data/lib/rubocop/cop/style/static_class.rb +5 -5
- data/lib/rubocop/cop/style/string_chars.rb +4 -2
- data/lib/rubocop/cop/style/string_concatenation.rb +5 -1
- data/lib/rubocop/cop/style/string_hash_keys.rb +4 -0
- data/lib/rubocop/cop/style/struct_inheritance.rb +3 -2
- data/lib/rubocop/cop/style/swap_values.rb +4 -2
- data/lib/rubocop/cop/style/symbol_proc.rb +26 -0
- data/lib/rubocop/cop/style/trailing_comma_in_block_args.rb +19 -0
- data/lib/rubocop/cop/style/trivial_accessors.rb +1 -1
- data/lib/rubocop/cop/style/yoda_condition.rb +24 -7
- data/lib/rubocop/cop/style/zero_length_predicate.rb +6 -0
- data/lib/rubocop/cop/util.rb +15 -4
- data/lib/rubocop/cops_documentation_generator.rb +17 -5
- data/lib/rubocop/options.rb +126 -112
- data/lib/rubocop/rake_task.rb +1 -1
- data/lib/rubocop/result_cache.rb +3 -3
- data/lib/rubocop/rspec/cop_helper.rb +1 -1
- data/lib/rubocop/rspec/expect_offense.rb +6 -2
- data/lib/rubocop/rspec/parallel_formatter.rb +90 -0
- data/lib/rubocop/rspec/support.rb +1 -0
- data/lib/rubocop/runner.rb +2 -3
- data/lib/rubocop/target_finder.rb +1 -1
- data/lib/rubocop/version.rb +1 -1
- data/lib/rubocop.rb +8 -1
- metadata +14 -5
data/lib/rubocop/options.rb
CHANGED
@@ -59,86 +59,111 @@ module RuboCop
|
|
59
59
|
|
60
60
|
def define_options
|
61
61
|
OptionParser.new do |opts|
|
62
|
-
opts.banner = 'Usage: rubocop [options] [file1, file2, ...]'
|
62
|
+
opts.banner = rainbow.wrap('Usage: rubocop [options] [file1, file2, ...]').bright
|
63
63
|
|
64
|
-
|
65
|
-
add_only_options(opts)
|
66
|
-
add_configuration_options(opts)
|
67
|
-
add_formatting_options(opts)
|
68
|
-
|
69
|
-
option(opts, '-r', '--require FILE') { |f| require_feature(f) }
|
70
|
-
|
71
|
-
add_severity_option(opts)
|
72
|
-
add_flags_with_optional_args(opts)
|
64
|
+
add_check_options(opts)
|
73
65
|
add_cache_options(opts)
|
74
|
-
|
75
|
-
|
66
|
+
add_output_options(opts)
|
67
|
+
add_autocorrection_options(opts)
|
68
|
+
add_config_generation_options(opts)
|
69
|
+
add_additional_modes(opts)
|
70
|
+
add_general_options(opts)
|
71
|
+
end
|
72
|
+
end
|
76
73
|
|
74
|
+
def add_check_options(opts) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
75
|
+
section(opts, 'Basic Options') do
|
76
|
+
option(opts, '-l', '--lint') do
|
77
|
+
@options[:only] ||= []
|
78
|
+
@options[:only] << 'Lint'
|
79
|
+
end
|
80
|
+
option(opts, '-x', '--fix-layout') do
|
81
|
+
@options[:only] ||= []
|
82
|
+
@options[:only] << 'Layout'
|
83
|
+
@options[:auto_correct] = true
|
84
|
+
end
|
85
|
+
option(opts, '--safe')
|
86
|
+
add_cop_selection_csv_option('except', opts)
|
87
|
+
add_cop_selection_csv_option('only', opts)
|
88
|
+
option(opts, '--only-guide-cops')
|
89
|
+
option(opts, '-F', '--fail-fast')
|
90
|
+
option(opts, '--disable-pending-cops')
|
91
|
+
option(opts, '--enable-pending-cops')
|
92
|
+
option(opts, '--ignore-disable-comments')
|
93
|
+
option(opts, '--force-exclusion')
|
94
|
+
option(opts, '--only-recognized-file-types')
|
95
|
+
option(opts, '--ignore-parent-exclusion')
|
96
|
+
option(opts, '--force-default-config')
|
77
97
|
option(opts, '-s', '--stdin FILE')
|
98
|
+
option(opts, '-P', '--[no-]parallel')
|
99
|
+
add_severity_option(opts)
|
78
100
|
end
|
79
101
|
end
|
80
102
|
|
81
|
-
def
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
103
|
+
def add_output_options(opts) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
104
|
+
section(opts, 'Output Options') do
|
105
|
+
option(opts, '-f', '--format FORMATTER') do |key|
|
106
|
+
@options[:formatters] ||= []
|
107
|
+
@options[:formatters] << [key]
|
108
|
+
end
|
86
109
|
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
message = "--#{option} argument should be [COP1,COP2,...]."
|
110
|
+
option(opts, '-D', '--[no-]display-cop-names')
|
111
|
+
option(opts, '-E', '--extra-details')
|
112
|
+
option(opts, '-S', '--display-style-guide')
|
91
113
|
|
92
|
-
|
114
|
+
option(opts, '-o', '--out FILE') do |path|
|
115
|
+
if @options[:formatters]
|
116
|
+
@options[:formatters].last << path
|
117
|
+
else
|
118
|
+
@options[:output_path] = path
|
119
|
+
end
|
93
120
|
end
|
94
121
|
|
95
|
-
|
122
|
+
option(opts, '--stderr')
|
123
|
+
option(opts, '--display-time')
|
124
|
+
option(opts, '--display-only-failed')
|
125
|
+
option(opts, '--display-only-fail-level-offenses')
|
96
126
|
end
|
97
127
|
end
|
98
128
|
|
99
|
-
def
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
def add_auto_gen_options(opts)
|
109
|
-
option(opts, '--auto-gen-config')
|
110
|
-
|
111
|
-
option(opts, '--regenerate-todo') do
|
112
|
-
@options.replace(ConfigRegeneration.new.options.merge(@options))
|
129
|
+
def add_autocorrection_options(opts)
|
130
|
+
section(opts, 'Auto-correction') do
|
131
|
+
option(opts, '-a', '--auto-correct') { @options[:safe_auto_correct] = true }
|
132
|
+
option(opts, '--safe-auto-correct') do
|
133
|
+
warn '--safe-auto-correct is deprecated; use --auto-correct'
|
134
|
+
@options[:safe_auto_correct] = @options[:auto_correct] = true
|
135
|
+
end
|
136
|
+
option(opts, '-A', '--auto-correct-all') { @options[:auto_correct] = true }
|
137
|
+
option(opts, '--disable-uncorrectable')
|
113
138
|
end
|
139
|
+
end
|
114
140
|
|
115
|
-
|
141
|
+
def add_config_generation_options(opts)
|
142
|
+
section(opts, 'Config Generation') do
|
143
|
+
option(opts, '--auto-gen-config')
|
116
144
|
|
117
|
-
|
145
|
+
option(opts, '--regenerate-todo') do
|
146
|
+
@options.replace(ConfigRegeneration.new.options.merge(@options))
|
147
|
+
end
|
118
148
|
|
119
|
-
|
120
|
-
option(opts, '--[no-]auto-gen-only-exclude')
|
121
|
-
option(opts, '--[no-]auto-gen-timestamp')
|
149
|
+
option(opts, '--exclude-limit COUNT') { @validator.validate_exclude_limit_option }
|
122
150
|
|
123
|
-
|
151
|
+
option(opts, '--[no-]offense-counts')
|
152
|
+
option(opts, '--[no-]auto-gen-only-exclude')
|
153
|
+
option(opts, '--[no-]auto-gen-timestamp')
|
154
|
+
end
|
124
155
|
end
|
125
156
|
|
126
|
-
def
|
127
|
-
option(opts,
|
128
|
-
|
129
|
-
|
130
|
-
end
|
157
|
+
def add_cop_selection_csv_option(option, opts)
|
158
|
+
option(opts, "--#{option} [COP1,COP2,...]") do |list|
|
159
|
+
unless list
|
160
|
+
message = "--#{option} argument should be [COP1,COP2,...]."
|
131
161
|
|
132
|
-
|
133
|
-
if @options[:formatters]
|
134
|
-
@options[:formatters].last << path
|
135
|
-
else
|
136
|
-
@options[:output_path] = path
|
162
|
+
raise OptionArgumentError, message
|
137
163
|
end
|
138
|
-
end
|
139
164
|
|
140
|
-
|
141
|
-
|
165
|
+
@options[:"#{option}"] = list.empty? ? [''] : list.split(',')
|
166
|
+
end
|
142
167
|
end
|
143
168
|
|
144
169
|
def add_severity_option(opts)
|
@@ -148,62 +173,50 @@ module RuboCop
|
|
148
173
|
table) do |severity|
|
149
174
|
@options[:fail_level] = severity
|
150
175
|
end
|
151
|
-
option(opts, '--display-only-fail-level-offenses')
|
152
176
|
end
|
153
177
|
|
154
|
-
def
|
155
|
-
|
156
|
-
|
178
|
+
def add_cache_options(opts)
|
179
|
+
section(opts, 'Caching') do
|
180
|
+
option(opts, '-C', '--cache FLAG')
|
181
|
+
option(opts, '--cache-root DIR') { @validator.validate_cache_enabled_for_cache_root }
|
157
182
|
end
|
158
183
|
end
|
159
184
|
|
160
|
-
def
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
def add_boolean_flags(opts)
|
167
|
-
option(opts, '-F', '--fail-fast')
|
168
|
-
option(opts, '-d', '--debug')
|
169
|
-
option(opts, '-D', '--[no-]display-cop-names')
|
170
|
-
option(opts, '-E', '--extra-details')
|
171
|
-
option(opts, '-S', '--display-style-guide')
|
172
|
-
option(opts, '-a', '--auto-correct') { @options[:safe_auto_correct] = true }
|
173
|
-
option(opts, '--safe-auto-correct') do
|
174
|
-
warn '--safe-auto-correct is deprecated; use --auto-correct'
|
175
|
-
@options[:safe_auto_correct] = @options[:auto_correct] = true
|
185
|
+
def add_additional_modes(opts)
|
186
|
+
section(opts, 'Additional Modes') do
|
187
|
+
option(opts, '-L', '--list-target-files')
|
188
|
+
option(opts, '--show-cops [COP1,COP2,...]') do |list|
|
189
|
+
@options[:show_cops] = list.nil? ? [] : list.split(',')
|
190
|
+
end
|
176
191
|
end
|
177
|
-
option(opts, '-A', '--auto-correct-all') { @options[:auto_correct] = true }
|
178
|
-
option(opts, '--disable-pending-cops')
|
179
|
-
option(opts, '--enable-pending-cops')
|
180
|
-
option(opts, '--ignore-disable-comments')
|
181
|
-
|
182
|
-
option(opts, '--safe')
|
183
|
-
|
184
|
-
option(opts, '--stderr')
|
185
|
-
option(opts, '--[no-]color')
|
186
|
-
|
187
|
-
option(opts, '-v', '--version')
|
188
|
-
option(opts, '-V', '--verbose-version')
|
189
|
-
option(opts, '-P', '--[no-]parallel')
|
190
192
|
end
|
191
|
-
# rubocop:enable Metrics/MethodLength, Metrics/AbcSize
|
192
193
|
|
193
|
-
def
|
194
|
-
|
195
|
-
|
196
|
-
|
194
|
+
def add_general_options(opts)
|
195
|
+
section(opts, 'General Options') do
|
196
|
+
option(opts, '--init')
|
197
|
+
option(opts, '-c', '--config FILE')
|
198
|
+
option(opts, '-d', '--debug')
|
199
|
+
option(opts, '-r', '--require FILE') { |f| require_feature(f) }
|
200
|
+
option(opts, '--[no-]color')
|
201
|
+
option(opts, '-v', '--version')
|
202
|
+
option(opts, '-V', '--verbose-version')
|
197
203
|
end
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
204
|
+
end
|
205
|
+
|
206
|
+
def rainbow
|
207
|
+
@rainbow ||= begin
|
208
|
+
rainbow = Rainbow.new
|
209
|
+
rainbow.enabled = false if ARGV.include?('--no-color')
|
210
|
+
rainbow
|
202
211
|
end
|
203
212
|
end
|
204
213
|
|
205
|
-
|
206
|
-
|
214
|
+
# Creates a section of options in order to separate them visually when
|
215
|
+
# using `--help`.
|
216
|
+
def section(opts, heading, &_block)
|
217
|
+
heading = rainbow.wrap(heading).bright
|
218
|
+
opts.separator("\n#{heading}:\n")
|
219
|
+
yield
|
207
220
|
end
|
208
221
|
|
209
222
|
# Sets a value in the @options hash, based on the given long option and its
|
@@ -403,7 +416,7 @@ module RuboCop
|
|
403
416
|
only: 'Run only the given cop(s).',
|
404
417
|
only_guide_cops: ['Run only cops for rules that link to a',
|
405
418
|
'style guide.'],
|
406
|
-
except: '
|
419
|
+
except: 'Exclude the given cop(s).',
|
407
420
|
require: 'Require Ruby file.',
|
408
421
|
config: 'Specify configuration file.',
|
409
422
|
auto_gen_config: ['Generate a configuration file acting as a',
|
@@ -422,29 +435,30 @@ module RuboCop
|
|
422
435
|
'when running --auto-gen-config, except if the',
|
423
436
|
'number of files with offenses is bigger than',
|
424
437
|
'exclude-limit. Default is false.'],
|
425
|
-
exclude_limit: ['
|
426
|
-
'
|
427
|
-
"
|
438
|
+
exclude_limit: ['Set the limit for how many files to explicitly exclude.',
|
439
|
+
'If there are more files than the limit, the cop will',
|
440
|
+
"be disabled instead. Default is #{MAX_EXCL}."],
|
428
441
|
disable_uncorrectable: ['Used with --auto-correct to annotate any',
|
429
442
|
'offenses that do not support autocorrect',
|
430
443
|
'with `rubocop:todo` comments.'],
|
431
|
-
force_exclusion: ['
|
432
|
-
'
|
433
|
-
'
|
444
|
+
force_exclusion: ['Any files excluded by `Exclude` in configuration',
|
445
|
+
'files will be excluded, even if given explicitly',
|
446
|
+
'as arguments.'],
|
434
447
|
only_recognized_file_types: ['Inspect files given on the command line only if',
|
435
|
-
'they are listed in AllCops/Include parameters',
|
448
|
+
'they are listed in `AllCops/Include` parameters',
|
436
449
|
'of user configuration or default configuration.'],
|
437
450
|
ignore_disable_comments: ['Run cops even when they are disabled locally',
|
438
|
-
'
|
439
|
-
ignore_parent_exclusion: ['Prevent from inheriting AllCops/Exclude from',
|
451
|
+
'by a `rubocop:disable` directive.'],
|
452
|
+
ignore_parent_exclusion: ['Prevent from inheriting `AllCops/Exclude` from',
|
440
453
|
'parent folders.'],
|
441
454
|
force_default_config: ['Use default configuration even if configuration',
|
442
455
|
'files are present in the directory tree.'],
|
443
456
|
format: ['Choose an output formatter. This option',
|
444
457
|
'can be specified multiple times to enable',
|
445
458
|
'multiple formatters at the same time.',
|
446
|
-
|
447
|
-
|
459
|
+
*FORMATTER_OPTION_LIST.map do |item|
|
460
|
+
" #{item}#{' (default)' if item == '[p]rogress'}"
|
461
|
+
end,
|
448
462
|
' custom formatter class name'],
|
449
463
|
out: ['Write output to a file instead of STDOUT.',
|
450
464
|
'This option applies to the previously',
|
data/lib/rubocop/rake_task.rb
CHANGED
@@ -33,7 +33,7 @@ module RuboCop
|
|
33
33
|
private
|
34
34
|
|
35
35
|
def run_cli(verbose, options)
|
36
|
-
# We lazy-load
|
36
|
+
# We lazy-load RuboCop so that the task doesn't dramatically impact the
|
37
37
|
# load time of your Rakefile.
|
38
38
|
require 'rubocop'
|
39
39
|
|
data/lib/rubocop/result_cache.rb
CHANGED
@@ -6,7 +6,7 @@ require 'etc'
|
|
6
6
|
require 'zlib'
|
7
7
|
|
8
8
|
module RuboCop
|
9
|
-
# Provides functionality for caching
|
9
|
+
# Provides functionality for caching RuboCop runs.
|
10
10
|
# @api private
|
11
11
|
class ResultCache
|
12
12
|
NON_CHANGING = %i[color format formatters out debug fail_level auto_correct
|
@@ -45,7 +45,7 @@ module RuboCop
|
|
45
45
|
def remove_oldest_files(files, dirs, cache_root, verbose)
|
46
46
|
# Add 1 to half the number of files, so that we remove the file if
|
47
47
|
# there's only 1 left.
|
48
|
-
remove_count = 1 + files.length / 2
|
48
|
+
remove_count = 1 + (files.length / 2)
|
49
49
|
puts "Removing the #{remove_count} oldest files from #{cache_root}" if verbose
|
50
50
|
sorted = files.sort_by { |path| File.mtime(path) }
|
51
51
|
remove_files(sorted, dirs, remove_count)
|
@@ -170,7 +170,7 @@ module RuboCop
|
|
170
170
|
attr_accessor :source_checksum, :inhibit_cleanup
|
171
171
|
end
|
172
172
|
|
173
|
-
# The checksum of the
|
173
|
+
# The checksum of the RuboCop program running the inspection.
|
174
174
|
def rubocop_checksum
|
175
175
|
ResultCache.source_checksum ||=
|
176
176
|
begin
|
@@ -49,7 +49,7 @@ module CopHelper
|
|
49
49
|
team = RuboCop::Cop::Team.new([cop], nil, raise_error: true)
|
50
50
|
report = team.investigate(processed_source)
|
51
51
|
@last_corrector = report.correctors.first || RuboCop::Cop::Corrector.new(processed_source)
|
52
|
-
report.offenses
|
52
|
+
report.offenses.reject(&:disabled?)
|
53
53
|
end
|
54
54
|
end
|
55
55
|
|
@@ -126,7 +126,7 @@ module RuboCop
|
|
126
126
|
@offenses
|
127
127
|
end
|
128
128
|
|
129
|
-
# rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
129
|
+
# rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/CyclomaticComplexity
|
130
130
|
def expect_correction(correction, loop: true, source: nil)
|
131
131
|
if source
|
132
132
|
expected_annotations = parse_annotations(source, raise_error: false)
|
@@ -136,6 +136,8 @@ module RuboCop
|
|
136
136
|
|
137
137
|
raise '`expect_correction` must follow `expect_offense`' unless @processed_source
|
138
138
|
|
139
|
+
source = @processed_source.raw_source
|
140
|
+
|
139
141
|
iteration = 0
|
140
142
|
new_source = loop do
|
141
143
|
iteration += 1
|
@@ -155,9 +157,11 @@ module RuboCop
|
|
155
157
|
_investigate(cop, @processed_source)
|
156
158
|
end
|
157
159
|
|
160
|
+
raise 'Use `expect_no_corrections` if the code will not change' if new_source == source
|
161
|
+
|
158
162
|
expect(new_source).to eq(correction)
|
159
163
|
end
|
160
|
-
# rubocop:enable Metrics/AbcSize, Metrics/MethodLength
|
164
|
+
# rubocop:enable Metrics/AbcSize, Metrics/MethodLength, Metrics/CyclomaticComplexity
|
161
165
|
|
162
166
|
def expect_no_corrections
|
163
167
|
raise '`expect_no_corrections` must follow `expect_offense`' unless @processed_source
|
@@ -0,0 +1,90 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec::Support.require_rspec_core 'formatters/base_text_formatter'
|
4
|
+
RSpec::Support.require_rspec_core 'formatters/console_codes'
|
5
|
+
|
6
|
+
module RuboCop
|
7
|
+
module RSpec
|
8
|
+
# RSpec formatter for use with running `rake spec` in parallel. This formatter
|
9
|
+
# removes much of the noise from RSpec so that only the important information
|
10
|
+
# will be surfaced by test-queue.
|
11
|
+
# It also adds metadata to the output in order to more easily find the text
|
12
|
+
# needed for outputting after the parallel run completes.
|
13
|
+
class ParallelFormatter < ::RSpec::Core::Formatters::BaseTextFormatter
|
14
|
+
::RSpec::Core::Formatters.register self, :dump_pending, :dump_failures, :dump_summary
|
15
|
+
|
16
|
+
# Don't show pending tests
|
17
|
+
def dump_pending(*); end
|
18
|
+
|
19
|
+
# The BEGIN/END comments are used by `spec_runner.rake` to determine what
|
20
|
+
# output goes where in the final parallelized output, and should not be
|
21
|
+
# removed!
|
22
|
+
def dump_failures(notification)
|
23
|
+
return if notification.failure_notifications.empty?
|
24
|
+
|
25
|
+
output.puts '# FAILURES BEGIN'
|
26
|
+
notification.failure_notifications.each do |failure|
|
27
|
+
output.puts failure.fully_formatted('*', colorizer)
|
28
|
+
end
|
29
|
+
output.puts
|
30
|
+
output.puts '# FAILURES END'
|
31
|
+
end
|
32
|
+
|
33
|
+
def dump_summary(summary)
|
34
|
+
output_summary(summary)
|
35
|
+
output_rerun_commands(summary)
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def colorizer
|
41
|
+
@colorizer ||= ::RSpec::Core::Formatters::ConsoleCodes
|
42
|
+
end
|
43
|
+
|
44
|
+
# The BEGIN/END comments are used by `spec_runner.rake` to determine what
|
45
|
+
# output goes where in the final parallelized output, and should not be
|
46
|
+
# removed!
|
47
|
+
def output_summary(summary)
|
48
|
+
output.puts '# SUMMARY BEGIN'
|
49
|
+
output.puts colorize_summary(summary)
|
50
|
+
output.puts '# SUMMARY END'
|
51
|
+
end
|
52
|
+
|
53
|
+
def colorize_summary(summary)
|
54
|
+
totals = totals(summary)
|
55
|
+
|
56
|
+
if summary.failure_count.positive? || summary.errors_outside_of_examples_count.positive?
|
57
|
+
colorizer.wrap(totals, ::RSpec.configuration.failure_color)
|
58
|
+
else
|
59
|
+
colorizer.wrap(totals, ::RSpec.configuration.success_color)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
# The BEGIN/END comments are used by `spec_runner.rake` to determine what
|
64
|
+
# output goes where in the final parallelized output, and should not be
|
65
|
+
# removed!
|
66
|
+
def output_rerun_commands(summary)
|
67
|
+
output.puts '# RERUN BEGIN'
|
68
|
+
output.puts summary.colorized_rerun_commands.lines[3..-1].join
|
69
|
+
output.puts '# RERUN END'
|
70
|
+
end
|
71
|
+
|
72
|
+
def totals(summary)
|
73
|
+
output = pluralize(summary.example_count, 'example')
|
74
|
+
output += ", #{summary.pending_count} pending" if summary.pending_count.positive?
|
75
|
+
output += ", #{pluralize(summary.failure_count, 'failure')}"
|
76
|
+
|
77
|
+
if summary.errors_outside_of_examples_count.positive?
|
78
|
+
error_count = pluralize(summary.errors_outside_of_examples_count, 'error')
|
79
|
+
output += ", #{error_count} occurred outside of examples"
|
80
|
+
end
|
81
|
+
|
82
|
+
output
|
83
|
+
end
|
84
|
+
|
85
|
+
def pluralize(*args)
|
86
|
+
::RSpec::Core::Formatters::Helpers.pluralize(*args)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
data/lib/rubocop/runner.rb
CHANGED
@@ -60,7 +60,7 @@ module RuboCop
|
|
60
60
|
|
61
61
|
private
|
62
62
|
|
63
|
-
# Warms up the RuboCop cache by forking a suitable number of
|
63
|
+
# Warms up the RuboCop cache by forking a suitable number of RuboCop
|
64
64
|
# instances that each inspects its allotted group of files.
|
65
65
|
def warm_cache(target_files)
|
66
66
|
puts 'Running parallel inspection' if @options[:debug]
|
@@ -216,8 +216,7 @@ module RuboCop
|
|
216
216
|
def cached_run?
|
217
217
|
@cached_run ||=
|
218
218
|
(@options[:cache] == 'true' ||
|
219
|
-
@options[:cache] != 'false' &&
|
220
|
-
@config_store.for_pwd.for_all_cops['UseCache']) &&
|
219
|
+
(@options[:cache] != 'false' && @config_store.for_pwd.for_all_cops['UseCache'])) &&
|
221
220
|
# When running --auto-gen-config, there's some processing done in the
|
222
221
|
# cops related to calculating the Max parameters for Metrics cops. We
|
223
222
|
# need to do that processing and cannot use caching.
|
@@ -95,7 +95,7 @@ module RuboCop
|
|
95
95
|
|
96
96
|
def wanted_dir_patterns(base_dir, exclude_pattern, flags)
|
97
97
|
base_dir = base_dir.gsub('/{}/', '/\{}/')
|
98
|
-
dirs = Dir.glob(File.join(base_dir.gsub('/**/', '/\**/'), '*/'), flags)
|
98
|
+
dirs = Dir.glob(File.join(base_dir.gsub('/*/', '/\*/').gsub('/**/', '/\**/'), '*/'), flags)
|
99
99
|
.reject do |dir|
|
100
100
|
next true if dir.end_with?('/./', '/../')
|
101
101
|
next true if File.fnmatch?(exclude_pattern, dir, flags)
|
data/lib/rubocop/version.rb
CHANGED
data/lib/rubocop.rb
CHANGED
@@ -263,6 +263,7 @@ require_relative 'rubocop/cop/layout/trailing_whitespace'
|
|
263
263
|
require_relative 'rubocop/cop/lint/ambiguous_assignment'
|
264
264
|
require_relative 'rubocop/cop/lint/ambiguous_block_association'
|
265
265
|
require_relative 'rubocop/cop/lint/ambiguous_operator'
|
266
|
+
require_relative 'rubocop/cop/lint/ambiguous_operator_precedence'
|
266
267
|
require_relative 'rubocop/cop/lint/ambiguous_range'
|
267
268
|
require_relative 'rubocop/cop/lint/ambiguous_regexp_literal'
|
268
269
|
require_relative 'rubocop/cop/lint/assignment_in_condition'
|
@@ -306,8 +307,9 @@ require_relative 'rubocop/cop/lint/hash_compare_by_identity'
|
|
306
307
|
require_relative 'rubocop/cop/lint/heredoc_method_call_position'
|
307
308
|
require_relative 'rubocop/cop/lint/identity_comparison'
|
308
309
|
require_relative 'rubocop/cop/lint/implicit_string_concatenation'
|
309
|
-
require_relative 'rubocop/cop/lint/
|
310
|
+
require_relative 'rubocop/cop/lint/incompatible_io_select_with_fiber_scheduler'
|
310
311
|
require_relative 'rubocop/cop/lint/ineffective_access_modifier'
|
312
|
+
require_relative 'rubocop/cop/lint/inherit_exception'
|
311
313
|
require_relative 'rubocop/cop/lint/interpolation_check'
|
312
314
|
require_relative 'rubocop/cop/lint/lambda_without_literal_block'
|
313
315
|
require_relative 'rubocop/cop/lint/literal_as_condition'
|
@@ -344,6 +346,7 @@ require_relative 'rubocop/cop/lint/redundant_with_index'
|
|
344
346
|
require_relative 'rubocop/cop/lint/redundant_with_object'
|
345
347
|
require_relative 'rubocop/cop/lint/regexp_as_condition'
|
346
348
|
require_relative 'rubocop/cop/lint/require_parentheses'
|
349
|
+
require_relative 'rubocop/cop/lint/require_relative_self_path'
|
347
350
|
require_relative 'rubocop/cop/lint/rescue_exception'
|
348
351
|
require_relative 'rubocop/cop/lint/rescue_type'
|
349
352
|
require_relative 'rubocop/cop/lint/return_in_void_context'
|
@@ -510,6 +513,7 @@ require_relative 'rubocop/cop/style/line_end_concatenation'
|
|
510
513
|
require_relative 'rubocop/cop/style/method_call_without_args_parentheses'
|
511
514
|
require_relative 'rubocop/cop/style/method_call_with_args_parentheses'
|
512
515
|
require_relative 'rubocop/cop/style/multiline_in_pattern_then'
|
516
|
+
require_relative 'rubocop/cop/style/numbered_parameters'
|
513
517
|
require_relative 'rubocop/cop/style/redundant_assignment'
|
514
518
|
require_relative 'rubocop/cop/style/redundant_fetch_block'
|
515
519
|
require_relative 'rubocop/cop/style/redundant_file_extension_in_require'
|
@@ -546,6 +550,7 @@ require_relative 'rubocop/cop/style/nil_comparison'
|
|
546
550
|
require_relative 'rubocop/cop/style/nil_lambda'
|
547
551
|
require_relative 'rubocop/cop/style/non_nil_check'
|
548
552
|
require_relative 'rubocop/cop/style/not'
|
553
|
+
require_relative 'rubocop/cop/style/numbered_parameters_limit'
|
549
554
|
require_relative 'rubocop/cop/style/numeric_literals'
|
550
555
|
require_relative 'rubocop/cop/style/numeric_literal_prefix'
|
551
556
|
require_relative 'rubocop/cop/style/numeric_predicate'
|
@@ -586,6 +591,7 @@ require_relative 'rubocop/cop/style/rescue_standard_error'
|
|
586
591
|
require_relative 'rubocop/cop/style/return_nil'
|
587
592
|
require_relative 'rubocop/cop/style/safe_navigation'
|
588
593
|
require_relative 'rubocop/cop/style/sample'
|
594
|
+
require_relative 'rubocop/cop/style/select_by_regexp'
|
589
595
|
require_relative 'rubocop/cop/style/self_assignment'
|
590
596
|
require_relative 'rubocop/cop/style/semicolon'
|
591
597
|
require_relative 'rubocop/cop/style/send'
|
@@ -633,6 +639,7 @@ require_relative 'rubocop/cop/style/yoda_condition'
|
|
633
639
|
require_relative 'rubocop/cop/style/zero_length_predicate'
|
634
640
|
|
635
641
|
require_relative 'rubocop/cop/security/eval'
|
642
|
+
require_relative 'rubocop/cop/security/io_methods'
|
636
643
|
require_relative 'rubocop/cop/security/json_load'
|
637
644
|
require_relative 'rubocop/cop/security/marshal_load'
|
638
645
|
require_relative 'rubocop/cop/security/open'
|