rubocop 0.86.0 → 0.87.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (99) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/config/default.yml +46 -4
  4. data/lib/rubocop.rb +7 -1
  5. data/lib/rubocop/cli.rb +0 -2
  6. data/lib/rubocop/cli/command/auto_genenerate_config.rb +40 -5
  7. data/lib/rubocop/cli/command/show_cops.rb +1 -1
  8. data/lib/rubocop/config_loader.rb +22 -62
  9. data/lib/rubocop/config_obsoletion.rb +0 -1
  10. data/lib/rubocop/cop/autocorrect_logic.rb +13 -23
  11. data/lib/rubocop/cop/base.rb +399 -0
  12. data/lib/rubocop/cop/bundler/insecure_protocol_source.rb +10 -20
  13. data/lib/rubocop/cop/commissioner.rb +48 -50
  14. data/lib/rubocop/cop/cop.rb +85 -236
  15. data/lib/rubocop/cop/corrector.rb +38 -115
  16. data/lib/rubocop/cop/gemspec/ruby_version_globals_usage.rb +1 -1
  17. data/lib/rubocop/cop/generator.rb +1 -1
  18. data/lib/rubocop/cop/internal_affairs/node_type_predicate.rb +11 -14
  19. data/lib/rubocop/cop/layout/case_indentation.rb +18 -19
  20. data/lib/rubocop/cop/layout/empty_lines_around_attribute_accessor.rb +1 -8
  21. data/lib/rubocop/cop/layout/first_argument_indentation.rb +4 -0
  22. data/lib/rubocop/cop/layout/hash_alignment.rb +1 -2
  23. data/lib/rubocop/cop/layout/multiline_block_layout.rb +0 -1
  24. data/lib/rubocop/cop/layout/space_around_block_parameters.rb +19 -25
  25. data/lib/rubocop/cop/legacy/corrections_proxy.rb +49 -0
  26. data/lib/rubocop/cop/legacy/corrector.rb +29 -0
  27. data/lib/rubocop/cop/lint/interpolation_check.rb +13 -0
  28. data/lib/rubocop/cop/lint/nested_method_definition.rb +1 -1
  29. data/lib/rubocop/cop/lint/non_deterministic_require_order.rb +2 -2
  30. data/lib/rubocop/cop/lint/parentheses_as_grouped_expression.rb +8 -3
  31. data/lib/rubocop/cop/lint/rand_one.rb +1 -1
  32. data/lib/rubocop/cop/lint/redundant_cop_disable_directive.rb +27 -23
  33. data/lib/rubocop/cop/lint/redundant_splat_expansion.rb +2 -2
  34. data/lib/rubocop/cop/lint/safe_navigation_with_empty.rb +8 -0
  35. data/lib/rubocop/cop/lint/syntax.rb +11 -26
  36. data/lib/rubocop/cop/lint/unused_method_argument.rb +1 -1
  37. data/lib/rubocop/cop/lint/useless_access_modifier.rb +1 -1
  38. data/lib/rubocop/cop/metrics/block_length.rb +22 -0
  39. data/lib/rubocop/cop/metrics/class_length.rb +25 -2
  40. data/lib/rubocop/cop/metrics/method_length.rb +23 -0
  41. data/lib/rubocop/cop/metrics/module_length.rb +25 -2
  42. data/lib/rubocop/cop/metrics/utils/code_length_calculator.rb +129 -0
  43. data/lib/rubocop/cop/mixin/allowed_methods.rb +19 -0
  44. data/lib/rubocop/cop/mixin/auto_corrector.rb +12 -0
  45. data/lib/rubocop/cop/mixin/code_length.rb +4 -0
  46. data/lib/rubocop/cop/mixin/configurable_formatting.rb +1 -1
  47. data/lib/rubocop/cop/mixin/enforce_superclass.rb +3 -1
  48. data/lib/rubocop/cop/mixin/nil_methods.rb +3 -5
  49. data/lib/rubocop/cop/mixin/ordered_gem_node.rb +6 -1
  50. data/lib/rubocop/cop/mixin/surrounding_space.rb +7 -2
  51. data/lib/rubocop/cop/mixin/too_many_lines.rb +3 -13
  52. data/lib/rubocop/cop/mixin/uncommunicative_name.rb +4 -2
  53. data/lib/rubocop/cop/naming/ascii_identifiers.rb +27 -4
  54. data/lib/rubocop/cop/naming/binary_operator_parameter_name.rb +2 -2
  55. data/lib/rubocop/cop/naming/method_name.rb +1 -1
  56. data/lib/rubocop/cop/naming/method_parameter_name.rb +1 -1
  57. data/lib/rubocop/cop/naming/predicate_name.rb +3 -5
  58. data/lib/rubocop/cop/naming/variable_name.rb +1 -1
  59. data/lib/rubocop/cop/naming/variable_number.rb +1 -1
  60. data/lib/rubocop/cop/offense.rb +16 -2
  61. data/lib/rubocop/cop/style/accessor_grouping.rb +136 -0
  62. data/lib/rubocop/cop/style/bisected_attr_accessor.rb +121 -0
  63. data/lib/rubocop/cop/style/class_vars.rb +21 -0
  64. data/lib/rubocop/cop/style/date_time.rb +1 -1
  65. data/lib/rubocop/cop/style/dir.rb +2 -2
  66. data/lib/rubocop/cop/style/empty_literal.rb +5 -5
  67. data/lib/rubocop/cop/style/expand_path_arguments.rb +2 -2
  68. data/lib/rubocop/cop/style/if_unless_modifier_of_if_unless.rb +12 -0
  69. data/lib/rubocop/cop/style/multiline_block_chain.rb +10 -1
  70. data/lib/rubocop/cop/style/mutable_constant.rb +4 -4
  71. data/lib/rubocop/cop/style/nested_parenthesized_calls.rb +2 -5
  72. data/lib/rubocop/cop/style/proc.rb +1 -1
  73. data/lib/rubocop/cop/style/random_with_offset.rb +4 -10
  74. data/lib/rubocop/cop/style/redundant_assignment.rb +117 -0
  75. data/lib/rubocop/cop/style/redundant_exception.rb +14 -10
  76. data/lib/rubocop/cop/style/redundant_fetch_block.rb +26 -7
  77. data/lib/rubocop/cop/style/redundant_freeze.rb +1 -1
  78. data/lib/rubocop/cop/style/redundant_parentheses.rb +7 -1
  79. data/lib/rubocop/cop/style/redundant_regexp_character_class.rb +2 -1
  80. data/lib/rubocop/cop/style/rescue_standard_error.rb +1 -1
  81. data/lib/rubocop/cop/style/signal_exception.rb +1 -1
  82. data/lib/rubocop/cop/style/stderr_puts.rb +1 -1
  83. data/lib/rubocop/cop/style/struct_inheritance.rb +2 -2
  84. data/lib/rubocop/cop/style/symbol_proc.rb +1 -1
  85. data/lib/rubocop/cop/style/trivial_accessors.rb +8 -7
  86. data/lib/rubocop/cop/style/zero_length_predicate.rb +2 -2
  87. data/lib/rubocop/cop/team.rb +97 -81
  88. data/lib/rubocop/cop/utils/format_string.rb +1 -2
  89. data/lib/rubocop/name_similarity.rb +1 -3
  90. data/lib/rubocop/options.rb +15 -8
  91. data/lib/rubocop/rake_task.rb +6 -9
  92. data/lib/rubocop/rspec/cop_helper.rb +4 -4
  93. data/lib/rubocop/rspec/expect_offense.rb +10 -16
  94. data/lib/rubocop/rspec/shared_contexts.rb +7 -7
  95. data/lib/rubocop/runner.rb +31 -29
  96. data/lib/rubocop/target_ruby.rb +1 -1
  97. data/lib/rubocop/version.rb +1 -1
  98. metadata +15 -7
  99. data/lib/rubocop/cop/mixin/classish_length.rb +0 -37
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 99c7f4b160b77fafa6fb31562b3fbd206a50b4b5201c918250b1a1d94105fb14
4
- data.tar.gz: d709c3614f3aaf536c0acefe88effe53ff51c148e37cc57740890d4ec4abbb50
3
+ metadata.gz: b4ab19d9feaaa55fc107e42860eb4fe6a6f0106350edcfee8095b689845106d1
4
+ data.tar.gz: b096ab80d7f1c3e1e3ea5b4e32f74f0ce23dc5bf34c06b2fb80893c53cd058dc
5
5
  SHA512:
6
- metadata.gz: 966a99e7d38184ccdd1f6b21c14c8d800a6f86488f9685571d60b712088ddac8218f1324e9fc61ddf37d941d6f16b6f6a8a3a1eb6f7c897780e02d1d7994fb15
7
- data.tar.gz: 61bc95d25555286a6ed5e4fc710ce97cbd0b1cf7858e8bd876cb42bf1cbb673fde2316917abf5e2f0e89252042b1a4495cb88f5cbc579046052e71a22cef1259
6
+ metadata.gz: d9db7c5ac245ecc290c75144ca7baf37d3f8a39911238f4d8d2866ce019c91b0c0dc2a9cc296c71e2f49d972d16773de3c077734ecef7e5b01f7d693de51a001
7
+ data.tar.gz: b9a3b18f4a95be71f2518ef6a2a4946f05079f0239a41c11230e7f60ba509b9d511c160edb0fe288663d41432d1e82aba6b721f6c27604a23a64b0bac674216f
data/README.md CHANGED
@@ -49,7 +49,7 @@ haven't reached version 1.0 yet). To prevent an unwanted RuboCop update you
49
49
  might want to use a conservative version lock in your `Gemfile`:
50
50
 
51
51
  ```rb
52
- gem 'rubocop', '~> 0.86.0', require: false
52
+ gem 'rubocop', '~> 0.87.0', require: false
53
53
  ```
54
54
 
55
55
  ## Quickstart
@@ -180,6 +180,9 @@ Bundler/OrderedGems:
180
180
  VersionAdded: '0.46'
181
181
  VersionChanged: '0.47'
182
182
  TreatCommentsAsGroupSeparators: true
183
+ # By default, "-" and "_" are ignored for order purposes.
184
+ # This can be overridden by setting this parameter to true.
185
+ ConsiderPunctuation: false
183
186
  Include:
184
187
  - '**/*.gemfile'
185
188
  - '**/Gemfile'
@@ -200,6 +203,9 @@ Gemspec/OrderedDependencies:
200
203
  Enabled: true
201
204
  VersionAdded: '0.51'
202
205
  TreatCommentsAsGroupSeparators: true
206
+ # By default, "-" and "_" are ignored for order purposes.
207
+ # This can be overridden by setting this parameter to true.
208
+ ConsiderPunctuation: false
203
209
  Include:
204
210
  - '**/*.gemspec'
205
211
 
@@ -1508,7 +1514,9 @@ Lint/InheritException:
1508
1514
  Lint/InterpolationCheck:
1509
1515
  Description: 'Raise warning for interpolation in single q strs.'
1510
1516
  Enabled: true
1517
+ SafeAutoCorrect: false
1511
1518
  VersionAdded: '0.50'
1519
+ VersionChanged: '0.87'
1512
1520
 
1513
1521
  Lint/LiteralAsCondition:
1514
1522
  Description: 'Checks of literals used in conditions.'
@@ -1736,6 +1744,7 @@ Lint/SafeNavigationWithEmpty:
1736
1744
  Description: 'Avoid `foo&.empty?` in conditionals.'
1737
1745
  Enabled: true
1738
1746
  VersionAdded: '0.62'
1747
+ VersionChanged: '0.87'
1739
1748
 
1740
1749
  Lint/ScriptPermission:
1741
1750
  Description: 'Grant script file execute permission.'
@@ -1902,9 +1911,10 @@ Metrics/BlockLength:
1902
1911
  Description: 'Avoid long blocks with many lines.'
1903
1912
  Enabled: true
1904
1913
  VersionAdded: '0.44'
1905
- VersionChanged: '0.66'
1914
+ VersionChanged: '0.87'
1906
1915
  CountComments: false # count full line comments?
1907
1916
  Max: 25
1917
+ CountAsOne: []
1908
1918
  ExcludedMethods:
1909
1919
  # By default, exclude the `#refine` method, as it tends to have larger
1910
1920
  # associated blocks.
@@ -1925,8 +1935,10 @@ Metrics/ClassLength:
1925
1935
  Description: 'Avoid classes longer than 100 lines of code.'
1926
1936
  Enabled: true
1927
1937
  VersionAdded: '0.25'
1938
+ VersionChanged: '0.87'
1928
1939
  CountComments: false # count full line comments?
1929
1940
  Max: 100
1941
+ CountAsOne: []
1930
1942
 
1931
1943
  # Avoid complex methods.
1932
1944
  Metrics/CyclomaticComplexity:
@@ -1944,17 +1956,20 @@ Metrics/MethodLength:
1944
1956
  StyleGuide: '#short-methods'
1945
1957
  Enabled: true
1946
1958
  VersionAdded: '0.25'
1947
- VersionChanged: '0.59.2'
1959
+ VersionChanged: '0.87'
1948
1960
  CountComments: false # count full line comments?
1949
1961
  Max: 10
1962
+ CountAsOne: []
1950
1963
  ExcludedMethods: []
1951
1964
 
1952
1965
  Metrics/ModuleLength:
1953
1966
  Description: 'Avoid modules longer than 100 lines of code.'
1954
1967
  Enabled: true
1955
1968
  VersionAdded: '0.31'
1969
+ VersionChanged: '0.87'
1956
1970
  CountComments: false # count full line comments?
1957
1971
  Max: 100
1972
+ CountAsOne: []
1958
1973
 
1959
1974
  Metrics/ParameterLists:
1960
1975
  Description: 'Avoid parameter lists longer than three or four parameters.'
@@ -1992,10 +2007,12 @@ Naming/AccessorMethodName:
1992
2007
  VersionAdded: '0.50'
1993
2008
 
1994
2009
  Naming/AsciiIdentifiers:
1995
- Description: 'Use only ascii symbols in identifiers.'
2010
+ Description: 'Use only ascii symbols in identifiers and constants.'
1996
2011
  StyleGuide: '#english-identifiers'
1997
2012
  Enabled: true
1998
2013
  VersionAdded: '0.50'
2014
+ VersionChanged: '0.87'
2015
+ AsciiConstants: true
1999
2016
 
2000
2017
  Naming/BinaryOperatorParameterName:
2001
2018
  Description: 'When defining binary operators, name the argument other.'
@@ -2288,6 +2305,17 @@ Style/AccessModifierDeclarations:
2288
2305
  - group
2289
2306
  AllowModifiersOnSymbols: true
2290
2307
 
2308
+ Style/AccessorGrouping:
2309
+ Description: 'Checks for grouping of accessors in `class` and `module` bodies.'
2310
+ Enabled: 'pending'
2311
+ VersionAdded: '0.87'
2312
+ EnforcedStyle: grouped
2313
+ SupportedStyles:
2314
+ # separated: each accessor goes in a separate statement.
2315
+ # grouped: accessors are grouped into a single statement.
2316
+ - separated
2317
+ - grouped
2318
+
2291
2319
  Style/Alias:
2292
2320
  Description: 'Use alias instead of alias_method.'
2293
2321
  StyleGuide: '#alias-method-lexically'
@@ -2355,6 +2383,13 @@ Style/BeginBlock:
2355
2383
  Enabled: true
2356
2384
  VersionAdded: '0.9'
2357
2385
 
2386
+ Style/BisectedAttrAccessor:
2387
+ Description: >-
2388
+ Checks for places where `attr_reader` and `attr_writer`
2389
+ for the same method can be combined into single `attr_accessor`.
2390
+ Enabled: 'pending'
2391
+ VersionAdded: '0.87'
2392
+
2358
2393
  Style/BlockComments:
2359
2394
  Description: 'Do not use block comments.'
2360
2395
  StyleGuide: '#no-block-comments'
@@ -2729,6 +2764,7 @@ Style/DoubleNegation:
2729
2764
  VersionAdded: '0.19'
2730
2765
  VersionChanged: '0.84'
2731
2766
  EnforcedStyle: allowed_in_returns
2767
+ SafeAutoCorrect: false
2732
2768
  SupportedStyles:
2733
2769
  - allowed_in_returns
2734
2770
  - forbidden
@@ -2995,6 +3031,7 @@ Style/IfUnlessModifierOfIfUnless:
2995
3031
  Avoid modifier if/unless usage on conditionals.
2996
3032
  Enabled: true
2997
3033
  VersionAdded: '0.39'
3034
+ VersionChanged: '0.87'
2998
3035
 
2999
3036
  Style/IfWithSemicolon:
3000
3037
  Description: 'Do not use if x; .... Use the ternary operator instead.'
@@ -3581,6 +3618,11 @@ Style/RandomWithOffset:
3581
3618
  Enabled: true
3582
3619
  VersionAdded: '0.52'
3583
3620
 
3621
+ Style/RedundantAssignment:
3622
+ Description: 'Checks for redundant assignment before returning.'
3623
+ Enabled: 'pending'
3624
+ VersionAdded: '0.87'
3625
+
3584
3626
  Style/RedundantBegin:
3585
3627
  Description: "Don't use begin blocks when they are not needed."
3586
3628
  StyleGuide: '#begin-implicit'
@@ -3924,7 +3966,7 @@ Style/SymbolLiteral:
3924
3966
  Style/SymbolProc:
3925
3967
  Description: 'Use symbols as procs instead of blocks when possible.'
3926
3968
  Enabled: true
3927
- SafeAutoCorrect: false
3969
+ Safe: false
3928
3970
  VersionAdded: '0.26'
3929
3971
  VersionChanged: '0.64'
3930
3972
  # A list of method names to be ignored by the check.
@@ -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'
@@ -326,6 +328,7 @@ require_relative 'rubocop/cop/metrics/utils/iterating_block'
326
328
  require_relative 'rubocop/cop/metrics/cyclomatic_complexity'
327
329
  # relies on cyclomatic_complexity
328
330
  require_relative 'rubocop/cop/metrics/utils/abc_size_calculator'
331
+ require_relative 'rubocop/cop/metrics/utils/code_length_calculator'
329
332
  require_relative 'rubocop/cop/metrics/abc_size'
330
333
  require_relative 'rubocop/cop/metrics/block_length'
331
334
  require_relative 'rubocop/cop/metrics/block_nesting'
@@ -353,6 +356,7 @@ require_relative 'rubocop/cop/naming/variable_name'
353
356
  require_relative 'rubocop/cop/naming/variable_number'
354
357
 
355
358
  require_relative 'rubocop/cop/style/access_modifier_declarations'
359
+ require_relative 'rubocop/cop/style/accessor_grouping'
356
360
  require_relative 'rubocop/cop/style/alias'
357
361
  require_relative 'rubocop/cop/style/and_or'
358
362
  require_relative 'rubocop/cop/style/array_join'
@@ -361,6 +365,7 @@ require_relative 'rubocop/cop/style/attr'
361
365
  require_relative 'rubocop/cop/style/auto_resource_cleanup'
362
366
  require_relative 'rubocop/cop/style/bare_percent_literals'
363
367
  require_relative 'rubocop/cop/style/begin_block'
368
+ require_relative 'rubocop/cop/style/bisected_attr_accessor'
364
369
  require_relative 'rubocop/cop/style/block_comments'
365
370
  require_relative 'rubocop/cop/style/block_delimiters'
366
371
  require_relative 'rubocop/cop/style/case_equality'
@@ -426,6 +431,7 @@ require_relative 'rubocop/cop/style/lambda_call'
426
431
  require_relative 'rubocop/cop/style/line_end_concatenation'
427
432
  require_relative 'rubocop/cop/style/method_call_without_args_parentheses'
428
433
  require_relative 'rubocop/cop/style/method_call_with_args_parentheses'
434
+ require_relative 'rubocop/cop/style/redundant_assignment'
429
435
  require_relative 'rubocop/cop/style/redundant_fetch_block'
430
436
  require_relative 'rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses'
431
437
  require_relative 'rubocop/cop/style/method_call_with_args_parentheses/require_parentheses'
@@ -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
@@ -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
 
@@ -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(ConfigLoader::AUTO_GENERATED_FILE)
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(ConfigLoader::AUTO_GENERATED_FILE, 'a') do |f|
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(ConfigLoader::AUTO_GENERATED_FILE, 'w') {}
91
- ConfigLoader.add_inheritance_from_auto_generated_file
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
- ConfigLoader::AUTO_GENERATED_FILE]
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
@@ -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.new(@config).support_autocorrect?
52
+ puts '# Supports --auto-correct' if cop.support_autocorrect?
53
53
  puts "#{cop.cop_name}:"
54
54
  puts config_lines(cop)
55
55
  puts
@@ -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, :auto_gen_config, :ignore_parent_exclusion,
27
- :options_config, :disable_pending_cops, :enable_pending_cops
25
+ attr_accessor :debug, :ignore_parent_exclusion,
26
+ :disable_pending_cops, :enable_pending_cops
28
27
  attr_writer :default_configuration
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 = @auto_gen_config = @options_config = nil
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 ConfigLoader.default_configuration if config_file == DEFAULT_FILE
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,8 +118,8 @@ module RuboCop
105
118
  end
106
119
 
107
120
  def add_excludes_from_files(config, config_file)
108
- found_files = find_files_upwards(DOTFILE, config_file) +
109
- [find_user_dotfile, find_user_xdg_config].compact
121
+ found_files = find_files_upwards(DOTFILE, config_file)
122
+ found_files = [find_user_dotfile, find_user_xdg_config].compact if found_files.empty?
110
123
 
111
124
  return if found_files.empty?
112
125
  return if PathUtil.relative_path(found_files.last) ==
@@ -139,36 +152,11 @@ module RuboCop
139
152
  warn Rainbow('For more information: https://docs.rubocop.org/rubocop/versioning.html').yellow
140
153
  end
141
154
 
142
- # Merges the given configuration with the default one. If
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.
155
+ # Merges the given configuration with the default one.
148
156
  def merge_with_default(config, config_file, unset_nil: true)
149
157
  resolver.merge_with_default(config, config_file, unset_nil: unset_nil)
150
158
  end
151
159
 
152
- def add_inheritance_from_auto_generated_file
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)
168
-
169
- puts "Added inheritance from `#{AUTO_GENERATED_FILE}` in `#{DOTFILE}`."
170
- end
171
-
172
160
  private
173
161
 
174
162
  def find_project_dotfile(target_dir)
@@ -196,38 +184,10 @@ module RuboCop
196
184
  path
197
185
  end
198
186
 
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
187
  def resolver
213
188
  @resolver ||= ConfigLoaderResolver.new
214
189
  end
215
190
 
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
191
  def check_duplication(yaml_code, absolute_path)
232
192
  smart_path = PathUtil.smart_path(absolute_path)
233
193
  YAMLDuplicationChecker.check(yaml_code, absolute_path) do |key1, key2|