rubocop 0.10.0 → 0.11.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of rubocop might be problematic. Click here for more details.

Files changed (79) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +35 -0
  3. data/CONTRIBUTING.md +2 -0
  4. data/README.md +102 -5
  5. data/config/default.yml +31 -3
  6. data/config/enabled.yml +21 -3
  7. data/lib/rubocop.rb +5 -0
  8. data/lib/rubocop/cli.rb +27 -7
  9. data/lib/rubocop/config.rb +21 -2
  10. data/lib/rubocop/config_store.rb +4 -1
  11. data/lib/rubocop/cop/commissioner.rb +2 -4
  12. data/lib/rubocop/cop/cop.rb +8 -8
  13. data/lib/rubocop/cop/lint/assignment_in_condition.rb +3 -0
  14. data/lib/rubocop/cop/lint/block_alignment.rb +10 -20
  15. data/lib/rubocop/cop/lint/useless_assignment.rb +63 -0
  16. data/lib/rubocop/cop/lint/useless_comparison.rb +30 -0
  17. data/lib/rubocop/cop/style/align_parameters.rb +23 -13
  18. data/lib/rubocop/cop/style/and_or.rb +13 -1
  19. data/lib/rubocop/cop/style/blocks.rb +35 -0
  20. data/lib/rubocop/cop/style/character_literal.rb +1 -1
  21. data/lib/rubocop/cop/style/comment_annotation.rb +20 -5
  22. data/lib/rubocop/cop/style/dot_position.rb +7 -1
  23. data/lib/rubocop/cop/style/empty_line_between_defs.rb +1 -1
  24. data/lib/rubocop/cop/style/favor_modifier.rb +4 -4
  25. data/lib/rubocop/cop/style/module_function.rb +34 -0
  26. data/lib/rubocop/cop/style/multiline_if_then.rb +7 -9
  27. data/lib/rubocop/cop/style/redundant_begin.rb +7 -7
  28. data/lib/rubocop/cop/style/redundant_return.rb +9 -11
  29. data/lib/rubocop/cop/style/redundant_self.rb +5 -1
  30. data/lib/rubocop/cop/style/regexp_literal.rb +2 -1
  31. data/lib/rubocop/cop/style/signal_exception.rb +40 -0
  32. data/lib/rubocop/cop/style/string_literals.rb +2 -2
  33. data/lib/rubocop/cop/style/symbol_name.rb +11 -0
  34. data/lib/rubocop/cop/style/trivial_accessors.rb +22 -10
  35. data/lib/rubocop/cop/variable_inspector.rb +92 -71
  36. data/lib/rubocop/formatter/clang_style_formatter.rb +8 -3
  37. data/lib/rubocop/formatter/disabled_config_formatter.rb +32 -0
  38. data/lib/rubocop/formatter/formatter_set.rb +7 -4
  39. data/lib/rubocop/target_finder.rb +3 -4
  40. data/lib/rubocop/version.rb +1 -1
  41. data/rubocop.gemspec +1 -1
  42. data/spec/rubocop/cli_spec.rb +90 -1
  43. data/spec/rubocop/cops/commissioner_spec.rb +1 -1
  44. data/spec/rubocop/cops/lint/assignment_in_condition_spec.rb +6 -0
  45. data/spec/rubocop/cops/lint/block_alignment_spec.rb +16 -4
  46. data/spec/rubocop/cops/lint/empty_ensure_spec.rb +1 -1
  47. data/spec/rubocop/cops/lint/ensure_return_spec.rb +1 -1
  48. data/spec/rubocop/cops/lint/shadowing_outer_local_variable_spec.rb +4 -4
  49. data/spec/rubocop/cops/lint/unused_local_variable_spec.rb +49 -13
  50. data/spec/rubocop/cops/lint/useless_assignment_spec.rb +62 -0
  51. data/spec/rubocop/cops/lint/useless_comparison_spec.rb +31 -0
  52. data/spec/rubocop/cops/style/align_parameters_spec.rb +9 -0
  53. data/spec/rubocop/cops/style/and_or_spec.rb +12 -0
  54. data/spec/rubocop/cops/style/avoid_global_vars_spec.rb +1 -1
  55. data/spec/rubocop/cops/style/blocks_spec.rb +57 -14
  56. data/spec/rubocop/cops/style/character_literal_spec.rb +2 -2
  57. data/spec/rubocop/cops/style/comment_annotation_spec.rb +32 -4
  58. data/spec/rubocop/cops/style/dot_position_spec.rb +10 -0
  59. data/spec/rubocop/cops/style/empty_line_between_defs_spec.rb +12 -0
  60. data/spec/rubocop/cops/style/end_of_line_spec.rb +1 -0
  61. data/spec/rubocop/cops/style/favor_modifier_spec.rb +18 -0
  62. data/spec/rubocop/cops/style/hash_syntax_spec.rb +7 -2
  63. data/spec/rubocop/cops/style/module_function_spec.rb +30 -0
  64. data/spec/rubocop/cops/style/redundant_begin_spec.rb +2 -2
  65. data/spec/rubocop/cops/style/redundant_return_spec.rb +4 -4
  66. data/spec/rubocop/cops/style/redundant_self_spec.rb +36 -2
  67. data/spec/rubocop/cops/style/regexp_literal_spec.rb +1 -0
  68. data/spec/rubocop/cops/style/signal_exception_spec.rb +74 -0
  69. data/spec/rubocop/cops/style/string_literals_spec.rb +10 -0
  70. data/spec/rubocop/cops/style/symbol_name_spec.rb +13 -0
  71. data/spec/rubocop/cops/style/trivial_accessors_spec.rb +28 -3
  72. data/spec/rubocop/cops/variable_inspector_spec.rb +217 -36
  73. data/spec/rubocop/formatter/base_formatter_spec.rb +3 -3
  74. data/spec/rubocop/formatter/clang_style_formatter_spec.rb +19 -0
  75. data/spec/rubocop/formatter/disabled_config_formatter_spec.rb +48 -0
  76. data/spec/rubocop/formatter/formatter_set_spec.rb +1 -1
  77. data/spec/rubocop/processed_source_spec.rb +1 -1
  78. data/spec/spec_helper.rb +18 -13
  79. metadata +31 -38
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 46a70e165239937f96e1ec60cf1d25c1ae523b8f
4
+ data.tar.gz: 9f8958bc707a011fdc1dc40b1e121e060d2d52ba
5
+ SHA512:
6
+ metadata.gz: c7e3f337b0ff25c99080a7dcc196a85307cc98db3c8a5b837e51e37e515c36145297dd44d31919a983dc7a4a4592fb31ea3a063ca0a916acaa1535ac7a4789f2
7
+ data.tar.gz: 8374798fa3ad9c7e0a7ac42c51597aaa2e32a0f5d261de2b3aab01921ed5fad558e71223a22e51442f9001e849ea3ae0a1ab5a467851ed57c88ca0d6dcc1e2c0
@@ -2,6 +2,41 @@
2
2
 
3
3
  ## master (unreleased)
4
4
 
5
+ ## 0.11.0 (09/08/2013)
6
+
7
+ ### New features
8
+
9
+ * [#421](https://github.com/bbatsov/rubocop/issues/421) - `
10
+ TrivialAccessors` now ignores methods on user-configurable
11
+ whitelist (such as `to_s` and `to_hash`)
12
+ * New option `--auto-gen-config` outputs RuboCop configuration that disables all
13
+ cops that detect any offences (for
14
+ [#369](https://github.com/bbatsov/rubocop/issues/369)).
15
+ * The list of annotation keywords recognized by the `CommentAnnotation` cop is now configurable.
16
+ * Configuration file names are printed as they are loaded in `--debug` mode.
17
+ * Auto-correct support added in `AlignParameters` cop.
18
+ * New cop `UselessComparison` checks for comparisons of the same arguments.
19
+ * New cop `UselessAssignment` checks for useless assignments to local variables.
20
+ * New cop `SignalException` checks for proper usage of `fail` and `raise`.
21
+ * New cop `ModuleFunction` checks for usage of `extend self` in modules.
22
+
23
+ ### Bugs fixed
24
+
25
+ * [#374](https://github.com/bbatsov/rubocop/issues/374) - Fixed error at post condition loop (`begin-end-while`, `begin-end-until`) in `UnusedLocalVariable` and `ShadowingOuterLocalVariable`
26
+ * [#373](https://github.com/bbatsov/rubocop/issues/373) and [#376](https://github.com/bbatsov/rubocop/issues/376) - allow braces around multi-line blocks if `do`-`end` would change the meaning of the code
27
+ * `RedundantSelf` now allows `self.` followed by any ruby keyword
28
+ * [#391](https://github.com/bbatsov/rubocop/issues/391) - Fix bug in counting slashes in a regexp.
29
+ * [#394](https://github.com/bbatsov/rubocop/issues/394) - `DotPosition` cop handles correctly code like `l.(1)`
30
+ * [#390](https://github.com/bbatsov/rubocop/issues/390) - `CommentAnnotation` cop allows keywords (e.g. Review, Optimize) if they just begin a sentence.
31
+ * [#400](https://github.com/bbatsov/rubocop/issues/400) - Fix bug concerning nested defs in `EmptyLineBetweenDefs` cop.
32
+ * [#399](https://github.com/bbatsov/rubocop/issues/399) - Allow assignment inside blocks in `AssignmentInCondition` cop.
33
+ * Fix bug in favor_modifier.rb regarding missed offences after else etc.
34
+ * [#393](https://github.com/bbatsov/rubocop/issues/393) - Retract support for multiline chaining of blocks (which fixed [#346](https://github.com/bbatsov/rubocop/issues/346)), thus rejecting issue 346.
35
+ * [#389](https://github.com/bbatsov/rubocop/issues/389) - Ignore symbols that are arguments to Module#private_constant in `SymbolName` cop.
36
+ * [#387](https://github.com/bbatsov/rubocop/issues/387) - Do autocorrect in `AndOr` cop only if it does not change the meaning of the code.
37
+ * [#398](https://github.com/bbatsov/rubocop/issues/398) - Don't display blank lines in the output of the clang formatter
38
+ * [#283](https://github.com/bbatsov/rubocop/issues/283) - Refine `StringLiterals` string content check
39
+
5
40
  ## 0.10.0 (17/07/2013)
6
41
 
7
42
  ### New features
@@ -14,3 +14,5 @@
14
14
  you want to have your own version, or is otherwise necessary, that
15
15
  is fine, but please isolate to its own commit so I can cherry-pick
16
16
  around it.
17
+ * Squash your commits.
18
+ * Create a pull-request.
data/README.md CHANGED
@@ -33,6 +33,34 @@ Alternatively you can pass `rubocop` a list of files and folders to check:
33
33
  $ rubocop app spec lib/something.rb
34
34
  ```
35
35
 
36
+ Here's RuboCop in action. Consider the following Ruby source code:
37
+
38
+ ```ruby
39
+ def badName
40
+ if something
41
+ test
42
+ end
43
+ end
44
+ ```
45
+
46
+ Running RuboCop on it (assuming it's in a file named `test.rb`) would produce the following report:
47
+
48
+ ```
49
+ Offences:
50
+
51
+ test.rb:1:1: C: Use snake_case for methods and variables.
52
+ def badName
53
+ ^^^
54
+ test.rb:2:3: C: Favor modifier if/unless usage when you have a single-line body. Another good alternative is the usage of control flow &&/||.
55
+ if something
56
+ ^^^^^
57
+ test.rb:4:5: W: end at 4, 4 is not aligned with if at 2, 2
58
+ end
59
+ ^^^
60
+
61
+ 1 file inspected, 3 offences detected
62
+ ```
63
+
36
64
  For more details check the available command-line options:
37
65
 
38
66
  ```bash
@@ -50,9 +78,10 @@ Command flag | Description
50
78
  `-r/--require` | Require Ruby file
51
79
  `-R/--rails` | Run extra Rails cops
52
80
  `-l/--lint` | Run only lint cops
53
- `-a/--auto-correct` | Auto-correct certain offences.
81
+ `-a/--auto-correct` | Auto-correct certain offences *Note:* Experimental - use with caution
54
82
  `-s/--silent` | Suppress the final summary
55
83
  `--only` | Run only the specified cop
84
+ `--auto-gen-config` | Generate a configuration file acting as a TODO list
56
85
 
57
86
  ## Configuration
58
87
 
@@ -163,8 +192,71 @@ for the directory tree starting where it is defined. It is not
163
192
  shadowed by the setting of `Excludes` in other `.rubocop.yml` files in
164
193
  subdirectories.
165
194
 
195
+ ### Automatically Generated Configuration
196
+
197
+ If you have a code base with an overwhelming amount of offences, it can be a
198
+ good idea to use `rubocop --auto_gen_config` and add an `inherit_from:
199
+ rubocop-todo.yml` in your `.rubocop.yml`. The generated file `rubocop-todo.yml`
200
+ contains configuration to disable all cops that currently detect an offence in
201
+ the code. Then you can start removing the entries in the generated file one by
202
+ one as you work through all the offences in the code.
203
+
166
204
  ## Formatters
167
205
 
206
+ ### Clang Formatter (default)
207
+
208
+ The `Clang` formatter displays the offences in a manner similar to `clang`:
209
+
210
+ ```
211
+ rubocop test.rb
212
+
213
+ Inspecting 1 file
214
+ W
215
+
216
+ Offences:
217
+
218
+ test.rb:1:1: C: Use snake_case for methods and variables.
219
+ def badName
220
+ ^^^
221
+ test.rb:2:3: C: Favor modifier if/unless usage when you have a single-line body. Another good alternative is the usage of control flow &&/||.
222
+ if something
223
+ ^^^^^
224
+ test.rb:4:5: W: end at 4, 4 is not aligned with if at 2, 2
225
+ end
226
+ ^^^
227
+
228
+ 1 file inspected, 3 offences detected
229
+ ```
230
+
231
+ ### Emacs
232
+
233
+ The `Emacs` formatter displays the offences in a format suitable for consumption by `Emacs` (and possibly other tools).
234
+
235
+ ```
236
+ rubocop --format emacs test.rb
237
+
238
+ /Users/bozhidar/projects/test.rb:1:1: C: Use snake_case for methods and variables.
239
+ /Users/bozhidar/projects/test.rb:2:3: C: Favor modifier if/unless usage when you have a single-line body. Another good alternative is the usage of control flow &&/||.
240
+ /Users/bozhidar/projects/test.rb:4:5: W: end at 4, 4 is not aligned with if at 2, 2
241
+
242
+ 1 file inspected, 3 offences detected
243
+ ```
244
+
245
+ ### Simple (default in RuboCop prior to version 0.9)
246
+
247
+ The name of the formatter says it all :-)
248
+
249
+ ```
250
+ rubocop --format simple test.rb
251
+
252
+ == test.rb ==
253
+ C: 1: 1: Use snake_case for methods and variables.
254
+ C: 2: 3: Favor modifier if/unless usage when you have a single-line body. Another good alternative is the usage of control flow &&/||.
255
+ W: 4: 5: end at 4, 4 is not aligned with if at 2, 2
256
+
257
+ 1 file inspected, 3 offences detected
258
+ ```
259
+
168
260
  ### File List Formmater
169
261
 
170
262
  Sometimes you might want to just open all files with offences in your
@@ -321,6 +413,15 @@ Rubocop::RakeTask.new(:rubocop) do |task|
321
413
  end
322
414
  ```
323
415
 
416
+ ## Team
417
+
418
+ Here's a list of RuboCop's core developers:
419
+
420
+ * [Bozhidar Batsov](https://github.com/bbatsov)
421
+ * [Jonas Arvidsson](https://github.com/jonas054)
422
+ * [Yuji Nakayama](https://github.com/yujinakayama)
423
+ * [Evgeni Dzhelyov](https://github.com/edzhelyov)
424
+
324
425
  ## Contributors
325
426
 
326
427
  Here's a [list](https://github.com/bbatsov/rubocop/contributors) of
@@ -328,10 +429,6 @@ all the people who have contributed to the development of RuboCop.
328
429
 
329
430
  I'm extremely grateful to each and every one of them!
330
431
 
331
- I'd like to single out [Jonas Arvidsson](https://github.com/jonas054)
332
- and [Yuji Nakayama](https://github.com/yujinakayama) for their many
333
- excellent code contributions as well as valuable feedback and ideas!
334
-
335
432
  If you'd like to contribute to RuboCop, please take the time to go
336
433
  through our short
337
434
  [contribution guidelines](CONTRIBUTING.md).
@@ -65,14 +65,33 @@ CollectionMethods:
65
65
  detect: 'find'
66
66
  find_all: 'select'
67
67
 
68
- # Muli-line method chaining should be done with leading dots.
68
+ # Multi-line method chaining should be done with leading dots.
69
69
  DotPosition:
70
70
  Style: 'leading'
71
71
 
72
- # TrivialAccessors doesn't require exact name matches and doesn't allow predicated methods by default.
72
+ # TrivialAccessors doesn't require exact name matches and doesn't allow
73
+ # predicated methods by default.
73
74
  TrivialAccessors:
74
75
  ExactNameMatch: false
75
76
  AllowPredicates: false
77
+ Whitelist:
78
+ - to_ary
79
+ - to_a
80
+ - to_c
81
+ - to_enum
82
+ - to_h
83
+ - to_hash
84
+ - to_i
85
+ - to_int
86
+ - to_io
87
+ - to_open
88
+ - to_path
89
+ - to_proc
90
+ - to_r
91
+ - to_regexp
92
+ - to_str
93
+ - to_s
94
+ - to_sym
76
95
 
77
96
  # Allow safe assignment in conditions.
78
97
  AssignmentInCondition:
@@ -80,4 +99,13 @@ AssignmentInCondition:
80
99
 
81
100
  # Allow safe assignment in conditions.
82
101
  ParenthesesAroundCondition:
83
- AllowSafeAssignment: true
102
+ AllowSafeAssignment: true
103
+
104
+ # Checks formatting of special comments
105
+ CommentAnnotation:
106
+ Keywords:
107
+ - TODO
108
+ - FIXME
109
+ - OPTIMIZE
110
+ - HACK
111
+ - REVIEW
@@ -4,7 +4,7 @@
4
4
  Encoding:
5
5
  Enabled: true
6
6
 
7
- # Limit lines to 80 characters.
7
+ # Limit lines to 79 characters.
8
8
  LineLength:
9
9
  Enabled: true
10
10
 
@@ -64,7 +64,8 @@ SpaceAfterColon:
64
64
  SpaceAfterControlKeyword:
65
65
  Enabled: true
66
66
 
67
- # Prefer symbols instead of strings as hash keys.
67
+ # Prefer Ruby 1.9 hash syntax { a: 1, b: 2 } over 1.8 syntax
68
+ # { :a => 1, :b => 2 }.
68
69
  HashSyntax:
69
70
  Enabled: true
70
71
 
@@ -316,7 +317,8 @@ ConstantName:
316
317
  AccessControl:
317
318
  Enabled: true
318
319
 
319
- # Use Kernel#loop with break rather than begin/end/until or begin/end/while for post-loop tests.
320
+ # Use Kernel#loop with break rather than begin/end/until or begin/end/while for
321
+ # post-loop tests.
320
322
  Loop:
321
323
  Enabled: true
322
324
 
@@ -372,6 +374,14 @@ DotPosition:
372
374
  Attr:
373
375
  Enabled: true
374
376
 
377
+ # Checks for proper usage of fail and raise.
378
+ SignalException:
379
+ Enabled: true
380
+
381
+ # Checks for usage of `extend self` in modules.
382
+ ModuleFunction:
383
+ Enabled: true
384
+
375
385
  #################### Lint ################################
376
386
 
377
387
  # Don't use assignment in conditions.
@@ -419,6 +429,14 @@ EmptyEnsure:
419
429
  CommentAnnotation:
420
430
  Enabled: true
421
431
 
432
+ # Checks for useless assignment to a local variable.
433
+ UselessAssignment:
434
+ Enabled: true
435
+
436
+ # Checks for comparison of something with itself.
437
+ UselessComparison:
438
+ Enabled: true
439
+
422
440
  ##################### Rails ##################################
423
441
 
424
442
  # Use sexy validations.
@@ -28,6 +28,8 @@ require 'rubocop/cop/lint/rescue_exception'
28
28
  require 'rubocop/cop/lint/shadowing_outer_local_variable'
29
29
  require 'rubocop/cop/lint/unreachable_code'
30
30
  require 'rubocop/cop/lint/unused_local_variable'
31
+ require 'rubocop/cop/lint/useless_assignment'
32
+ require 'rubocop/cop/lint/useless_comparison'
31
33
  require 'rubocop/cop/lint/void'
32
34
 
33
35
  require 'rubocop/cop/style/access_control'
@@ -80,6 +82,7 @@ require 'rubocop/cop/style/line_length'
80
82
  require 'rubocop/cop/style/method_and_variable_snake_case'
81
83
  require 'rubocop/cop/style/method_call_parentheses'
82
84
  require 'rubocop/cop/style/method_length'
85
+ require 'rubocop/cop/style/module_function'
83
86
  require 'rubocop/cop/style/not'
84
87
  require 'rubocop/cop/style/numeric_literals'
85
88
  require 'rubocop/cop/style/op_method'
@@ -93,6 +96,7 @@ require 'rubocop/cop/style/redundant_self'
93
96
  require 'rubocop/cop/style/regexp_literal'
94
97
  require 'rubocop/cop/style/rescue_modifier'
95
98
  require 'rubocop/cop/style/semicolon'
99
+ require 'rubocop/cop/style/signal_exception'
96
100
  require 'rubocop/cop/style/single_line_methods'
97
101
  require 'rubocop/cop/style/space_after_comma_etc'
98
102
  require 'rubocop/cop/style/space_after_control_keyword'
@@ -114,6 +118,7 @@ require 'rubocop/cop/rails/validation'
114
118
 
115
119
  require 'rubocop/formatter/base_formatter'
116
120
  require 'rubocop/formatter/simple_text_formatter'
121
+ require 'rubocop/formatter/disabled_config_formatter'
117
122
  require 'rubocop/formatter/emacs_style_formatter'
118
123
  require 'rubocop/formatter/clang_style_formatter'
119
124
  require 'rubocop/formatter/progress_formatter'
@@ -29,12 +29,9 @@ module Rubocop
29
29
  def run(args = ARGV)
30
30
  trap_interrupt
31
31
 
32
- begin
33
- parse_options(args)
34
- rescue => e
35
- $stderr.puts e.message
36
- return 1
37
- end
32
+ parse_options(args)
33
+
34
+ Config.debug = @options[:debug]
38
35
 
39
36
  # filter out Rails cops unless requested
40
37
  @cops.reject!(&:rails?) unless @options[:rails]
@@ -68,6 +65,9 @@ module Rubocop
68
65
  display_error_summary(@errors) unless @options[:silent]
69
66
 
70
67
  !any_failed && !wants_to_quit ? 0 : 1
68
+ rescue => e
69
+ $stderr.puts e.message
70
+ return 1
71
71
  end
72
72
 
73
73
  def validate_only_option
@@ -76,6 +76,13 @@ module Rubocop
76
76
  end
77
77
  end
78
78
 
79
+ def validate_auto_gen_config_option(args)
80
+ if args.any?
81
+ fail ArgumentError,
82
+ '--auto-gen-config can not be combined with any other arguments.'
83
+ end
84
+ end
85
+
79
86
  def inspect_file(file)
80
87
  begin
81
88
  processed_source = SourceParser.parse_file(file)
@@ -94,7 +101,10 @@ module Rubocop
94
101
  end
95
102
 
96
103
  config = @config_store.for(file)
97
-
104
+ if @options[:auto_gen_config] && config.contains_auto_generated_config
105
+ fail "Remove #{Config::AUTO_GENERATED_FILE} from the current " +
106
+ 'configuration before generating it again.'
107
+ end
98
108
  set_config_for_all_cops(config)
99
109
 
100
110
  cops = []
@@ -166,6 +176,16 @@ module Rubocop
166
176
  @options[:only] = s
167
177
  validate_only_option
168
178
  end
179
+ opts.on('--auto-gen-config',
180
+ 'Generate a configuration file acting as a',
181
+ 'TODO list.') do
182
+ @options[:auto_gen_config] = true
183
+ @options[:formatters] = [
184
+ [DEFAULT_FORMATTER],
185
+ [Formatter::DisabledConfigFormatter, Config::AUTO_GENERATED_FILE]
186
+ ]
187
+ validate_auto_gen_config_option(args)
188
+ end
169
189
  opts.on('-f', '--format FORMATTER',
170
190
  'Choose an output formatter. This option',
171
191
  'can be specified multiple times to enable',
@@ -16,13 +16,20 @@ module Rubocop
16
16
  DOTFILE = '.rubocop.yml'
17
17
  RUBOCOP_HOME = File.realpath(File.join(File.dirname(__FILE__), '..', '..'))
18
18
  DEFAULT_FILE = File.join(RUBOCOP_HOME, 'config', 'default.yml')
19
+ AUTO_GENERATED_FILE = 'rubocop-todo.yml'
19
20
 
20
21
  attr_reader :loaded_path
22
+ attr_accessor :contains_auto_generated_config
21
23
 
22
24
  class << self
25
+ attr_accessor :debug
26
+ alias_method :debug?, :debug
27
+
23
28
  def load_file(path)
24
29
  path = File.absolute_path(path)
25
30
  hash = YAML.load_file(path)
31
+ puts "configuration from #{path}" if debug?
32
+ contains_auto_generated_config = false
26
33
 
27
34
  base_configs(path, hash['inherit_from']).reverse.each do |base_config|
28
35
  if File.basename(base_config.loaded_path) == DOTFILE
@@ -33,11 +40,15 @@ module Rubocop
33
40
  hash[key] = hash.has_key?(key) ? merge(value, hash[key]) : value
34
41
  end
35
42
  end
43
+ if base_config.loaded_path.include?(AUTO_GENERATED_FILE)
44
+ contains_auto_generated_config = true
45
+ end
36
46
  end
37
47
 
38
48
  hash.delete('inherit_from')
39
49
  config = new(hash, path)
40
50
  config.warn_unless_valid
51
+ config.contains_auto_generated_config = contains_auto_generated_config
41
52
  config
42
53
  end
43
54
 
@@ -88,6 +99,7 @@ module Rubocop
88
99
  end
89
100
  base_files.map do |f|
90
101
  f = File.join(File.dirname(path), f) unless f.start_with?('/')
102
+ print 'Inheriting ' if debug?
91
103
  load_file(f)
92
104
  end
93
105
  end
@@ -105,6 +117,7 @@ module Rubocop
105
117
  config = load_file(config_file)
106
118
  found_files = config_files_in_path(config_file)
107
119
  if found_files.any? && found_files.last != config_file
120
+ print 'AllCops/Excludes ' if debug?
108
121
  add_excludes_from_higher_level(config, load_file(found_files.last))
109
122
  end
110
123
  make_excludes_absolute(config)
@@ -126,11 +139,17 @@ module Rubocop
126
139
  end
127
140
 
128
141
  def default_configuration
129
- @default_configuration ||= load_file(DEFAULT_FILE)
142
+ @default_configuration ||= begin
143
+ print 'Default ' if debug?
144
+ load_file(DEFAULT_FILE)
145
+ end
130
146
  end
131
147
 
132
148
  def merge_with_default(config, config_file)
133
- new(merge(default_configuration, config), config_file)
149
+ result = new(merge(default_configuration, config), config_file)
150
+ result.contains_auto_generated_config =
151
+ config.contains_auto_generated_config
152
+ result
134
153
  end
135
154
 
136
155
  private