rubocop 0.85.0 → 0.88.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 +25 -17
- data/bin/rubocop-profile +31 -0
- data/config/default.yml +132 -11
- data/lib/rubocop.rb +17 -1
- data/lib/rubocop/cli.rb +2 -4
- data/lib/rubocop/cli/command/auto_genenerate_config.rb +42 -7
- data/lib/rubocop/cli/command/init_dotfile.rb +1 -1
- data/lib/rubocop/cli/command/show_cops.rb +1 -1
- data/lib/rubocop/config.rb +1 -1
- data/lib/rubocop/config_loader.rb +39 -67
- data/lib/rubocop/config_loader_resolver.rb +1 -1
- data/lib/rubocop/config_obsoletion.rb +0 -1
- data/lib/rubocop/config_store.rb +4 -0
- data/lib/rubocop/cop/autocorrect_logic.rb +14 -24
- data/lib/rubocop/cop/badge.rb +1 -1
- data/lib/rubocop/cop/base.rb +407 -0
- data/lib/rubocop/cop/bundler/insecure_protocol_source.rb +10 -20
- data/lib/rubocop/cop/commissioner.rb +48 -50
- data/lib/rubocop/cop/cop.rb +91 -235
- data/lib/rubocop/cop/corrector.rb +38 -115
- data/lib/rubocop/cop/correctors/multiline_literal_brace_corrector.rb +26 -0
- data/lib/rubocop/cop/gemspec/required_ruby_version.rb +7 -2
- data/lib/rubocop/cop/gemspec/ruby_version_globals_usage.rb +1 -1
- data/lib/rubocop/cop/generator.rb +1 -1
- data/lib/rubocop/cop/generator/configuration_injector.rb +1 -1
- data/lib/rubocop/cop/internal_affairs/node_type_predicate.rb +11 -14
- data/lib/rubocop/cop/layout/case_indentation.rb +18 -19
- data/lib/rubocop/cop/layout/class_structure.rb +2 -37
- data/lib/rubocop/cop/layout/comment_indentation.rb +3 -3
- data/lib/rubocop/cop/layout/empty_comment.rb +1 -1
- data/lib/rubocop/cop/layout/empty_lines_around_access_modifier.rb +1 -0
- data/lib/rubocop/cop/layout/empty_lines_around_attribute_accessor.rb +3 -8
- data/lib/rubocop/cop/layout/end_alignment.rb +3 -2
- data/lib/rubocop/cop/layout/end_of_line.rb +1 -1
- data/lib/rubocop/cop/layout/first_argument_indentation.rb +5 -1
- data/lib/rubocop/cop/layout/first_array_element_line_break.rb +1 -1
- data/lib/rubocop/cop/layout/hash_alignment.rb +2 -3
- data/lib/rubocop/cop/layout/heredoc_indentation.rb +1 -1
- data/lib/rubocop/cop/layout/multiline_block_layout.rb +17 -7
- data/lib/rubocop/cop/layout/space_after_colon.rb +1 -1
- data/lib/rubocop/cop/layout/space_around_block_parameters.rb +22 -27
- data/lib/rubocop/cop/layout/space_around_keyword.rb +2 -2
- data/lib/rubocop/cop/layout/space_around_method_call_operator.rb +27 -68
- data/lib/rubocop/cop/layout/space_around_operators.rb +1 -1
- data/lib/rubocop/cop/layout/space_before_block_braces.rb +14 -0
- data/lib/rubocop/cop/layout/space_inside_array_literal_brackets.rb +4 -3
- data/lib/rubocop/cop/layout/space_inside_block_braces.rb +1 -1
- data/lib/rubocop/cop/layout/space_inside_hash_literal_braces.rb +2 -2
- data/lib/rubocop/cop/legacy/corrections_proxy.rb +49 -0
- data/lib/rubocop/cop/legacy/corrector.rb +29 -0
- data/lib/rubocop/cop/lint/constant_resolution.rb +89 -0
- data/lib/rubocop/cop/lint/deprecated_open_ssl_constant.rb +4 -4
- data/lib/rubocop/cop/lint/disjunctive_assignment_in_constructor.rb +8 -2
- data/lib/rubocop/cop/lint/duplicate_elsif_condition.rb +39 -0
- data/lib/rubocop/cop/lint/duplicate_methods.rb +2 -2
- data/lib/rubocop/cop/lint/float_out_of_range.rb +1 -1
- data/lib/rubocop/cop/lint/format_parameter_mismatch.rb +38 -2
- data/lib/rubocop/cop/lint/implicit_string_concatenation.rb +3 -2
- data/lib/rubocop/cop/lint/interpolation_check.rb +13 -0
- data/lib/rubocop/cop/lint/literal_as_condition.rb +11 -1
- data/lib/rubocop/cop/lint/mixed_regexp_capture_types.rb +8 -1
- data/lib/rubocop/cop/lint/nested_method_definition.rb +14 -20
- data/lib/rubocop/cop/lint/non_deterministic_require_order.rb +69 -2
- data/lib/rubocop/cop/lint/parentheses_as_grouped_expression.rb +8 -3
- data/lib/rubocop/cop/lint/percent_string_array.rb +1 -1
- data/lib/rubocop/cop/lint/percent_symbol_array.rb +1 -1
- data/lib/rubocop/cop/lint/raise_exception.rb +12 -4
- data/lib/rubocop/cop/lint/rand_one.rb +1 -1
- data/lib/rubocop/cop/lint/redundant_cop_disable_directive.rb +31 -25
- data/lib/rubocop/cop/lint/redundant_splat_expansion.rb +2 -2
- data/lib/rubocop/cop/lint/regexp_as_condition.rb +6 -0
- data/lib/rubocop/cop/lint/safe_navigation_with_empty.rb +9 -1
- data/lib/rubocop/cop/lint/suppressed_exception.rb +1 -1
- data/lib/rubocop/cop/lint/syntax.rb +11 -26
- data/lib/rubocop/cop/lint/unused_method_argument.rb +1 -1
- data/lib/rubocop/cop/lint/useless_access_modifier.rb +1 -1
- data/lib/rubocop/cop/metrics/block_length.rb +22 -0
- data/lib/rubocop/cop/metrics/class_length.rb +25 -2
- data/lib/rubocop/cop/metrics/cyclomatic_complexity.rb +35 -3
- data/lib/rubocop/cop/metrics/method_length.rb +23 -0
- data/lib/rubocop/cop/metrics/module_length.rb +25 -2
- data/lib/rubocop/cop/metrics/utils/abc_size_calculator.rb +1 -1
- data/lib/rubocop/cop/metrics/utils/code_length_calculator.rb +129 -0
- data/lib/rubocop/cop/metrics/utils/iterating_block.rb +61 -0
- data/lib/rubocop/cop/mixin/allowed_methods.rb +19 -0
- data/lib/rubocop/cop/mixin/auto_corrector.rb +12 -0
- data/lib/rubocop/cop/mixin/code_length.rb +4 -0
- data/lib/rubocop/cop/mixin/configurable_formatting.rb +1 -1
- data/lib/rubocop/cop/mixin/configurable_naming.rb +1 -1
- data/lib/rubocop/cop/mixin/documentation_comment.rb +2 -2
- data/lib/rubocop/cop/mixin/end_keyword_alignment.rb +1 -1
- data/lib/rubocop/cop/mixin/enforce_superclass.rb +3 -1
- data/lib/rubocop/cop/mixin/first_element_line_break.rb +1 -1
- data/lib/rubocop/cop/mixin/multiline_expression_indentation.rb +1 -1
- data/lib/rubocop/cop/mixin/nil_methods.rb +3 -5
- data/lib/rubocop/cop/mixin/ordered_gem_node.rb +6 -1
- data/lib/rubocop/cop/mixin/parentheses.rb +1 -2
- data/lib/rubocop/cop/mixin/preceding_following_alignment.rb +1 -1
- data/lib/rubocop/cop/mixin/range_help.rb +1 -1
- data/lib/rubocop/cop/mixin/regexp_literal_help.rb +27 -0
- data/lib/rubocop/cop/mixin/statement_modifier.rb +3 -3
- data/lib/rubocop/cop/mixin/string_literals_help.rb +1 -1
- data/lib/rubocop/cop/mixin/surrounding_space.rb +10 -5
- data/lib/rubocop/cop/mixin/too_many_lines.rb +3 -13
- data/lib/rubocop/cop/mixin/trailing_comma.rb +1 -1
- data/lib/rubocop/cop/mixin/uncommunicative_name.rb +6 -4
- data/lib/rubocop/cop/mixin/visibility_help.rb +50 -0
- data/lib/rubocop/cop/naming/ascii_identifiers.rb +27 -4
- data/lib/rubocop/cop/naming/binary_operator_parameter_name.rb +3 -3
- data/lib/rubocop/cop/naming/file_name.rb +1 -3
- data/lib/rubocop/cop/naming/heredoc_delimiter_naming.rb +1 -1
- data/lib/rubocop/cop/naming/method_name.rb +1 -1
- data/lib/rubocop/cop/naming/method_parameter_name.rb +1 -1
- data/lib/rubocop/cop/naming/predicate_name.rb +3 -5
- data/lib/rubocop/cop/naming/variable_name.rb +1 -1
- data/lib/rubocop/cop/naming/variable_number.rb +1 -1
- data/lib/rubocop/cop/offense.rb +16 -2
- data/lib/rubocop/cop/registry.rb +62 -7
- data/lib/rubocop/cop/style/accessor_grouping.rb +147 -0
- data/lib/rubocop/cop/style/array_coercion.rb +63 -0
- data/lib/rubocop/cop/style/auto_resource_cleanup.rb +3 -2
- data/lib/rubocop/cop/style/bare_percent_literals.rb +1 -1
- data/lib/rubocop/cop/style/bisected_attr_accessor.rb +146 -0
- data/lib/rubocop/cop/style/block_delimiters.rb +2 -4
- data/lib/rubocop/cop/style/case_like_if.rb +217 -0
- data/lib/rubocop/cop/style/class_and_module_children.rb +1 -1
- data/lib/rubocop/cop/style/class_vars.rb +21 -0
- data/lib/rubocop/cop/style/command_literal.rb +1 -1
- data/lib/rubocop/cop/style/commented_keyword.rb +5 -2
- data/lib/rubocop/cop/style/conditional_assignment.rb +2 -2
- data/lib/rubocop/cop/style/copyright.rb +3 -3
- data/lib/rubocop/cop/style/date_time.rb +1 -1
- data/lib/rubocop/cop/style/dir.rb +2 -2
- data/lib/rubocop/cop/style/disable_cops_within_source_code_directive.rb +1 -1
- data/lib/rubocop/cop/style/documentation.rb +2 -2
- data/lib/rubocop/cop/style/empty_case_condition.rb +8 -6
- data/lib/rubocop/cop/style/empty_literal.rb +5 -5
- data/lib/rubocop/cop/style/encoding.rb +1 -1
- data/lib/rubocop/cop/style/expand_path_arguments.rb +2 -2
- data/lib/rubocop/cop/style/exponential_notation.rb +8 -10
- data/lib/rubocop/cop/style/float_division.rb +7 -10
- data/lib/rubocop/cop/style/format_string_token.rb +5 -5
- data/lib/rubocop/cop/style/frozen_string_literal_comment.rb +1 -1
- data/lib/rubocop/cop/style/hash_as_last_array_item.rb +62 -0
- data/lib/rubocop/cop/style/hash_like_case.rb +76 -0
- data/lib/rubocop/cop/style/identical_conditional_branches.rb +1 -1
- data/lib/rubocop/cop/style/if_inside_else.rb +1 -1
- data/lib/rubocop/cop/style/if_unless_modifier.rb +11 -11
- data/lib/rubocop/cop/style/if_unless_modifier_of_if_unless.rb +12 -0
- data/lib/rubocop/cop/style/inverse_methods.rb +1 -1
- data/lib/rubocop/cop/style/ip_addresses.rb +1 -1
- data/lib/rubocop/cop/style/missing_else.rb +1 -11
- data/lib/rubocop/cop/style/multiline_block_chain.rb +10 -1
- data/lib/rubocop/cop/style/multiline_if_then.rb +1 -1
- data/lib/rubocop/cop/style/multiline_ternary_operator.rb +17 -6
- data/lib/rubocop/cop/style/mutable_constant.rb +4 -4
- data/lib/rubocop/cop/style/nested_parenthesized_calls.rb +2 -5
- data/lib/rubocop/cop/style/nested_ternary_operator.rb +27 -0
- data/lib/rubocop/cop/style/next.rb +2 -2
- data/lib/rubocop/cop/style/numeric_literal_prefix.rb +2 -2
- data/lib/rubocop/cop/style/numeric_predicate.rb +3 -4
- data/lib/rubocop/cop/style/parallel_assignment.rb +3 -3
- data/lib/rubocop/cop/style/percent_literal_delimiters.rb +1 -1
- data/lib/rubocop/cop/style/proc.rb +1 -1
- data/lib/rubocop/cop/style/random_with_offset.rb +4 -10
- data/lib/rubocop/cop/style/redundant_assignment.rb +117 -0
- data/lib/rubocop/cop/style/redundant_conditional.rb +4 -3
- data/lib/rubocop/cop/style/redundant_exception.rb +14 -10
- data/lib/rubocop/cop/style/redundant_fetch_block.rb +122 -0
- data/lib/rubocop/cop/style/redundant_file_extension_in_require.rb +50 -0
- data/lib/rubocop/cop/style/redundant_freeze.rb +1 -1
- data/lib/rubocop/cop/style/redundant_parentheses.rb +8 -2
- data/lib/rubocop/cop/style/redundant_percent_q.rb +2 -2
- data/lib/rubocop/cop/style/redundant_regexp_character_class.rb +4 -3
- data/lib/rubocop/cop/style/redundant_regexp_escape.rb +14 -23
- data/lib/rubocop/cop/style/redundant_self.rb +6 -9
- data/lib/rubocop/cop/style/redundant_sort.rb +3 -2
- data/lib/rubocop/cop/style/rescue_standard_error.rb +1 -1
- data/lib/rubocop/cop/style/sample.rb +1 -1
- data/lib/rubocop/cop/style/semicolon.rb +1 -1
- data/lib/rubocop/cop/style/signal_exception.rb +1 -1
- data/lib/rubocop/cop/style/stabby_lambda_parentheses.rb +3 -2
- data/lib/rubocop/cop/style/stderr_puts.rb +1 -1
- data/lib/rubocop/cop/style/struct_inheritance.rb +23 -2
- data/lib/rubocop/cop/style/symbol_array.rb +5 -5
- data/lib/rubocop/cop/style/symbol_proc.rb +1 -1
- data/lib/rubocop/cop/style/ternary_parentheses.rb +1 -1
- data/lib/rubocop/cop/style/trailing_method_end_statement.rb +9 -32
- data/lib/rubocop/cop/style/trivial_accessors.rb +8 -7
- data/lib/rubocop/cop/style/word_array.rb +1 -1
- data/lib/rubocop/cop/style/yoda_condition.rb +18 -1
- data/lib/rubocop/cop/style/zero_length_predicate.rb +2 -2
- data/lib/rubocop/cop/team.rb +105 -81
- data/lib/rubocop/cop/util.rb +2 -2
- data/lib/rubocop/cop/utils/format_string.rb +19 -2
- data/lib/rubocop/cop/variable_force/variable.rb +5 -3
- data/lib/rubocop/file_finder.rb +12 -12
- data/lib/rubocop/formatter/disabled_config_formatter.rb +2 -2
- data/lib/rubocop/formatter/formatter_set.rb +1 -1
- data/lib/rubocop/name_similarity.rb +7 -3
- data/lib/rubocop/options.rb +15 -8
- data/lib/rubocop/path_util.rb +4 -19
- data/lib/rubocop/platform.rb +1 -1
- data/lib/rubocop/rake_task.rb +6 -9
- data/lib/rubocop/result_cache.rb +12 -8
- data/lib/rubocop/rspec/cop_helper.rb +4 -4
- data/lib/rubocop/rspec/expect_offense.rb +65 -21
- data/lib/rubocop/rspec/shared_contexts.rb +19 -16
- data/lib/rubocop/runner.rb +34 -33
- data/lib/rubocop/target_finder.rb +3 -3
- data/lib/rubocop/target_ruby.rb +2 -2
- data/lib/rubocop/version.rb +1 -1
- metadata +34 -9
- data/lib/rubocop/cop/mixin/classish_length.rb +0 -37
data/lib/rubocop.rb
CHANGED
@@ -30,6 +30,7 @@ require_relative 'rubocop/cop/ignored_node'
|
|
30
30
|
require_relative 'rubocop/cop/autocorrect_logic'
|
31
31
|
require_relative 'rubocop/cop/badge'
|
32
32
|
require_relative 'rubocop/cop/registry'
|
33
|
+
require_relative 'rubocop/cop/base'
|
33
34
|
require_relative 'rubocop/cop/cop'
|
34
35
|
require_relative 'rubocop/cop/commissioner'
|
35
36
|
require_relative 'rubocop/cop/corrector'
|
@@ -52,11 +53,12 @@ require_relative 'rubocop/cop/mixin/annotation_comment'
|
|
52
53
|
require_relative 'rubocop/cop/mixin/array_min_size'
|
53
54
|
require_relative 'rubocop/cop/mixin/array_syntax'
|
54
55
|
require_relative 'rubocop/cop/mixin/alignment'
|
56
|
+
require_relative 'rubocop/cop/mixin/allowed_methods'
|
57
|
+
require_relative 'rubocop/cop/mixin/auto_corrector'
|
55
58
|
require_relative 'rubocop/cop/mixin/check_assignment'
|
56
59
|
require_relative 'rubocop/cop/mixin/check_line_breakable'
|
57
60
|
require_relative 'rubocop/cop/mixin/configurable_max'
|
58
61
|
require_relative 'rubocop/cop/mixin/code_length' # relies on configurable_max
|
59
|
-
require_relative 'rubocop/cop/mixin/classish_length' # relies on code_length
|
60
62
|
require_relative 'rubocop/cop/mixin/configurable_enforced_style'
|
61
63
|
require_relative 'rubocop/cop/mixin/configurable_formatting'
|
62
64
|
require_relative 'rubocop/cop/mixin/configurable_naming'
|
@@ -113,6 +115,7 @@ require_relative 'rubocop/cop/mixin/trailing_body'
|
|
113
115
|
require_relative 'rubocop/cop/mixin/trailing_comma'
|
114
116
|
require_relative 'rubocop/cop/mixin/uncommunicative_name'
|
115
117
|
require_relative 'rubocop/cop/mixin/unused_argument'
|
118
|
+
require_relative 'rubocop/cop/mixin/visibility_help'
|
116
119
|
|
117
120
|
require_relative 'rubocop/cop/utils/format_string'
|
118
121
|
|
@@ -242,11 +245,13 @@ require_relative 'rubocop/cop/lint/assignment_in_condition'
|
|
242
245
|
require_relative 'rubocop/cop/lint/big_decimal_new'
|
243
246
|
require_relative 'rubocop/cop/lint/boolean_symbol'
|
244
247
|
require_relative 'rubocop/cop/lint/circular_argument_reference'
|
248
|
+
require_relative 'rubocop/cop/lint/constant_resolution'
|
245
249
|
require_relative 'rubocop/cop/lint/debugger'
|
246
250
|
require_relative 'rubocop/cop/lint/deprecated_class_methods'
|
247
251
|
require_relative 'rubocop/cop/lint/deprecated_open_ssl_constant'
|
248
252
|
require_relative 'rubocop/cop/lint/disjunctive_assignment_in_constructor'
|
249
253
|
require_relative 'rubocop/cop/lint/duplicate_case_condition'
|
254
|
+
require_relative 'rubocop/cop/lint/duplicate_elsif_condition'
|
250
255
|
require_relative 'rubocop/cop/lint/duplicate_hash_key'
|
251
256
|
require_relative 'rubocop/cop/lint/duplicate_methods'
|
252
257
|
require_relative 'rubocop/cop/lint/each_with_object_argument'
|
@@ -321,9 +326,11 @@ require_relative 'rubocop/cop/lint/useless_else_without_rescue'
|
|
321
326
|
require_relative 'rubocop/cop/lint/useless_setter_call'
|
322
327
|
require_relative 'rubocop/cop/lint/void'
|
323
328
|
|
329
|
+
require_relative 'rubocop/cop/metrics/utils/iterating_block'
|
324
330
|
require_relative 'rubocop/cop/metrics/cyclomatic_complexity'
|
325
331
|
# relies on cyclomatic_complexity
|
326
332
|
require_relative 'rubocop/cop/metrics/utils/abc_size_calculator'
|
333
|
+
require_relative 'rubocop/cop/metrics/utils/code_length_calculator'
|
327
334
|
require_relative 'rubocop/cop/metrics/abc_size'
|
328
335
|
require_relative 'rubocop/cop/metrics/block_length'
|
329
336
|
require_relative 'rubocop/cop/metrics/block_nesting'
|
@@ -351,17 +358,21 @@ require_relative 'rubocop/cop/naming/variable_name'
|
|
351
358
|
require_relative 'rubocop/cop/naming/variable_number'
|
352
359
|
|
353
360
|
require_relative 'rubocop/cop/style/access_modifier_declarations'
|
361
|
+
require_relative 'rubocop/cop/style/accessor_grouping'
|
354
362
|
require_relative 'rubocop/cop/style/alias'
|
355
363
|
require_relative 'rubocop/cop/style/and_or'
|
364
|
+
require_relative 'rubocop/cop/style/array_coercion'
|
356
365
|
require_relative 'rubocop/cop/style/array_join'
|
357
366
|
require_relative 'rubocop/cop/style/ascii_comments'
|
358
367
|
require_relative 'rubocop/cop/style/attr'
|
359
368
|
require_relative 'rubocop/cop/style/auto_resource_cleanup'
|
360
369
|
require_relative 'rubocop/cop/style/bare_percent_literals'
|
361
370
|
require_relative 'rubocop/cop/style/begin_block'
|
371
|
+
require_relative 'rubocop/cop/style/bisected_attr_accessor'
|
362
372
|
require_relative 'rubocop/cop/style/block_comments'
|
363
373
|
require_relative 'rubocop/cop/style/block_delimiters'
|
364
374
|
require_relative 'rubocop/cop/style/case_equality'
|
375
|
+
require_relative 'rubocop/cop/style/case_like_if'
|
365
376
|
require_relative 'rubocop/cop/style/character_literal'
|
366
377
|
require_relative 'rubocop/cop/style/class_and_module_children'
|
367
378
|
require_relative 'rubocop/cop/style/class_check'
|
@@ -405,7 +416,9 @@ require_relative 'rubocop/cop/style/format_string_token'
|
|
405
416
|
require_relative 'rubocop/cop/style/frozen_string_literal_comment'
|
406
417
|
require_relative 'rubocop/cop/style/global_vars'
|
407
418
|
require_relative 'rubocop/cop/style/guard_clause'
|
419
|
+
require_relative 'rubocop/cop/style/hash_as_last_array_item'
|
408
420
|
require_relative 'rubocop/cop/style/hash_each_methods'
|
421
|
+
require_relative 'rubocop/cop/style/hash_like_case'
|
409
422
|
require_relative 'rubocop/cop/style/hash_syntax'
|
410
423
|
require_relative 'rubocop/cop/style/hash_transform_keys'
|
411
424
|
require_relative 'rubocop/cop/style/hash_transform_values'
|
@@ -424,6 +437,9 @@ require_relative 'rubocop/cop/style/lambda_call'
|
|
424
437
|
require_relative 'rubocop/cop/style/line_end_concatenation'
|
425
438
|
require_relative 'rubocop/cop/style/method_call_without_args_parentheses'
|
426
439
|
require_relative 'rubocop/cop/style/method_call_with_args_parentheses'
|
440
|
+
require_relative 'rubocop/cop/style/redundant_assignment'
|
441
|
+
require_relative 'rubocop/cop/style/redundant_fetch_block'
|
442
|
+
require_relative 'rubocop/cop/style/redundant_file_extension_in_require'
|
427
443
|
require_relative 'rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses'
|
428
444
|
require_relative 'rubocop/cop/style/method_call_with_args_parentheses/require_parentheses'
|
429
445
|
require_relative 'rubocop/cop/style/method_called_on_do_end_block'
|
data/lib/rubocop/cli.rb
CHANGED
@@ -75,7 +75,7 @@ module RuboCop
|
|
75
75
|
|
76
76
|
def validate_options_vs_config
|
77
77
|
if @options[:parallel] &&
|
78
|
-
!@config_store.
|
78
|
+
!@config_store.for_pwd.for_all_cops['UseCache']
|
79
79
|
raise OptionArgumentError, '-P/--parallel uses caching to speed up ' \
|
80
80
|
'execution, so combining with AllCops: ' \
|
81
81
|
'UseCache: false is not allowed.'
|
@@ -101,11 +101,9 @@ module RuboCop
|
|
101
101
|
|
102
102
|
def set_options_to_config_loader
|
103
103
|
ConfigLoader.debug = @options[:debug]
|
104
|
-
ConfigLoader.auto_gen_config = @options[:auto_gen_config]
|
105
104
|
ConfigLoader.disable_pending_cops = @options[:disable_pending_cops]
|
106
105
|
ConfigLoader.enable_pending_cops = @options[:enable_pending_cops]
|
107
106
|
ConfigLoader.ignore_parent_exclusion = @options[:ignore_parent_exclusion]
|
108
|
-
ConfigLoader.options_config = @options[:config]
|
109
107
|
end
|
110
108
|
|
111
109
|
def handle_exiting_options
|
@@ -123,7 +121,7 @@ module RuboCop
|
|
123
121
|
if @options[:auto_gen_config]
|
124
122
|
formatter = 'autogenconf'
|
125
123
|
else
|
126
|
-
cfg = @config_store.
|
124
|
+
cfg = @config_store.for_pwd.for_all_cops
|
127
125
|
formatter = cfg['DefaultFormatter'] || 'progress'
|
128
126
|
end
|
129
127
|
[[formatter, @options[:output_path]]]
|
@@ -7,6 +7,8 @@ module RuboCop
|
|
7
7
|
class AutoGenerateConfig < Base
|
8
8
|
self.command_name = :auto_gen_config
|
9
9
|
|
10
|
+
AUTO_GENERATED_FILE = '.rubocop_todo.yml'
|
11
|
+
|
10
12
|
PHASE_1 = 'Phase 1 of 2: run Layout/LineLength cop'
|
11
13
|
PHASE_2 = 'Phase 2 of 2: run all cops'
|
12
14
|
|
@@ -25,10 +27,10 @@ module RuboCop
|
|
25
27
|
private
|
26
28
|
|
27
29
|
def maybe_run_line_length_cop
|
28
|
-
if !line_length_enabled?(@config_store.
|
30
|
+
if !line_length_enabled?(@config_store.for_pwd)
|
29
31
|
skip_line_length_cop(PHASE_1_DISABLED)
|
30
32
|
elsif !same_max_line_length?(
|
31
|
-
@config_store.
|
33
|
+
@config_store.for_pwd, ConfigLoader.default_configuration
|
32
34
|
)
|
33
35
|
skip_line_length_cop(PHASE_1_OVERRIDDEN)
|
34
36
|
else
|
@@ -67,7 +69,7 @@ module RuboCop
|
|
67
69
|
@options.delete(:only)
|
68
70
|
@config_store = ConfigStore.new
|
69
71
|
# Save the todo configuration of the LineLength cop.
|
70
|
-
IO.read(
|
72
|
+
IO.read(AUTO_GENERATED_FILE)
|
71
73
|
.lines
|
72
74
|
.drop_while { |line| line.start_with?('#') }
|
73
75
|
.join
|
@@ -78,7 +80,7 @@ module RuboCop
|
|
78
80
|
result = execute_runner
|
79
81
|
# This run was made with the current maximum length allowed, so append
|
80
82
|
# the saved setting for LineLength.
|
81
|
-
File.open(
|
83
|
+
File.open(AUTO_GENERATED_FILE, 'a') do |f|
|
82
84
|
f.write(line_length_contents)
|
83
85
|
end
|
84
86
|
result
|
@@ -87,18 +89,51 @@ module RuboCop
|
|
87
89
|
def reset_config_and_auto_gen_file
|
88
90
|
@config_store = ConfigStore.new
|
89
91
|
@config_store.options_config = @options[:config] if @options[:config]
|
90
|
-
File.open(
|
91
|
-
|
92
|
+
File.open(AUTO_GENERATED_FILE, 'w') {}
|
93
|
+
add_inheritance_from_auto_generated_file(@options[:config])
|
92
94
|
end
|
93
95
|
|
94
96
|
def add_formatter
|
95
97
|
@options[:formatters] << [Formatter::DisabledConfigFormatter,
|
96
|
-
|
98
|
+
AUTO_GENERATED_FILE]
|
97
99
|
end
|
98
100
|
|
99
101
|
def execute_runner
|
100
102
|
Environment.new(@options, @config_store, @paths).run(:execute_runner)
|
101
103
|
end
|
104
|
+
|
105
|
+
def add_inheritance_from_auto_generated_file(config_file)
|
106
|
+
file_string = " #{AUTO_GENERATED_FILE}"
|
107
|
+
|
108
|
+
config_file ||= ConfigLoader::DOTFILE
|
109
|
+
|
110
|
+
if File.exist?(config_file)
|
111
|
+
files = Array(ConfigLoader.load_yaml_configuration(config_file)['inherit_from'])
|
112
|
+
|
113
|
+
return if files.include?(AUTO_GENERATED_FILE)
|
114
|
+
|
115
|
+
files.unshift(AUTO_GENERATED_FILE)
|
116
|
+
file_string = "\n - " + files.join("\n - ") if files.size > 1
|
117
|
+
rubocop_yml_contents = existing_configuration(config_file)
|
118
|
+
end
|
119
|
+
|
120
|
+
write_config_file(config_file, file_string, rubocop_yml_contents)
|
121
|
+
|
122
|
+
puts "Added inheritance from `#{AUTO_GENERATED_FILE}` in `#{ConfigLoader::DOTFILE}`."
|
123
|
+
end
|
124
|
+
|
125
|
+
def existing_configuration(config_file)
|
126
|
+
IO.read(config_file, encoding: Encoding::UTF_8)
|
127
|
+
.sub(/^inherit_from: *[^\n]+/, '')
|
128
|
+
.sub(/^inherit_from: *(\n *- *[^\n]+)+/, '')
|
129
|
+
end
|
130
|
+
|
131
|
+
def write_config_file(file_name, file_string, rubocop_yml_contents)
|
132
|
+
File.open(file_name, 'w') do |f|
|
133
|
+
f.write "inherit_from:#{file_string}\n"
|
134
|
+
f.write "\n#{rubocop_yml_contents}" if /\S/.match?(rubocop_yml_contents)
|
135
|
+
end
|
136
|
+
end
|
102
137
|
end
|
103
138
|
end
|
104
139
|
end
|
@@ -27,7 +27,7 @@ module RuboCop
|
|
27
27
|
# RuboCop will start looking for the configuration file in the directory
|
28
28
|
# where the inspected file is and continue its way up to the root directory.
|
29
29
|
#
|
30
|
-
# See https://
|
30
|
+
# See https://docs.rubocop.org/rubocop/configuration
|
31
31
|
DESC
|
32
32
|
|
33
33
|
File.open(DOTFILE, 'w') do |f|
|
@@ -49,7 +49,7 @@ module RuboCop
|
|
49
49
|
|
50
50
|
def print_cop_details(cops)
|
51
51
|
cops.each do |cop|
|
52
|
-
puts '# Supports --auto-correct' if cop.
|
52
|
+
puts '# Supports --auto-correct' if cop.support_autocorrect?
|
53
53
|
puts "#{cop.cop_name}:"
|
54
54
|
puts config_lines(cop)
|
55
55
|
puts
|
data/lib/rubocop/config.rb
CHANGED
@@ -152,7 +152,7 @@ module RuboCop
|
|
152
152
|
return true if File.extname(file) == '.gemspec'
|
153
153
|
|
154
154
|
file_to_include?(file) do |pattern, relative_path, absolute_path|
|
155
|
-
|
155
|
+
/[A-Z]/.match?(pattern.to_s) &&
|
156
156
|
(match_path?(pattern, relative_path) ||
|
157
157
|
match_path?(pattern, absolute_path))
|
158
158
|
end
|
@@ -18,21 +18,19 @@ module RuboCop
|
|
18
18
|
XDG_CONFIG = 'config.yml'
|
19
19
|
RUBOCOP_HOME = File.realpath(File.join(File.dirname(__FILE__), '..', '..'))
|
20
20
|
DEFAULT_FILE = File.join(RUBOCOP_HOME, 'config', 'default.yml')
|
21
|
-
AUTO_GENERATED_FILE = '.rubocop_todo.yml'
|
22
21
|
|
23
22
|
class << self
|
24
23
|
include FileFinder
|
25
24
|
|
26
|
-
attr_accessor :debug, :
|
27
|
-
:
|
28
|
-
attr_writer :default_configuration
|
25
|
+
attr_accessor :debug, :ignore_parent_exclusion,
|
26
|
+
:disable_pending_cops, :enable_pending_cops
|
27
|
+
attr_writer :default_configuration, :project_root
|
29
28
|
|
30
29
|
alias debug? debug
|
31
|
-
alias auto_gen_config? auto_gen_config
|
32
30
|
alias ignore_parent_exclusion? ignore_parent_exclusion
|
33
31
|
|
34
32
|
def clear_options
|
35
|
-
@debug =
|
33
|
+
@debug = nil
|
36
34
|
FileFinder.root_level = nil
|
37
35
|
end
|
38
36
|
|
@@ -55,6 +53,21 @@ module RuboCop
|
|
55
53
|
Config.create(hash, path)
|
56
54
|
end
|
57
55
|
|
56
|
+
def load_yaml_configuration(absolute_path)
|
57
|
+
file_contents = read_file(absolute_path)
|
58
|
+
yaml_code = Dir.chdir(File.dirname(absolute_path)) do
|
59
|
+
ERB.new(file_contents).result
|
60
|
+
end
|
61
|
+
check_duplication(yaml_code, absolute_path)
|
62
|
+
hash = yaml_safe_load(yaml_code, absolute_path) || {}
|
63
|
+
|
64
|
+
puts "configuration from #{absolute_path}" if debug?
|
65
|
+
|
66
|
+
raise(TypeError, "Malformed configuration in #{absolute_path}") unless hash.is_a?(Hash)
|
67
|
+
|
68
|
+
hash
|
69
|
+
end
|
70
|
+
|
58
71
|
def add_missing_namespaces(path, hash)
|
59
72
|
# Using `hash.each_key` will cause the
|
60
73
|
# `can't add a new key into hash during iteration` error
|
@@ -85,7 +98,7 @@ module RuboCop
|
|
85
98
|
end
|
86
99
|
|
87
100
|
def configuration_from_file(config_file)
|
88
|
-
return
|
101
|
+
return default_configuration if config_file == DEFAULT_FILE
|
89
102
|
|
90
103
|
config = load_file(config_file)
|
91
104
|
if ignore_parent_exclusion?
|
@@ -105,15 +118,13 @@ module RuboCop
|
|
105
118
|
end
|
106
119
|
|
107
120
|
def add_excludes_from_files(config, config_file)
|
108
|
-
|
109
|
-
[find_user_dotfile, find_user_xdg_config].compact
|
121
|
+
exclusion_file = find_last_file_upwards(DOTFILE, config_file, project_root)
|
110
122
|
|
111
|
-
return
|
112
|
-
return if PathUtil.relative_path(
|
113
|
-
PathUtil.relative_path(config_file)
|
123
|
+
return unless exclusion_file
|
124
|
+
return if PathUtil.relative_path(exclusion_file) == PathUtil.relative_path(config_file)
|
114
125
|
|
115
126
|
print 'AllCops/Exclude ' if debug?
|
116
|
-
config.add_excludes_from_higher_level(load_file(
|
127
|
+
config.add_excludes_from_higher_level(load_file(exclusion_file))
|
117
128
|
end
|
118
129
|
|
119
130
|
def default_configuration
|
@@ -123,6 +134,12 @@ module RuboCop
|
|
123
134
|
end
|
124
135
|
end
|
125
136
|
|
137
|
+
# Returns the path rubocop inferred as the root of the project. No file
|
138
|
+
# searches will go past this directory.
|
139
|
+
def project_root
|
140
|
+
@project_root ||= find_project_root
|
141
|
+
end
|
142
|
+
|
126
143
|
def warn_on_pending_cops(pending_cops)
|
127
144
|
return if pending_cops.empty?
|
128
145
|
|
@@ -139,40 +156,23 @@ module RuboCop
|
|
139
156
|
warn Rainbow('For more information: https://docs.rubocop.org/rubocop/versioning.html').yellow
|
140
157
|
end
|
141
158
|
|
142
|
-
# Merges the given configuration with the default one.
|
143
|
-
# AllCops:DisabledByDefault is true, it changes the Enabled params so
|
144
|
-
# that only cops from user configuration are enabled.
|
145
|
-
# If AllCops::EnabledByDefault is true, it changes the Enabled params
|
146
|
-
# so that only cops explicitly disabled in user configuration are
|
147
|
-
# disabled.
|
159
|
+
# Merges the given configuration with the default one.
|
148
160
|
def merge_with_default(config, config_file, unset_nil: true)
|
149
161
|
resolver.merge_with_default(config, config_file, unset_nil: unset_nil)
|
150
162
|
end
|
151
163
|
|
152
|
-
|
153
|
-
file_string = " #{AUTO_GENERATED_FILE}"
|
154
|
-
|
155
|
-
config_file = options_config || DOTFILE
|
156
|
-
|
157
|
-
if File.exist?(config_file)
|
158
|
-
files = Array(load_yaml_configuration(config_file)['inherit_from'])
|
159
|
-
|
160
|
-
return if files.include?(AUTO_GENERATED_FILE)
|
161
|
-
|
162
|
-
files.unshift(AUTO_GENERATED_FILE)
|
163
|
-
file_string = "\n - " + files.join("\n - ") if files.size > 1
|
164
|
-
rubocop_yml_contents = existing_configuration(config_file)
|
165
|
-
end
|
166
|
-
|
167
|
-
write_config_file(config_file, file_string, rubocop_yml_contents)
|
164
|
+
private
|
168
165
|
|
169
|
-
|
166
|
+
def find_project_dotfile(target_dir)
|
167
|
+
find_file_upwards(DOTFILE, target_dir, project_root)
|
170
168
|
end
|
171
169
|
|
172
|
-
|
170
|
+
def find_project_root
|
171
|
+
pwd = Dir.pwd
|
172
|
+
gems_file = find_last_file_upwards('Gemfile', pwd) || find_last_file_upwards('gems.rb', pwd)
|
173
|
+
return unless gems_file
|
173
174
|
|
174
|
-
|
175
|
-
find_file_upwards(DOTFILE, target_dir)
|
175
|
+
File.dirname(gems_file)
|
176
176
|
end
|
177
177
|
|
178
178
|
def find_user_dotfile
|
@@ -196,38 +196,10 @@ module RuboCop
|
|
196
196
|
path
|
197
197
|
end
|
198
198
|
|
199
|
-
def existing_configuration(config_file)
|
200
|
-
IO.read(config_file, encoding: Encoding::UTF_8)
|
201
|
-
.sub(/^inherit_from: *[^\n]+/, '')
|
202
|
-
.sub(/^inherit_from: *(\n *- *[^\n]+)+/, '')
|
203
|
-
end
|
204
|
-
|
205
|
-
def write_config_file(file_name, file_string, rubocop_yml_contents)
|
206
|
-
File.open(file_name, 'w') do |f|
|
207
|
-
f.write "inherit_from:#{file_string}\n"
|
208
|
-
f.write "\n#{rubocop_yml_contents}" if /\S/.match?(rubocop_yml_contents)
|
209
|
-
end
|
210
|
-
end
|
211
|
-
|
212
199
|
def resolver
|
213
200
|
@resolver ||= ConfigLoaderResolver.new
|
214
201
|
end
|
215
202
|
|
216
|
-
def load_yaml_configuration(absolute_path)
|
217
|
-
file_contents = read_file(absolute_path)
|
218
|
-
yaml_code = Dir.chdir(File.dirname(absolute_path)) do
|
219
|
-
ERB.new(file_contents).result
|
220
|
-
end
|
221
|
-
check_duplication(yaml_code, absolute_path)
|
222
|
-
hash = yaml_safe_load(yaml_code, absolute_path) || {}
|
223
|
-
|
224
|
-
puts "configuration from #{absolute_path}" if debug?
|
225
|
-
|
226
|
-
raise(TypeError, "Malformed configuration in #{absolute_path}") unless hash.is_a?(Hash)
|
227
|
-
|
228
|
-
hash
|
229
|
-
end
|
230
|
-
|
231
203
|
def check_duplication(yaml_code, absolute_path)
|
232
204
|
smart_path = PathUtil.smart_path(absolute_path)
|
233
205
|
YAMLDuplicationChecker.check(yaml_code, absolute_path) do |key1, key2|
|
@@ -63,7 +63,6 @@ module RuboCop
|
|
63
63
|
'Layout/SpaceAfterControlKeyword' => 'Layout/SpaceAroundKeyword',
|
64
64
|
'Layout/SpaceBeforeModifierKeyword' => 'Layout/SpaceAroundKeyword',
|
65
65
|
'Lint/RescueWithoutErrorClass' => 'Style/RescueStandardError',
|
66
|
-
'Rails/DefaultScope' => nil,
|
67
66
|
'Style/SpaceAfterControlKeyword' => 'Layout/SpaceAroundKeyword',
|
68
67
|
'Style/SpaceBeforeModifierKeyword' => 'Layout/SpaceAroundKeyword',
|
69
68
|
'Style/TrailingComma' => 'Style/TrailingCommaInArguments, ' \
|
data/lib/rubocop/config_store.rb
CHANGED