rubocop 0.32.1 → 0.33.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 (50) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +58 -0
  3. data/README.md +22 -4
  4. data/config/default.yml +29 -10
  5. data/config/disabled.yml +8 -4
  6. data/config/enabled.yml +40 -1
  7. data/lib/rubocop.rb +8 -0
  8. data/lib/rubocop/cli.rb +1 -0
  9. data/lib/rubocop/config_loader.rb +23 -2
  10. data/lib/rubocop/cop/lint/block_alignment.rb +1 -1
  11. data/lib/rubocop/cop/lint/circular_argument_reference.rb +38 -0
  12. data/lib/rubocop/cop/lint/def_end_alignment.rb +8 -4
  13. data/lib/rubocop/cop/lint/deprecated_class_methods.rb +38 -21
  14. data/lib/rubocop/cop/lint/duplicate_methods.rb +1 -1
  15. data/lib/rubocop/cop/lint/format_parameter_mismatch.rb +95 -0
  16. data/lib/rubocop/cop/mixin/end_keyword_alignment.rb +1 -1
  17. data/lib/rubocop/cop/mixin/on_method_def.rb +4 -5
  18. data/lib/rubocop/cop/mixin/string_literals_help.rb +1 -1
  19. data/lib/rubocop/cop/performance/count.rb +2 -0
  20. data/lib/rubocop/cop/performance/detect.rb +11 -2
  21. data/lib/rubocop/cop/performance/flat_map.rb +3 -3
  22. data/lib/rubocop/cop/performance/string_replacement.rb +161 -0
  23. data/lib/rubocop/cop/rails/date.rb +8 -8
  24. data/lib/rubocop/cop/rails/time_zone.rb +22 -13
  25. data/lib/rubocop/cop/style/block_delimiters.rb +6 -1
  26. data/lib/rubocop/cop/style/documentation.rb +1 -1
  27. data/lib/rubocop/cop/style/extra_spacing.rb +84 -5
  28. data/lib/rubocop/cop/style/first_parameter_indentation.rb +2 -0
  29. data/lib/rubocop/cop/style/indentation_width.rb +28 -4
  30. data/lib/rubocop/cop/style/initial_indentation.rb +32 -0
  31. data/lib/rubocop/cop/style/method_call_parentheses.rb +20 -1
  32. data/lib/rubocop/cop/style/one_line_conditional.rb +8 -4
  33. data/lib/rubocop/cop/style/option_hash.rb +56 -0
  34. data/lib/rubocop/cop/style/optional_arguments.rb +49 -0
  35. data/lib/rubocop/cop/style/parallel_assignment.rb +3 -0
  36. data/lib/rubocop/cop/style/percent_literal_delimiters.rb +3 -66
  37. data/lib/rubocop/cop/style/redundant_return.rb +20 -3
  38. data/lib/rubocop/cop/style/rescue_ensure_alignment.rb +77 -0
  39. data/lib/rubocop/cop/style/rescue_modifier.rb +4 -28
  40. data/lib/rubocop/cop/style/send.rb +18 -0
  41. data/lib/rubocop/cop/style/space_inside_string_interpolation.rb +32 -13
  42. data/lib/rubocop/cop/style/symbol_literal.rb +1 -1
  43. data/lib/rubocop/cop/style/trivial_accessors.rb +10 -1
  44. data/lib/rubocop/cop/style/while_until_do.rb +1 -1
  45. data/lib/rubocop/cop/style/word_array.rb +13 -1
  46. data/lib/rubocop/formatter/disabled_config_formatter.rb +54 -5
  47. data/lib/rubocop/options.rb +81 -55
  48. data/lib/rubocop/version.rb +1 -1
  49. data/relnotes/v0.33.0.md +157 -0
  50. metadata +11 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ce6b65d33cc2aafc8810c0ff7dd711bfd4f1ce3d
4
- data.tar.gz: 619b13298973e7c421fa8cc804a9a8c8671c508d
3
+ metadata.gz: 948d87ff6bb72ea91804494d73ebebad2c839195
4
+ data.tar.gz: 37dae007c0ba3c9dec6f0e7d98fe9e8446762889
5
5
  SHA512:
6
- metadata.gz: 00cd718d6abd4ab32394abbb2c0768d27ffcaeecf368ff406c5dac3b73d687dc5ad7610464bba315477620e22d8e6eec0a48f6518e1bb7d43331ef75c38e06c2
7
- data.tar.gz: f4ec724f81671c10cfc980b2cd99ad39c59f40d41ea3ce8f6267020f01a3f2918b35725a46c0ac84b778e3590d4026a5cfd9fa773c03b69fdaaa297d8dabe86d
6
+ metadata.gz: 063bfc76a95e6bc6e585f75c4a7a23c40459317f0c78549ae98444aa4a8b5280353f9fada35ad7e267f52a95c1b705385c7a8d189e550916ef99dd391d21dbf0
7
+ data.tar.gz: b8537a85f221b320271a8d021c8bb49d09a85a3a6c4af0714c2e1a20de9b9f1be9229a1574ee5bb8689e09a0e9b72a0b6f3e3af21dadfe204648147013431fb4
@@ -2,6 +2,53 @@
2
2
 
3
3
  ## master (unreleased)
4
4
 
5
+ ## 0.33.0 (05/08/2015)
6
+
7
+ ### New features
8
+
9
+ * [#2081](https://github.com/bbatsov/rubocop/pull/2081): New cop `Style/Send` checks for the use of `send` and instead encourages changing it to `BasicObject#__send__` or `Object#public_send` (disabled by default). ([@syndbg][])
10
+ * [#2057](https://github.com/bbatsov/rubocop/pull/2057): New cop `Lint/FormatParameterMismatch` checks for a mismatch between the number of fields expected in format/sprintf/% and what was pased to it. ([@edmz][])
11
+ * [#2010](https://github.com/bbatsov/rubocop/pull/2010): Add `space` style for SpaceInsideStringInterpolation. ([@gotrevor][])
12
+ * [#2007](https://github.com/bbatsov/rubocop/pull/2007): Allow any modifier before `def`, not only visibility modifiers. ([@fphilipe][])
13
+ * [#1980](https://github.com/bbatsov/rubocop/pull/1980): `--auto-gen-config` now outputs an excluded files list for failed cops (up to a maxiumum of 15 files). ([@bmorrall][])
14
+ * [#2004](https://github.com/bbatsov/rubocop/pull/2004): Introduced `--exclude-limit COUNT` to configure how many files `--auto-gen-config` will exclude. ([@awwaiid][], [@jonas054][])
15
+ * [#1918](https://github.com/bbatsov/rubocop/issues/1918): New configuration parameter `AllCops:DisabledByDefault` when set to `true` makes only cops found in user configuration enabled, which makes cop selection *opt-in*. ([@jonas054][])
16
+ * New cop `Performance/StringReplacement` checks for usages of `gsub` that can be replaced with `tr` or `delete`. ([@rrosenblum][])
17
+ * [#2001](https://github.com/bbatsov/rubocop/issues/2001): New cop `Style/InitialIndentation` checks for indentation of the first non-blank non-comment line in a file. ([@jonas054][])
18
+ * [#2060](https://github.com/bbatsov/rubocop/issues/2060): New cop `Style/RescueEnsureAlignment` checks for bad alignment of `rescue` and `ensure` keywords. ([@lumeet][])
19
+ * New cop `Style/OptionalArguments` checks for optional arguments that do not appear at the end of an argument list. ([@rrosenblum][])
20
+ * New cop `Lint/CircularArgumentReference` checks for "circular argument references" in keyword arguments, which Ruby 2.2 warns against. ([@maxjacobson][], [@sliuu][])
21
+ * [#2030](https://github.com/bbatsov/rubocop/issues/2030): New cop `Lint/OptionHash` checks for option hashes and encourages changing them to keyword arguments (disabled by default). ([@maxjacobson][])
22
+
23
+ ### Changes
24
+
25
+ * [#2052](https://github.com/bbatsov/rubocop/pull/2052): `Style/RescueModifier` uses token stream to identify offenses. ([@urbanautomaton][])
26
+ * Rename `Rails/Date` and `Rails/TimeZone` style names to "strict" and "flexible" and make "flexible" to be default. ([@palkan][])
27
+ * [#2035](https://github.com/bbatsov/rubocop/issues/2035): `Style/ExtraSpacing` is now enabled by default and has a configuration parameter `AllowForAlignment` that is `true` by default, making it allow extra spacing if it's used for alignment purposes. ([@jonas054][])
28
+
29
+ ### Bugs fixed
30
+
31
+ * [#2014](https://github.com/bbatsov/rubocop/pull/2014): Fix `Style/TrivialAccessors` to support AllowPredicates: false. ([@gotrevor][])
32
+ * [#1988](https://github.com/bbatsov/rubocop/issues/1988): Fix bug in `Style/ParallelAssignment` when assigning from `Module::CONSTANT`. ([@rrosenblum][])
33
+ * [#1995](https://github.com/bbatsov/rubocop/pull/1995): Improve message for `Rails/TimeZone`. ([@palkan][])
34
+ * [#1977](https://github.com/bbatsov/rubocop/issues/1977): Fix bugs in `Rails/Date` and `Rails/TimeZone` when using namespaced Time/Date. ([@palkan][])
35
+ * [#1973](https://github.com/bbatsov/rubocop/issues/1973): Do not register an offense in `Performance/Detect` when `select` is called on `Enumerable::Lazy`. ([@palkan][])
36
+ * [#2015](https://github.com/bbatsov/rubocop/issues/2015): Fix bug occurring for auto-correction of a misaligned `end` in a file with only one method. ([@jonas054][])
37
+ * Allow string interpolation segments inside single quoted string literals when double quotes are preferred. ([@segiddins][])
38
+ * [#2026](https://github.com/bbatsov/rubocop/issues/2026): Allow `Time.current` when style is "acceptable".([@palkan][])
39
+ * [#2029](https://github.com/bbatsov/rubocop/issues/2029): Fix bug where `Style/RedundantReturn` auto-corrects returning implicit hashes to invalid syntax. ([@rrosenblum][])
40
+ * [#2021](https://github.com/bbatsov/rubocop/issues/2021): Fix bug in `Style/BlockDelimiters` when a `semantic` expression is used in an array or a range. ([@lumeet][])
41
+ * [#1992](https://github.com/bbatsov/rubocop/issues/1992): Allow parentheses in assignment to a variable with the same name as the method's in `Style/MethodCallParentheses`. ([@lumeet][])
42
+ * [#2045](https://github.com/bbatsov/rubocop/issues/2045): Fix crash in `Style/IndentationWidth` when using `private_class_method def self.foo` syntax. ([@unmanbearpig][])
43
+ * [#2006](https://github.com/bbatsov/rubocop/issues/2006): Fix crash in `Style/FirstParameterIndentation` in case of nested offenses. ([@unmanbearpig][])
44
+ * [#2059](https://github.com/bbatsov/rubocop/issues/2059): Don't check for trivial accessors in modules. ([@bbatsov][])
45
+ * Add proper punctuation to the end of offense messages, where it is missing. ([@lumeet][])
46
+ * [#2071](https://github.com/bbatsov/rubocop/pull/2071): Keep line breaks in place on WordArray autocorrect.([@unmanbearpig][])
47
+ * [#2075](https://github.com/bbatsov/rubocop/pull/2075): Properly correct `Style/PercentLiteralDelimiters` with escape characters in them. ([@rrosenblum][])
48
+ * [#2023](https://github.com/bbatsov/rubocop/issues/2023): Avoid auto-correction corruption in `IndentationWidth`. ([@jonas054][])
49
+ * [#2080](https://github.com/bbatsov/rubocop/issues/2080): Properly parse code in `Performance/Count` when calling `select..count` in a class that extends an enumerable. ([@rrosenblum][])
50
+ * [#2093](https://github.com/bbatsov/rubocop/issues/2093): Fix bug in `Style/OneLineConditional` which should not raise an offense with an 'if/then/end' statement. ([@sliuu][])
51
+
5
52
  ## 0.32.1 (24/06/2015)
6
53
 
7
54
  ### New features
@@ -1467,3 +1514,14 @@
1467
1514
  [@matugm]: https://github.com/matugm
1468
1515
  [@m1foley]: https://github.com/m1foley
1469
1516
  [@tejasbubane]: https://github.com/tejasbubane
1517
+ [@bmorrall]: https://github.com/bmorrall
1518
+ [@fphilipe]: https://github.com/fphilipe
1519
+ [@gotrevor]: https://github.com/gotrevor
1520
+ [@awwaiid]: https://github.com/awwaiid
1521
+ [@segiddins]: https://github.com/segiddins
1522
+ [@urbanautomaton]: https://github.com/urbanautomaton.com
1523
+ [@unmanbearpig]: https://github.com/unmanbearpig
1524
+ [@maxjacobson]: https://github.com/maxjacobson
1525
+ [@sliuu]: https://github.com/sliuu
1526
+ [@edmz]: https://github.com/edmz
1527
+ [@syndbg]: https://github.com/syndbg
data/README.md CHANGED
@@ -173,6 +173,7 @@ Command flag | Description
173
173
  `--only` | Run only the specified cop(s) and/or cops in the specified departments.
174
174
  `--except` | Run all cops enabled by configuration except the specified cop(s) and/or departments.
175
175
  `--auto-gen-config` | Generate a configuration file acting as a TODO list.
176
+ `--exclude-limit` | Limit how many individual files `--auto-gen-config` can list in `Exclude` parameters, default is 15.
176
177
  `--show-cops` | Shows available cops and their configuration.
177
178
  `--fail-level` | Minimum [severity](#severity) for exit with error code. Full severity name or upper case initial can be given. Normally, auto-corrected offenses are ignored. Use `A` or `autocorrect` if you'd like them to trigger failure.
178
179
 
@@ -368,6 +369,15 @@ Metrics/LineLength:
368
369
  Enabled: false
369
370
  ```
370
371
 
372
+ Most cops are enabled by default. Some cops, configured in [config/disabled.yml](https://github.com/bbatsov/rubocop/blob/master/config/disabled.yml), are disabled by default. The cop enabling process can be altered by setting `DisabledByDefault` to `true`.
373
+
374
+ ```yaml
375
+ AllCops:
376
+ DisabledByDefault: true
377
+ ```
378
+
379
+ All cops are then disabled by default, and only cops appearing in user configuration files are enabled. `Enabled: true` does not have to be set for cops in user configuration. They will be enabled anyway.
380
+
371
381
  #### Severity
372
382
 
373
383
  Each cop has a default severity level based on which department it belongs
@@ -400,10 +410,18 @@ Style/PerlBackrefs:
400
410
  If you have a code base with an overwhelming amount of offenses, it can
401
411
  be a good idea to use `rubocop --auto-gen-config` and add an
402
412
  `inherit_from: .rubocop_todo.yml` in your `.rubocop.yml`. The generated
403
- file `.rubocop_todo.yml` contains configuration to disable all cops that
404
- currently detect an offense in the code. Then you can start removing the
405
- entries in the generated file one by one as you work through all the
406
- offenses in the code.
413
+ file `.rubocop_todo.yml` contains configuration to disable cops that
414
+ currently detect an offense in the code by excluding the offending
415
+ files, or disabling the cop altogether once a file count limit has been
416
+ reached.
417
+
418
+ By adding the option `--exclude-limit COUNT`, e.g., `rubocop
419
+ --auto-gen-config --exclude-limit 5`, you can change how many files are
420
+ excluded before the cop is entirely disabled. The default COUNT is 15.
421
+
422
+ Then you can start removing the entries in the generated
423
+ `.rubocop_todo.yml` file one by one as you work through all the offenses
424
+ in the code.
407
425
 
408
426
  ## Disabling Cops within Source Code
409
427
 
@@ -42,6 +42,13 @@ AllCops:
42
42
  # default. Change behavior by overriding StyleGuideCopsOnly, or by giving
43
43
  # the --only-guide-cops option.
44
44
  StyleGuideCopsOnly: false
45
+ # All cops except the ones in disabled.yml are enabled by default. Change
46
+ # this behavior by overriding DisabledByDefault. When DisabledByDefault is
47
+ # true, all cops in the default configuration are disabled, and and only cops
48
+ # in user configuration are enabled. This makes cops opt-in instead of
49
+ # opt-out. Note that when DisabledByDefault is true, cops in user
50
+ # configuration will be enabled even if they don't set the Enabled parameter.
51
+ DisabledByDefault: false
45
52
 
46
53
  # Indent private/protected/public as deep as method definitions
47
54
  Style/AccessModifierIndentation:
@@ -376,6 +383,12 @@ Style/Encoding:
376
383
  - always
377
384
  AutoCorrectEncodingComment: '# encoding: utf-8'
378
385
 
386
+ Style/ExtraSpacing:
387
+ # When true, allows most uses of extra spacing if the intent is to align
388
+ # things with the previous or next line, not counting empty lines or comment
389
+ # lines.
390
+ AllowForAlignment: true
391
+
379
392
  Style/FileName:
380
393
  # File names listed in AllCops:Include are excluded by default. Add extra
381
394
  # excludes here.
@@ -643,6 +656,12 @@ Style/SpaceInsideHashLiteralBraces:
643
656
  - space
644
657
  - no_space
645
658
 
659
+ Style/SpaceInsideStringInterpolation:
660
+ EnforcedStyle: no_space
661
+ SupportedStyles:
662
+ - space
663
+ - no_space
664
+
646
665
  Style/SymbolProc:
647
666
  # A list of method names to be ignored by the check.
648
667
  # The names should be fairly unique, otherwise you'll end up ignoring lots of code.
@@ -805,15 +824,15 @@ Rails/ActionFilter:
805
824
  - app/controllers/**/*.rb
806
825
 
807
826
  Rails/Date:
808
- # The value `always` disallows usage of `Date.today`, `Date.current`,
827
+ # The value `strict` disallows usage of `Date.today`, `Date.current`,
809
828
  # `Date#to_time` etc.
810
- # The value `acceptable` allows usage of `Date.current`, `Date.yesterday`, etc
829
+ # The value `flexible` allows usage of `Date.current`, `Date.yesterday`, etc
811
830
  # (but not `Date.today`) which are overriden by ActiveSupport to handle current
812
831
  # time zone.
813
- EnforcedStyle: always
832
+ EnforcedStyle: flexible
814
833
  SupportedStyles:
815
- - always
816
- - acceptable
834
+ - strict
835
+ - flexible
817
836
 
818
837
  Rails/DefaultScope:
819
838
  Include:
@@ -847,12 +866,12 @@ Rails/ScopeArgs:
847
866
  - app/models/**/*.rb
848
867
 
849
868
  Rails/TimeZone:
850
- # The value `always` means that `Time` should be used with `zone`.
851
- # The value `acceptable` allows usage of `in_time_zone` instead of `zone`.
852
- EnforcedStyle: always
869
+ # The value `strict` means that `Time` should be used with `zone`.
870
+ # The value `flexible` allows usage of `in_time_zone` instead of `zone`.
871
+ EnforcedStyle: flexible
853
872
  SupportedStyles:
854
- - always
855
- - acceptable
873
+ - strict
874
+ - flexible
856
875
 
857
876
  Rails/Validation:
858
877
  Include:
@@ -44,15 +44,19 @@ Style/MissingElse:
44
44
  - case
45
45
  - both
46
46
 
47
+ Style/OptionHash:
48
+ Description: "Don't use option hashes when you can use keyword arguments."
49
+
50
+ Style/Send:
51
+ Description: 'Prefer `Object#__send__` or `Object#public_send` to `send`, as `send` may overlap with existing methods.'
52
+ StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#prefer-public-send'
53
+ Enabled: false
54
+
47
55
  Style/SymbolArray:
48
56
  Description: 'Use %i or %I for arrays of symbols.'
49
57
  StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#percent-i'
50
58
  Enabled: false
51
59
 
52
- Style/ExtraSpacing:
53
- Description: 'Do not use unnecessary spacing.'
54
- Enabled: false
55
-
56
60
  Lint/LiteralInInterpolation:
57
61
  Description: 'Avoid interpolating literals in strings'
58
62
  AutoCorrect: false
@@ -243,11 +243,20 @@ Style/EvenOdd:
243
243
  StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#predicate-methods'
244
244
  Enabled: true
245
245
 
246
+ Style/ExtraSpacing:
247
+ Description: 'Do not use unnecessary spacing.'
248
+ Enabled: true
249
+
246
250
  Style/FileName:
247
251
  Description: 'Use snake_case for source file names.'
248
252
  StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#snake-case-files'
249
253
  Enabled: true
250
254
 
255
+ Style/InitialIndentation:
256
+ Description: >-
257
+ Checks the indentation of the first non-blank non-comment line in a file.
258
+ Enabled: true
259
+
251
260
  Style/FirstParameterIndentation:
252
261
  Description: 'Checks the indentation of the first parameter in a method call.'
253
262
  Enabled: true
@@ -447,6 +456,13 @@ Style/OpMethod:
447
456
  StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#other-arg'
448
457
  Enabled: true
449
458
 
459
+ Style/OptionalArguments:
460
+ Description: >-
461
+ Checks for optional arguments that do not appear at the end
462
+ of the argument list
463
+ StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#optional-arguments'
464
+ Enabled: true
465
+
450
466
  Style/ParallelAssignment:
451
467
  Description: >-
452
468
  Check for simple usages of parallel assignment.
@@ -518,6 +534,10 @@ Style/RegexpLiteral:
518
534
  StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#percent-r'
519
535
  Enabled: true
520
536
 
537
+ Style/RescueEnsureAlignment:
538
+ Description: 'Align rescues and ensures correctly.'
539
+ Enabled: true
540
+
521
541
  Style/RescueModifier:
522
542
  Description: 'Avoid using rescue in its modifier form.'
523
543
  StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-rescue-modifiers'
@@ -844,6 +864,10 @@ Lint/BlockAlignment:
844
864
  Description: 'Align block ends correctly.'
845
865
  Enabled: true
846
866
 
867
+ Lint/CircularArgumentReference:
868
+ Description: "Don't refer to the keyword argument in the default value."
869
+ Enabled: true
870
+
847
871
  Lint/ConditionPosition:
848
872
  Description: >-
849
873
  Checks for condition placed in a confusing position relative to
@@ -900,6 +924,10 @@ Lint/Eval:
900
924
  Description: 'The use of eval represents a serious security risk.'
901
925
  Enabled: true
902
926
 
927
+ Lint/FormatParameterMismatch:
928
+ Description: 'The number of parameters to format/sprint must match the fields.'
929
+ Enabled: true
930
+
903
931
  Lint/HandleExceptions:
904
932
  Description: "Don't suppress exception."
905
933
  StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#dont-hide-exceptions'
@@ -975,7 +1003,10 @@ Lint/UnderscorePrefixedVariableName:
975
1003
  Enabled: true
976
1004
 
977
1005
  Lint/UnneededDisable:
978
- Description: 'Checks for rubocop:disable comments that can be removed.'
1006
+ Description: >-
1007
+ Checks for rubocop:disable comments that can be removed.
1008
+ Note: this cop is not disabled when disabling all cops.
1009
+ It must be explicitly disabled.
979
1010
  Enabled: true
980
1011
 
981
1012
  Lint/UnusedBlockArgument:
@@ -1065,6 +1096,14 @@ Performance/Size:
1065
1096
  Reference: 'https://github.com/JuanitoFatas/fast-ruby#arraycount-vs-arraysize-code'
1066
1097
  Enabled: true
1067
1098
 
1099
+ Performance/StringReplacement:
1100
+ Description: >-
1101
+ Use `tr` instead of `gsub` when you are replacing the same
1102
+ number of characters. Use `delete` instead of `gsub` when
1103
+ you are deleting characters.
1104
+ Reference: 'https://github.com/JuanitoFatas/fast-ruby#stringgsub-vs-stringtr-code'
1105
+ Enabled: true
1106
+
1068
1107
  ##################### Rails ##################################
1069
1108
 
1070
1109
  Rails/ActionFilter:
@@ -72,6 +72,7 @@ require 'rubocop/cop/lint/ambiguous_operator'
72
72
  require 'rubocop/cop/lint/ambiguous_regexp_literal'
73
73
  require 'rubocop/cop/lint/assignment_in_condition'
74
74
  require 'rubocop/cop/lint/block_alignment'
75
+ require 'rubocop/cop/lint/circular_argument_reference'
75
76
  require 'rubocop/cop/lint/condition_position'
76
77
  require 'rubocop/cop/lint/debugger'
77
78
  require 'rubocop/cop/lint/def_end_alignment'
@@ -85,6 +86,7 @@ require 'rubocop/cop/lint/end_alignment'
85
86
  require 'rubocop/cop/lint/end_in_method'
86
87
  require 'rubocop/cop/lint/ensure_return'
87
88
  require 'rubocop/cop/lint/eval'
89
+ require 'rubocop/cop/lint/format_parameter_mismatch'
88
90
  require 'rubocop/cop/lint/handle_exceptions'
89
91
  require 'rubocop/cop/lint/invalid_character_literal'
90
92
  require 'rubocop/cop/lint/literal_in_condition'
@@ -127,6 +129,7 @@ require 'rubocop/cop/performance/flat_map'
127
129
  require 'rubocop/cop/performance/reverse_each'
128
130
  require 'rubocop/cop/performance/sample'
129
131
  require 'rubocop/cop/performance/size'
132
+ require 'rubocop/cop/performance/string_replacement'
130
133
 
131
134
  require 'rubocop/cop/style/access_modifier_indentation'
132
135
  require 'rubocop/cop/style/accessor_method_name'
@@ -199,6 +202,7 @@ require 'rubocop/cop/style/indent_hash'
199
202
  require 'rubocop/cop/style/indentation_consistency'
200
203
  require 'rubocop/cop/style/indentation_width'
201
204
  require 'rubocop/cop/style/infinite_loop'
205
+ require 'rubocop/cop/style/initial_indentation'
202
206
  require 'rubocop/cop/style/inline_comment'
203
207
  require 'rubocop/cop/style/lambda'
204
208
  require 'rubocop/cop/style/lambda_call'
@@ -224,6 +228,8 @@ require 'rubocop/cop/style/not'
224
228
  require 'rubocop/cop/style/numeric_literals'
225
229
  require 'rubocop/cop/style/one_line_conditional'
226
230
  require 'rubocop/cop/style/op_method'
231
+ require 'rubocop/cop/style/optional_arguments'
232
+ require 'rubocop/cop/style/option_hash'
227
233
  require 'rubocop/cop/style/parallel_assignment'
228
234
  require 'rubocop/cop/style/parentheses_around_condition'
229
235
  require 'rubocop/cop/style/percent_literal_delimiters'
@@ -237,9 +243,11 @@ require 'rubocop/cop/style/redundant_exception'
237
243
  require 'rubocop/cop/style/redundant_return'
238
244
  require 'rubocop/cop/style/redundant_self'
239
245
  require 'rubocop/cop/style/regexp_literal'
246
+ require 'rubocop/cop/style/rescue_ensure_alignment'
240
247
  require 'rubocop/cop/style/rescue_modifier'
241
248
  require 'rubocop/cop/style/self_assignment'
242
249
  require 'rubocop/cop/style/semicolon'
250
+ require 'rubocop/cop/style/send'
243
251
  require 'rubocop/cop/style/signal_exception'
244
252
  require 'rubocop/cop/style/single_line_block_params'
245
253
  require 'rubocop/cop/style/single_line_methods'
@@ -53,6 +53,7 @@ module RuboCop
53
53
 
54
54
  ConfigLoader.debug = @options[:debug]
55
55
  ConfigLoader.auto_gen_config = @options[:auto_gen_config]
56
+ ConfigLoader.exclude_limit = @options[:exclude_limit]
56
57
 
57
58
  @config_store.options_config = @options[:config] if @options[:config]
58
59
 
@@ -16,7 +16,7 @@ module RuboCop
16
16
  AUTO_GENERATED_FILE = '.rubocop_todo.yml'
17
17
 
18
18
  class << self
19
- attr_accessor :debug, :auto_gen_config
19
+ attr_accessor :debug, :auto_gen_config, :exclude_limit
20
20
  attr_writer :root_level # The upwards search is stopped at this level.
21
21
 
22
22
  alias_method :debug?, :debug
@@ -100,12 +100,33 @@ module RuboCop
100
100
  end
101
101
  end
102
102
 
103
+ # Merges the given configuration with the default one. If
104
+ # AllCops:DisabledByDefault is true, it changes the Enabled params so
105
+ # that only cops from user configuration are enabled.
103
106
  def merge_with_default(config, config_file)
104
- Config.new(merge(default_configuration, config), config_file)
107
+ configs =
108
+ if config.key?('AllCops') && config['AllCops']['DisabledByDefault']
109
+ disabled_default = transform(default_configuration) do |params|
110
+ params.merge('Enabled' => false) # Overwrite with false.
111
+ end
112
+ enabled_user_config = transform(config) do |params|
113
+ { 'Enabled' => true }.merge(params) # Set true if not set.
114
+ end
115
+ [disabled_default, enabled_user_config]
116
+ else
117
+ [default_configuration, config]
118
+ end
119
+ Config.new(merge(configs.first, configs.last), config_file)
105
120
  end
106
121
 
107
122
  private
108
123
 
124
+ # Returns a new hash where the parameters of the given config hash have
125
+ # been replaced by parmeters returned by the given block.
126
+ def transform(config)
127
+ Hash[config.map { |cop, params| [cop, yield(params)] }]
128
+ end
129
+
109
130
  def load_yaml_configuration(absolute_path)
110
131
  yaml_code = IO.read(absolute_path)
111
132
  # At one time, there was a problem with the psych YAML engine under
@@ -14,7 +14,7 @@ module RuboCop
14
14
  class BlockAlignment < Cop
15
15
  include CheckAssignment
16
16
 
17
- MSG = '`end` at %d, %d is not aligned with `%s` at %d, %d%s'
17
+ MSG = '`end` at %d, %d is not aligned with `%s` at %d, %d%s.'
18
18
 
19
19
  def on_block(node)
20
20
  return if ignored_node?(node)
@@ -0,0 +1,38 @@
1
+ # encoding: utf-8
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module Lint
6
+ # This cop checks for circular argument references in keyword arguments.
7
+ #
8
+ # This cop mirrors a warning produced by MRI since 2.2.
9
+ #
10
+ # @example
11
+ # def bake(pie: pie)
12
+ # pie.heat_up
13
+ # end
14
+ class CircularArgumentReference < Cop
15
+ MSG = 'Circular argument reference - `%s`.'
16
+
17
+ def on_kwoptarg(node)
18
+ arg_name, arg_value = *node
19
+ case arg_value.type
20
+ when :send
21
+ # Ruby 2.0 will have type send every time, and "send nil" if it is
22
+ # calling itself with a specified "self" receiver
23
+ receiver, name = *arg_value
24
+ return unless name == arg_name && receiver.nil?
25
+ when :lvar
26
+ # Ruby 2.2.2 will have type lvar if it is calling its own method
27
+ # without a specified "self"
28
+ return unless arg_value.to_a == [arg_name]
29
+ else
30
+ return
31
+ end
32
+
33
+ add_offense(arg_value, :expression, format(MSG, arg_name))
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end