rubocop 0.30.1 → 0.31.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +38 -0
- data/README.md +10 -0
- data/config/default.yml +8 -1
- data/config/enabled.yml +28 -0
- data/lib/rubocop.rb +7 -0
- data/lib/rubocop/cli.rb +3 -2
- data/lib/rubocop/config.rb +12 -18
- data/lib/rubocop/cop/autocorrect_logic.rb +1 -1
- data/lib/rubocop/cop/cop.rb +35 -23
- data/lib/rubocop/cop/lint/block_alignment.rb +1 -1
- data/lib/rubocop/cop/lint/def_end_alignment.rb +6 -0
- data/lib/rubocop/cop/lint/deprecated_class_methods.rb +1 -1
- data/lib/rubocop/cop/lint/each_with_object_argument.rb +29 -0
- data/lib/rubocop/cop/lint/end_alignment.rb +5 -0
- data/lib/rubocop/cop/lint/require_parentheses.rb +1 -1
- data/lib/rubocop/cop/lint/space_before_first_arg.rb +1 -1
- data/lib/rubocop/cop/lint/string_conversion_in_interpolation.rb +1 -1
- data/lib/rubocop/cop/metrics/class_length.rb +1 -25
- data/lib/rubocop/cop/metrics/module_length.rb +24 -0
- data/lib/rubocop/cop/metrics/parameter_lists.rb +1 -1
- data/lib/rubocop/cop/mixin/autocorrect_alignment.rb +2 -2
- data/lib/rubocop/cop/mixin/autocorrect_unless_changing_ast.rb +2 -2
- data/lib/rubocop/cop/mixin/classish_length.rb +37 -0
- data/lib/rubocop/cop/mixin/empty_lines_around_body.rb +1 -1
- data/lib/rubocop/cop/mixin/end_keyword_alignment.rb +14 -1
- data/lib/rubocop/cop/mixin/min_body_length.rb +19 -0
- data/lib/rubocop/cop/mixin/on_method_def.rb +1 -0
- data/lib/rubocop/cop/mixin/space_after_punctuation.rb +2 -4
- data/lib/rubocop/cop/mixin/space_before_punctuation.rb +1 -3
- data/lib/rubocop/cop/mixin/space_inside.rb +1 -1
- data/lib/rubocop/cop/mixin/statement_modifier.rb +14 -7
- data/lib/rubocop/cop/mixin/string_literals_help.rb +1 -1
- data/lib/rubocop/cop/mixin/unused_argument.rb +1 -3
- data/lib/rubocop/cop/performance/count.rb +84 -0
- data/lib/rubocop/cop/performance/detect.rb +1 -1
- data/lib/rubocop/cop/performance/flat_map.rb +2 -1
- data/lib/rubocop/cop/performance/parallel_assignment.rb +79 -0
- data/lib/rubocop/cop/performance/reverse_each.rb +1 -3
- data/lib/rubocop/cop/performance/sample.rb +25 -18
- data/lib/rubocop/cop/performance/size.rb +1 -3
- data/lib/rubocop/cop/rails/action_filter.rb +1 -1
- data/lib/rubocop/cop/rails/delegate.rb +2 -5
- data/lib/rubocop/cop/rails/find_by.rb +1 -1
- data/lib/rubocop/cop/rails/find_each.rb +1 -3
- data/lib/rubocop/cop/rails/read_write_attribute.rb +1 -3
- data/lib/rubocop/cop/rails/time_zone.rb +29 -7
- data/lib/rubocop/cop/style/alias.rb +1 -1
- data/lib/rubocop/cop/style/align_hash.rb +11 -14
- data/lib/rubocop/cop/style/array_join.rb +11 -0
- data/lib/rubocop/cop/style/attr.rb +1 -3
- data/lib/rubocop/cop/style/bare_percent_literals.rb +1 -1
- data/lib/rubocop/cop/style/block_comments.rb +1 -1
- data/lib/rubocop/cop/style/block_delimiters.rb +2 -9
- data/lib/rubocop/cop/style/block_end_newline.rb +1 -1
- data/lib/rubocop/cop/style/braces_around_hash_parameters.rb +1 -1
- data/lib/rubocop/cop/style/character_literal.rb +1 -1
- data/lib/rubocop/cop/style/class_check.rb +1 -1
- data/lib/rubocop/cop/style/class_methods.rb +1 -3
- data/lib/rubocop/cop/style/collection_methods.rb +1 -1
- data/lib/rubocop/cop/style/colon_method_call.rb +1 -3
- data/lib/rubocop/cop/style/command_literal.rb +2 -2
- data/lib/rubocop/cop/style/comment_annotation.rb +9 -2
- data/lib/rubocop/cop/style/copyright.rb +1 -1
- data/lib/rubocop/cop/style/def_with_parentheses.rb +1 -1
- data/lib/rubocop/cop/style/deprecated_hash_methods.rb +1 -1
- data/lib/rubocop/cop/style/dot_position.rb +1 -1
- data/lib/rubocop/cop/style/empty_line_between_defs.rb +1 -3
- data/lib/rubocop/cop/style/empty_lines.rb +1 -1
- data/lib/rubocop/cop/style/empty_lines_around_access_modifier.rb +1 -1
- data/lib/rubocop/cop/style/empty_literal.rb +2 -6
- data/lib/rubocop/cop/style/encoding.rb +1 -1
- data/lib/rubocop/cop/style/even_odd.rb +2 -4
- data/lib/rubocop/cop/style/extra_spacing.rb +1 -3
- data/lib/rubocop/cop/style/guard_clause.rb +1 -11
- data/lib/rubocop/cop/style/hash_syntax.rb +1 -1
- data/lib/rubocop/cop/style/if_unless_modifier.rb +11 -6
- data/lib/rubocop/cop/style/indentation_width.rb +11 -2
- data/lib/rubocop/cop/style/infinite_loop.rb +8 -8
- data/lib/rubocop/cop/style/lambda_call.rb +1 -1
- data/lib/rubocop/cop/style/leading_comment_space.rb +1 -3
- data/lib/rubocop/cop/style/line_end_concatenation.rb +5 -7
- data/lib/rubocop/cop/style/method_call_parentheses.rb +1 -8
- data/lib/rubocop/cop/style/method_def_parentheses.rb +1 -1
- data/lib/rubocop/cop/style/multiline_block_chain.rb +2 -1
- data/lib/rubocop/cop/style/multiline_block_layout.rb +11 -8
- data/lib/rubocop/cop/style/multiline_if_then.rb +1 -1
- data/lib/rubocop/cop/style/multiline_operation_indentation.rb +3 -2
- data/lib/rubocop/cop/style/multiline_ternary_operator.rb +2 -1
- data/lib/rubocop/cop/style/negated_if.rb +1 -1
- data/lib/rubocop/cop/style/negated_while.rb +2 -2
- data/lib/rubocop/cop/style/next.rb +1 -11
- data/lib/rubocop/cop/style/nil_comparison.rb +3 -5
- data/lib/rubocop/cop/style/non_nil_check.rb +2 -2
- data/lib/rubocop/cop/style/not.rb +3 -5
- data/lib/rubocop/cop/style/numeric_literals.rb +2 -5
- data/lib/rubocop/cop/style/parentheses_around_condition.rb +1 -1
- data/lib/rubocop/cop/style/percent_literal_delimiters.rb +1 -1
- data/lib/rubocop/cop/style/percent_q_literals.rb +1 -1
- data/lib/rubocop/cop/style/perl_backrefs.rb +1 -1
- data/lib/rubocop/cop/style/proc.rb +1 -3
- data/lib/rubocop/cop/style/redundant_begin.rb +1 -1
- data/lib/rubocop/cop/style/redundant_exception.rb +6 -8
- data/lib/rubocop/cop/style/redundant_return.rb +1 -1
- data/lib/rubocop/cop/style/redundant_self.rb +2 -2
- data/lib/rubocop/cop/style/regexp_literal.rb +2 -2
- data/lib/rubocop/cop/style/self_assignment.rb +1 -1
- data/lib/rubocop/cop/style/semicolon.rb +2 -2
- data/lib/rubocop/cop/style/signal_exception.rb +1 -1
- data/lib/rubocop/cop/style/single_line_methods.rb +1 -1
- data/lib/rubocop/cop/style/single_space_before_first_arg.rb +1 -1
- data/lib/rubocop/cop/style/space_after_colon.rb +1 -3
- data/lib/rubocop/cop/style/space_after_control_keyword.rb +1 -3
- data/lib/rubocop/cop/style/space_after_method_name.rb +1 -3
- data/lib/rubocop/cop/style/space_after_not.rb +1 -1
- data/lib/rubocop/cop/style/space_around_block_parameters.rb +34 -16
- data/lib/rubocop/cop/style/space_around_equals_in_parameter_default.rb +1 -3
- data/lib/rubocop/cop/style/space_around_operators.rb +3 -2
- data/lib/rubocop/cop/style/space_before_block_braces.rb +1 -1
- data/lib/rubocop/cop/style/space_before_comment.rb +1 -3
- data/lib/rubocop/cop/style/space_before_modifier_keyword.rb +1 -3
- data/lib/rubocop/cop/style/space_inside_block_braces.rb +5 -3
- data/lib/rubocop/cop/style/space_inside_hash_literal_braces.rb +1 -1
- data/lib/rubocop/cop/style/space_inside_range_literal.rb +1 -1
- data/lib/rubocop/cop/style/special_global_vars.rb +1 -1
- data/lib/rubocop/cop/style/symbol_literal.rb +1 -1
- data/lib/rubocop/cop/style/symbol_proc.rb +1 -1
- data/lib/rubocop/cop/style/tab.rb +1 -1
- data/lib/rubocop/cop/style/trailing_blank_lines.rb +2 -2
- data/lib/rubocop/cop/style/trailing_comma.rb +1 -1
- data/lib/rubocop/cop/style/trailing_underscore_variable.rb +72 -0
- data/lib/rubocop/cop/style/trailing_whitespace.rb +1 -1
- data/lib/rubocop/cop/style/trivial_accessors.rb +5 -10
- data/lib/rubocop/cop/style/unneeded_capital_w.rb +1 -1
- data/lib/rubocop/cop/style/unneeded_percent_q.rb +1 -1
- data/lib/rubocop/cop/style/variable_interpolation.rb +2 -4
- data/lib/rubocop/cop/style/when_then.rb +1 -3
- data/lib/rubocop/cop/style/while_until_do.rb +5 -7
- data/lib/rubocop/cop/style/while_until_modifier.rb +4 -6
- data/lib/rubocop/cop/style/word_array.rb +1 -1
- data/lib/rubocop/cop/util.rb +6 -3
- data/lib/rubocop/formatter/progress_formatter.rb +3 -2
- data/lib/rubocop/formatter/simple_text_formatter.rb +1 -1
- data/lib/rubocop/rake_task.rb +2 -2
- data/lib/rubocop/runner.rb +2 -11
- data/lib/rubocop/string_util.rb +4 -2
- data/lib/rubocop/token.rb +3 -1
- data/lib/rubocop/version.rb +1 -1
- data/relnotes/v0.31.0.md +120 -0
- metadata +10 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c41bd779d02cd33eca9911b0c15c002ec42715b7
|
4
|
+
data.tar.gz: b8cacc39e2c68e7122bf50b78c163fd7b3df3e73
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8e5e0fd412cc13b16887e3043a2e00d55cf7f65b10bd73fc00729d0ec48c13e9e6a7867616b2ba3b509f43e9a010a2db295fd5ffd944b1755189aeb695690063
|
7
|
+
data.tar.gz: 583b7509b1ac9536f4d78533a92376501b007275796c87bd7623575a99377610141406613f1ce8c809bbc71a146908ed82e61a9b77765bd2b4e4c387f8168c33
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,37 @@
|
|
2
2
|
|
3
3
|
## master (unreleased)
|
4
4
|
|
5
|
+
## 0.31.0 (05/05/2015)
|
6
|
+
|
7
|
+
### New features
|
8
|
+
|
9
|
+
* `Rails/TimeZone` emits acceptable methods on a violation when `EnforcedStyle` is `:acceptable`. ([@l8nite][])
|
10
|
+
* Recognize rackup file (config.ru) out of the box. ([@carhartl][])
|
11
|
+
* [#1788](https://github.com/bbatsov/rubocop/pull/1788): New cop `ModuleLength` checks for overly long module definitions. ([@sdeframond][])
|
12
|
+
* New cop `Performance/Count` to convert `Enumerable#select...size`, `Enumerable#reject...size`, `Enumerable#select...count`, `Enumerable#reject...count` `Enumerable#select...length`, and `Enumerable#reject...length` to `Enumerable#count`. ([@rrosenblum][])
|
13
|
+
* `CommentAnnotation` cop does auto-correction. ([@dylandavidson][])
|
14
|
+
* New cop `Style/TrailingUnderscoreVariable` to remove trailing underscore variables from mass assignment. ([@rrosenblum][])
|
15
|
+
* [#1136](https://github.com/bbatsov/rubocop/issues/1136): New cop `Performance/ParallelAssignment` to avoid usages of unnessary parallel assignment. ([@rrosenblum][])
|
16
|
+
* [#1278](https://github.com/bbatsov/rubocop/issues/1278): `DefEndAlignment` and `EndAlignment` cops do auto-correction. ([@lumeet][])
|
17
|
+
* `IndentationWidth` cop follows the `AlignWith` option of the `DefEndAlignment` cop. ([@lumeet][])
|
18
|
+
* [#1837](https://github.com/bbatsov/rubocop/issues/1837): New cop `EachWithObjectArgument` checks that `each_with_object` isn't called with an immutable object as argument. ([@jonas054][])
|
19
|
+
* `ArrayJoin` cop does auto-correction. ([@tmr08c][])
|
20
|
+
|
21
|
+
### Bugs fixed
|
22
|
+
|
23
|
+
* [#1816](https://github.com/bbatsov/rubocop/issues/1816): Fix bug in `Sample` when calling `#shuffle` with something other than an element selector. ([@rrosenblum][])
|
24
|
+
* [#1768](https://github.com/bbatsov/rubocop/pull/1768): `DefEndAlignment` recognizes preceding `private_class_method` or `public_class_method` before `def`. ([@til][])
|
25
|
+
* [#1820](https://github.com/bbatsov/rubocop/issues/1820): Correct the logic in `AlignHash` for when to ignore a key because it's not on its own line. ([@jonas054][])
|
26
|
+
* [#1829](https://github.com/bbatsov/rubocop/pull/1829): Fix bug in `Sample` and `FlatMap` that would cause them to report having been auto-corrected when they were not. ([@rrosenblum][])
|
27
|
+
* [#1832](https://github.com/bbatsov/rubocop/pull/1832): Fix bug in `UnusedMethodArgument` that would cause them to report having been auto-corrected when they were not. ([@jonas054][])
|
28
|
+
* [#1834](https://github.com/bbatsov/rubocop/issues/1834): Support only boolean values for `AutoCorrect` configuration parameter, and remove warning for unknown parameter. ([@jonas054][])
|
29
|
+
* [#1843](https://github.com/bbatsov/rubocop/issues/1843): Fix crash in `TrailingBlankLines` when a file ends with a block comment without final newline. ([@jonas054][])
|
30
|
+
* [#1849](https://github.com/bbatsov/rubocop/issues/1849): Fix bug where you can not have nested arrays in the Rake task configuration. ([@rrosenblum][])
|
31
|
+
* Fix bug in `MultilineTernaryOperator` where it will not register an offense when only the false branch is on a separate line. ([@rrosenblum][])
|
32
|
+
* Fix crash in `MultilineBlockLayout` when using new lambda literal syntax without parentheses. ([@hbd225][])
|
33
|
+
* [#1859](https://github.com/bbatsov/rubocop/pull/1859): Fix bugs in `IfUnlessModifier` concerning comments and empty lines. ([@jonas054][])
|
34
|
+
* Fix handling of trailing comma in `SpaceAroundBlockParameters` and `SpaceAfterComma`. ([@lumeet][])
|
35
|
+
|
5
36
|
## 0.30.1 (21/04/2015)
|
6
37
|
|
7
38
|
### Bugs fixed
|
@@ -1355,3 +1386,10 @@
|
|
1355
1386
|
[@bankair]: https://github.com/bankair
|
1356
1387
|
[@crimsonknave]: https://github.com/crimsonknave
|
1357
1388
|
[@renuo]: https://github.com/renuo
|
1389
|
+
[@sdeframond]: https://github.com/sdeframond
|
1390
|
+
[@til]: https://github.com/til
|
1391
|
+
[@carhartl]: https://github.com/carhartl
|
1392
|
+
[@dylandavidson]: https://github.com/dylandavidson
|
1393
|
+
[@tmr08c]: https://github.com/tmr08c
|
1394
|
+
[@hbd225]: https://github.com/hbd225
|
1395
|
+
[@l8nite]: https://github.com/l8nite
|
data/README.md
CHANGED
@@ -384,6 +384,16 @@ Metrics/CyclomaticComplexity:
|
|
384
384
|
Severity: warning
|
385
385
|
```
|
386
386
|
|
387
|
+
#### AutoCorrect
|
388
|
+
|
389
|
+
Cops that support the `--auto-correct` option can have that support
|
390
|
+
disabled. For example:
|
391
|
+
|
392
|
+
```yaml
|
393
|
+
Style/PerlBackrefs:
|
394
|
+
AutoCorrect: false
|
395
|
+
```
|
396
|
+
|
387
397
|
### Automatically Generated Configuration
|
388
398
|
|
389
399
|
If you have a code base with an overwhelming amount of offenses, it can
|
data/config/default.yml
CHANGED
@@ -7,13 +7,14 @@ inherit_from:
|
|
7
7
|
|
8
8
|
# Common configuration.
|
9
9
|
AllCops:
|
10
|
-
# Include
|
10
|
+
# Include common Ruby source files.
|
11
11
|
Include:
|
12
12
|
- '**/*.gemspec'
|
13
13
|
- '**/*.podspec'
|
14
14
|
- '**/*.jbuilder'
|
15
15
|
- '**/*.rake'
|
16
16
|
- '**/*.opal'
|
17
|
+
- '**/config.ru'
|
17
18
|
- '**/Gemfile'
|
18
19
|
- '**/Rakefile'
|
19
20
|
- '**/Capfile'
|
@@ -735,6 +736,10 @@ Metrics/ClassLength:
|
|
735
736
|
CountComments: false # count full line comments?
|
736
737
|
Max: 100
|
737
738
|
|
739
|
+
Metrics/ModuleLength:
|
740
|
+
CountComments: false # count full line comments?
|
741
|
+
Max: 100
|
742
|
+
|
738
743
|
# Avoid complex methods.
|
739
744
|
Metrics/CyclomaticComplexity:
|
740
745
|
Max: 6
|
@@ -776,6 +781,7 @@ Lint/EndAlignment:
|
|
776
781
|
SupportedStyles:
|
777
782
|
- keyword
|
778
783
|
- variable
|
784
|
+
AutoCorrect: false
|
779
785
|
|
780
786
|
Lint/DefEndAlignment:
|
781
787
|
# The value `def` means that `end` should be aligned with the def keyword.
|
@@ -786,6 +792,7 @@ Lint/DefEndAlignment:
|
|
786
792
|
SupportedStyles:
|
787
793
|
- start_of_line
|
788
794
|
- def
|
795
|
+
AutoCorrect: false
|
789
796
|
|
790
797
|
##################### Rails ##################################
|
791
798
|
|
data/config/enabled.yml
CHANGED
@@ -714,6 +714,12 @@ Style/UnneededPercentQ:
|
|
714
714
|
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#percent-q'
|
715
715
|
Enabled: true
|
716
716
|
|
717
|
+
Style/TrailingUnderscoreVariable:
|
718
|
+
Description: >-
|
719
|
+
Checks for the usage of unneeded trailing underscores at the
|
720
|
+
end of parallel variable assignment.
|
721
|
+
Enabled: true
|
722
|
+
|
717
723
|
Style/VariableInterpolation:
|
718
724
|
Description: >-
|
719
725
|
Don't interpolate global, instance and class variables
|
@@ -765,6 +771,10 @@ Metrics/ClassLength:
|
|
765
771
|
Description: 'Avoid classes longer than 100 lines of code.'
|
766
772
|
Enabled: true
|
767
773
|
|
774
|
+
Metrics/ModuleLength:
|
775
|
+
Description: 'Avoid modules longer than 100 lines of code.'
|
776
|
+
Enabled: true
|
777
|
+
|
768
778
|
Metrics/CyclomaticComplexity:
|
769
779
|
Description: >-
|
770
780
|
A complexity metric that is strongly correlated to the number
|
@@ -840,6 +850,10 @@ Lint/DuplicateMethods:
|
|
840
850
|
Description: 'Check for duplicate methods calls.'
|
841
851
|
Enabled: true
|
842
852
|
|
853
|
+
Lint/EachWithObjectArgument:
|
854
|
+
Description: 'Check for immutable argument given to each_with_object.'
|
855
|
+
Enabled: true
|
856
|
+
|
843
857
|
Lint/ElseLayout:
|
844
858
|
Description: 'Check for odd code arrangement in an else block.'
|
845
859
|
Enabled: true
|
@@ -979,6 +993,13 @@ Lint/Void:
|
|
979
993
|
|
980
994
|
##################### Performance #############################
|
981
995
|
|
996
|
+
Performance/Count:
|
997
|
+
Description: >-
|
998
|
+
Use `count` instead of `select...size`, `reject...size`,
|
999
|
+
`select...count`, `reject...count`, `select...length`,
|
1000
|
+
and `reject...length`.
|
1001
|
+
Enabled: true
|
1002
|
+
|
982
1003
|
Performance/Detect:
|
983
1004
|
Description: >-
|
984
1005
|
Use `detect` instead of `select.first`, `find_all.first`,
|
@@ -997,6 +1018,13 @@ Performance/FlatMap:
|
|
997
1018
|
# This can be dangerous since `flat_map` will only flatten 1 level, and
|
998
1019
|
# `flatten` without any parameters can flatten multiple levels.
|
999
1020
|
|
1021
|
+
Performance/ParallelAssignment:
|
1022
|
+
Description: >-
|
1023
|
+
Check for simple usages of parallel assignment.
|
1024
|
+
It will only warn when the number of variables
|
1025
|
+
matches on both sides of the assignment.
|
1026
|
+
Enabled: true
|
1027
|
+
|
1000
1028
|
Performance/ReverseEach:
|
1001
1029
|
Description: 'Use `reverse_each` instead of `reverse.each`.'
|
1002
1030
|
Enabled: true
|
data/lib/rubocop.rb
CHANGED
@@ -45,6 +45,7 @@ require 'rubocop/cop/mixin/autocorrect_unless_changing_ast'
|
|
45
45
|
require 'rubocop/cop/mixin/check_assignment'
|
46
46
|
require 'rubocop/cop/mixin/configurable_max'
|
47
47
|
require 'rubocop/cop/mixin/code_length'
|
48
|
+
require 'rubocop/cop/mixin/classish_length'
|
48
49
|
require 'rubocop/cop/mixin/configurable_enforced_style'
|
49
50
|
require 'rubocop/cop/mixin/configurable_naming'
|
50
51
|
require 'rubocop/cop/mixin/empty_lines_around_body'
|
@@ -53,6 +54,7 @@ require 'rubocop/cop/mixin/if_node'
|
|
53
54
|
require 'rubocop/cop/mixin/negative_conditional'
|
54
55
|
require 'rubocop/cop/mixin/on_method_def'
|
55
56
|
require 'rubocop/cop/mixin/method_complexity'
|
57
|
+
require 'rubocop/cop/mixin/min_body_length'
|
56
58
|
require 'rubocop/cop/mixin/on_normal_if_unless'
|
57
59
|
require 'rubocop/cop/mixin/parser_diagnostic'
|
58
60
|
require 'rubocop/cop/mixin/percent_literal'
|
@@ -75,6 +77,7 @@ require 'rubocop/cop/lint/debugger'
|
|
75
77
|
require 'rubocop/cop/lint/def_end_alignment'
|
76
78
|
require 'rubocop/cop/lint/deprecated_class_methods'
|
77
79
|
require 'rubocop/cop/lint/duplicate_methods'
|
80
|
+
require 'rubocop/cop/lint/each_with_object_argument'
|
78
81
|
require 'rubocop/cop/lint/else_layout'
|
79
82
|
require 'rubocop/cop/lint/empty_ensure'
|
80
83
|
require 'rubocop/cop/lint/empty_interpolation'
|
@@ -108,6 +111,7 @@ require 'rubocop/cop/lint/void'
|
|
108
111
|
|
109
112
|
require 'rubocop/cop/metrics/block_nesting'
|
110
113
|
require 'rubocop/cop/metrics/class_length'
|
114
|
+
require 'rubocop/cop/metrics/module_length'
|
111
115
|
require 'rubocop/cop/metrics/cyclomatic_complexity'
|
112
116
|
require 'rubocop/cop/metrics/abc_size'
|
113
117
|
require 'rubocop/cop/metrics/line_length'
|
@@ -115,8 +119,10 @@ require 'rubocop/cop/metrics/method_length'
|
|
115
119
|
require 'rubocop/cop/metrics/parameter_lists'
|
116
120
|
require 'rubocop/cop/metrics/perceived_complexity'
|
117
121
|
|
122
|
+
require 'rubocop/cop/performance/count'
|
118
123
|
require 'rubocop/cop/performance/detect'
|
119
124
|
require 'rubocop/cop/performance/flat_map'
|
125
|
+
require 'rubocop/cop/performance/parallel_assignment'
|
120
126
|
require 'rubocop/cop/performance/reverse_each'
|
121
127
|
require 'rubocop/cop/performance/sample'
|
122
128
|
require 'rubocop/cop/performance/size'
|
@@ -270,6 +276,7 @@ require 'rubocop/cop/style/trivial_accessors'
|
|
270
276
|
require 'rubocop/cop/style/unless_else'
|
271
277
|
require 'rubocop/cop/style/unneeded_capital_w'
|
272
278
|
require 'rubocop/cop/style/unneeded_percent_q'
|
279
|
+
require 'rubocop/cop/style/trailing_underscore_variable'
|
273
280
|
require 'rubocop/cop/style/variable_interpolation'
|
274
281
|
require 'rubocop/cop/style/variable_name'
|
275
282
|
require 'rubocop/cop/style/when_then'
|
data/lib/rubocop/cli.rb
CHANGED
@@ -4,6 +4,8 @@ module RuboCop
|
|
4
4
|
# The CLI is a class responsible of handling all the command line interface
|
5
5
|
# logic.
|
6
6
|
class CLI
|
7
|
+
include Formatter::TextUtil
|
8
|
+
|
7
9
|
attr_reader :options, :config_store
|
8
10
|
|
9
11
|
def initialize
|
@@ -100,8 +102,7 @@ module RuboCop
|
|
100
102
|
def display_error_summary(errors)
|
101
103
|
return if errors.empty?
|
102
104
|
|
103
|
-
|
104
|
-
warn "\n#{errors.count} error#{plural} occurred:".color(:red)
|
105
|
+
warn "\n#{pluralize(errors.size, 'error')} occurred:".color(:red)
|
105
106
|
|
106
107
|
errors.each { |error| warn error }
|
107
108
|
|
data/lib/rubocop/config.rb
CHANGED
@@ -14,14 +14,13 @@ module RuboCop
|
|
14
14
|
|
15
15
|
class ValidationError < StandardError; end
|
16
16
|
|
17
|
-
COMMON_PARAMS = %w(Exclude Include Severity)
|
17
|
+
COMMON_PARAMS = %w(Exclude Include Severity AutoCorrect)
|
18
18
|
|
19
19
|
attr_reader :loaded_path
|
20
20
|
|
21
21
|
def initialize(hash = {}, loaded_path = nil)
|
22
|
-
@hash = hash
|
23
22
|
@loaded_path = loaded_path
|
24
|
-
super(
|
23
|
+
super(hash)
|
25
24
|
end
|
26
25
|
|
27
26
|
def make_excludes_absolute
|
@@ -31,9 +30,8 @@ module RuboCop
|
|
31
30
|
|
32
31
|
self[key]['Exclude'].map! do |exclude_elem|
|
33
32
|
if exclude_elem.is_a?(String) && !exclude_elem.start_with?('/')
|
34
|
-
File.expand_path(
|
35
|
-
|
36
|
-
)
|
33
|
+
File.expand_path(File.join(base_dir_for_path_parameters,
|
34
|
+
exclude_elem))
|
37
35
|
else
|
38
36
|
exclude_elem
|
39
37
|
end
|
@@ -102,13 +100,12 @@ module RuboCop
|
|
102
100
|
'config'))
|
103
101
|
return if File.expand_path(loaded_path).start_with?(base_config_path)
|
104
102
|
|
105
|
-
valid_cop_names, invalid_cop_names =
|
103
|
+
valid_cop_names, invalid_cop_names = keys.partition do |key|
|
106
104
|
ConfigLoader.default_configuration.key?(key)
|
107
105
|
end
|
108
106
|
|
109
107
|
invalid_cop_names.each do |name|
|
110
|
-
fail ValidationError,
|
111
|
-
"unrecognized cop #{name} found in #{loaded_path || self}"
|
108
|
+
fail ValidationError, "unrecognized cop #{name} found in #{loaded_path}"
|
112
109
|
end
|
113
110
|
|
114
111
|
validate_parameter_names(valid_cop_names)
|
@@ -150,11 +147,11 @@ module RuboCop
|
|
150
147
|
end
|
151
148
|
|
152
149
|
def patterns_to_include
|
153
|
-
|
150
|
+
self['AllCops']['Include']
|
154
151
|
end
|
155
152
|
|
156
153
|
def patterns_to_exclude
|
157
|
-
|
154
|
+
self['AllCops']['Exclude']
|
158
155
|
end
|
159
156
|
|
160
157
|
def path_relative_to_config(path)
|
@@ -176,22 +173,19 @@ module RuboCop
|
|
176
173
|
private
|
177
174
|
|
178
175
|
def validate_section_presence(name)
|
179
|
-
return unless
|
180
|
-
fail ValidationError,
|
181
|
-
"empty section #{name} found " \
|
182
|
-
"in #{loaded_path || self}"
|
176
|
+
return unless key?(name) && self[name].nil?
|
177
|
+
fail ValidationError, "empty section #{name} found in #{loaded_path}"
|
183
178
|
end
|
184
179
|
|
185
180
|
def validate_parameter_names(valid_cop_names)
|
186
181
|
valid_cop_names.each do |name|
|
187
182
|
validate_section_presence(name)
|
188
|
-
|
183
|
+
self[name].each_key do |param|
|
189
184
|
next if COMMON_PARAMS.include?(param) ||
|
190
185
|
ConfigLoader.default_configuration[name].key?(param)
|
191
186
|
|
192
187
|
fail ValidationError,
|
193
|
-
"unrecognized parameter #{name}:#{param} found "
|
194
|
-
"in #{loaded_path || self}"
|
188
|
+
"unrecognized parameter #{name}:#{param} found in #{loaded_path}"
|
195
189
|
end
|
196
190
|
end
|
197
191
|
end
|
data/lib/rubocop/cop/cop.rb
CHANGED
@@ -2,7 +2,6 @@
|
|
2
2
|
|
3
3
|
module RuboCop
|
4
4
|
module Cop
|
5
|
-
class CorrectionNotPossible < Exception; end
|
6
5
|
class AmbiguousCopName < Exception; end
|
7
6
|
|
8
7
|
# Store for all cops with helper functions
|
@@ -22,6 +21,28 @@ module RuboCop
|
|
22
21
|
def without_type(type)
|
23
22
|
CopStore.new(reject { |c| c.cop_type == type })
|
24
23
|
end
|
24
|
+
|
25
|
+
def qualified_cop_name(name, origin)
|
26
|
+
@cop_names ||= Set.new(map(&:cop_name))
|
27
|
+
basename = File.basename(name)
|
28
|
+
found_ns = types.map(&:capitalize).select do |ns|
|
29
|
+
@cop_names.include?("#{ns}/#{basename}")
|
30
|
+
end
|
31
|
+
|
32
|
+
case found_ns.size
|
33
|
+
when 0 then name # No namespace found. Deal with it later in caller.
|
34
|
+
when 1 then cop_name_with_namespace(name, origin, basename, found_ns[0])
|
35
|
+
else fail AmbiguousCopName, "`#{basename}` used in #{origin}"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def cop_name_with_namespace(name, origin, basename, found_ns)
|
40
|
+
if name != basename && found_ns != File.dirname(name).to_sym
|
41
|
+
warn "#{origin}: #{name} has the wrong namespace - should be " \
|
42
|
+
"#{found_ns}"
|
43
|
+
end
|
44
|
+
"#{found_ns}/#{basename}"
|
45
|
+
end
|
25
46
|
end
|
26
47
|
|
27
48
|
# A scaffold for concrete cops.
|
@@ -59,25 +80,7 @@ module RuboCop
|
|
59
80
|
end
|
60
81
|
|
61
82
|
def self.qualified_cop_name(name, origin)
|
62
|
-
@
|
63
|
-
basename = File.basename(name)
|
64
|
-
found_ns = @all.types.map(&:capitalize).select do |ns|
|
65
|
-
@cop_names.include?("#{ns}/#{basename}")
|
66
|
-
end
|
67
|
-
|
68
|
-
case found_ns.size
|
69
|
-
when 0 then name # No namespace found. Deal with it later in caller.
|
70
|
-
when 1 then cop_name_with_namespace(name, origin, basename, found_ns[0])
|
71
|
-
else fail AmbiguousCopName, "`#{basename}` used in #{origin}"
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
def self.cop_name_with_namespace(name, origin, basename, found_ns)
|
76
|
-
if name != basename && found_ns != File.dirname(name).to_sym
|
77
|
-
warn "#{origin}: #{name} has the wrong namespace - should be " \
|
78
|
-
"#{found_ns}"
|
79
|
-
end
|
80
|
-
"#{found_ns}/#{basename}"
|
83
|
+
@all.qualified_cop_name(name, origin)
|
81
84
|
end
|
82
85
|
|
83
86
|
def self.non_rails
|
@@ -135,6 +138,15 @@ module RuboCop
|
|
135
138
|
config['AllCops'] && config['AllCops']['DisplayStyleGuide'])
|
136
139
|
end
|
137
140
|
|
141
|
+
# Returns true if the cop name or the cop namespace matches any of the
|
142
|
+
# given names.
|
143
|
+
def self.match?(given_names)
|
144
|
+
return false unless given_names
|
145
|
+
|
146
|
+
given_names.include?(cop_name) ||
|
147
|
+
given_names.include?(cop_type.to_s.capitalize)
|
148
|
+
end
|
149
|
+
|
138
150
|
def message(_node = nil)
|
139
151
|
self.class::MSG
|
140
152
|
end
|
@@ -162,10 +174,10 @@ module RuboCop
|
|
162
174
|
return nil unless support_autocorrect?
|
163
175
|
return false unless autocorrect?
|
164
176
|
|
165
|
-
autocorrect(node)
|
177
|
+
correction = autocorrect(node)
|
178
|
+
return false unless correction
|
179
|
+
@corrections << correction
|
166
180
|
true
|
167
|
-
rescue CorrectionNotPossible
|
168
|
-
false
|
169
181
|
end
|
170
182
|
|
171
183
|
def config_to_allow_offenses
|
@@ -143,7 +143,7 @@ module RuboCop
|
|
143
143
|
ancestor_node = ancestor_on_same_line(node)
|
144
144
|
source = node.loc.expression.source_buffer
|
145
145
|
|
146
|
-
|
146
|
+
lambda do |corrector|
|
147
147
|
start_col = (ancestor_node || node).loc.expression.column
|
148
148
|
starting_position_of_block_end = node.loc.end.begin_pos
|
149
149
|
end_col = node.loc.end.column
|