rubocop 0.31.0 → 0.32.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 +50 -0
- data/README.md +13 -0
- data/config/disabled.yml +4 -0
- data/config/enabled.yml +34 -8
- data/lib/rubocop.rb +4 -1
- data/lib/rubocop/cop/cop.rb +18 -12
- data/lib/rubocop/cop/lint/debugger.rb +7 -1
- data/lib/rubocop/cop/lint/duplicate_methods.rb +1 -1
- data/lib/rubocop/cop/lint/literal_in_interpolation.rb +10 -0
- data/lib/rubocop/cop/lint/nested_method_definition.rb +31 -0
- data/lib/rubocop/cop/lint/non_local_exit_from_iterator.rb +9 -0
- data/lib/rubocop/cop/lint/unneeded_disable.rb +53 -0
- data/lib/rubocop/cop/metrics/class_length.rb +1 -1
- data/lib/rubocop/cop/metrics/module_length.rb +1 -1
- data/lib/rubocop/cop/metrics/parameter_lists.rb +1 -1
- data/lib/rubocop/cop/mixin/autocorrect_alignment.rb +1 -1
- data/lib/rubocop/cop/mixin/if_node.rb +10 -0
- data/lib/rubocop/cop/mixin/space_after_punctuation.rb +8 -1
- data/lib/rubocop/cop/mixin/space_before_punctuation.rb +8 -1
- data/lib/rubocop/cop/mixin/statement_modifier.rb +2 -5
- data/lib/rubocop/cop/mixin/string_help.rb +1 -1
- data/lib/rubocop/cop/offense.rb +16 -3
- data/lib/rubocop/cop/performance/count.rb +33 -30
- data/lib/rubocop/cop/performance/sample.rb +103 -59
- data/lib/rubocop/cop/performance/size.rb +2 -1
- data/lib/rubocop/cop/rails/time_zone.rb +14 -6
- data/lib/rubocop/cop/style/align_hash.rb +7 -3
- data/lib/rubocop/cop/style/braces_around_hash_parameters.rb +39 -11
- data/lib/rubocop/cop/style/case_indentation.rb +18 -4
- data/lib/rubocop/cop/style/comment_annotation.rb +22 -7
- data/lib/rubocop/cop/style/documentation.rb +11 -5
- data/lib/rubocop/cop/style/empty_else.rb +25 -0
- data/lib/rubocop/cop/style/if_unless_modifier.rb +1 -5
- data/lib/rubocop/cop/style/indentation_width.rb +1 -5
- data/lib/rubocop/cop/style/multiline_operation_indentation.rb +12 -10
- data/lib/rubocop/cop/style/next.rb +1 -1
- data/lib/rubocop/cop/style/parallel_assignment.rb +196 -0
- data/lib/rubocop/cop/style/single_line_methods.rb +1 -4
- data/lib/rubocop/cop/style/space_inside_string_interpolation.rb +41 -0
- data/lib/rubocop/cop/style/struct_inheritance.rb +11 -10
- data/lib/rubocop/cop/style/trailing_blank_lines.rb +8 -0
- data/lib/rubocop/cop/style/trailing_comma.rb +1 -1
- data/lib/rubocop/cop/team.rb +8 -1
- data/lib/rubocop/formatter/disabled_config_formatter.rb +2 -1
- data/lib/rubocop/formatter/formatter_set.rb +24 -1
- data/lib/rubocop/options.rb +4 -0
- data/lib/rubocop/processed_source.rb +4 -1
- data/lib/rubocop/runner.rb +12 -7
- data/lib/rubocop/target_finder.rb +3 -3
- data/lib/rubocop/version.rb +1 -1
- data/relnotes/v0.32.0.md +139 -0
- data/rubocop.gemspec +2 -2
- metadata +12 -8
- data/lib/rubocop/cop/performance/parallel_assignment.rb +0 -79
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2f00678bddd0c2dc00390310b217cec58ec200d5
|
4
|
+
data.tar.gz: b0b294dae0580562e4ff6225e8f7543777c927fc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 86a0015fe3ff0021b1968662f9212898245754d97bbb02e73dd6f33f338a09c445f749068d1686199a5ec334f61cb5fa584d3271dd9a026926c5efff97677b40
|
7
|
+
data.tar.gz: 31af47e5133c430f1f63f0ed44a8e45224a2c78314c00ba447c9a2048796b872f5504acde692fd4ef3ba1a3de5cb269dce1c8c67d1570013c12fbcdf0d8267df
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,47 @@
|
|
2
2
|
|
3
3
|
## master (unreleased)
|
4
4
|
|
5
|
+
## 0.32.0 (06/06/2015)
|
6
|
+
|
7
|
+
### New features
|
8
|
+
|
9
|
+
* Adjust behavior of `TrailingComma` cop to account for multi-line hashes nested within method calls. ([@panthomakos][])
|
10
|
+
* [#1719](https://github.com/bbatsov/rubocop/pull/1719): Display an error and abort the program if input file can't be found. ([@matugm][])
|
11
|
+
* New cop `SpaceInsideStringInterpolation` checks for spaces within string interpolations. ([@glasnt][])
|
12
|
+
* New cop `NestedMethodDefinition` checks for method definitions inside other methods. ([@ojab][])
|
13
|
+
* `LiteralInInterpolation` cop does auto-correction. ([@tmr08c][])
|
14
|
+
* [#1865](https://github.com/bbatsov/rubocop/issues/1865): New cop `Lint/UnneededDisable` checks for `rubocop:disable` comments that can be removed. ([@jonas054][])
|
15
|
+
* `EmptyElse` cop does auto-correction. ([@lumeet][])
|
16
|
+
* Show reference links when displaying style guide links. ([@rrosenblum][])
|
17
|
+
* `Debugger` cop now checks for the Capybara debug method `save_screenshot`. ([@crazydog115][])
|
18
|
+
* [#1282](https://github.com/bbatsov/rubocop/issues/1282): `CaseIndentation` cop does auto-correction. ([@lumeet][])
|
19
|
+
* [#1928](https://github.com/bbatsov/rubocop/issues/1928): Do auto-correction one offense at a time (rather than one cop at a time) if there are tabs in the code. ([@jonas054][])
|
20
|
+
|
21
|
+
### Changes
|
22
|
+
|
23
|
+
* Prefer `SpaceInsideBlockBraces` to `SpaceBeforeSemicolon` and `SpaceAfterSemicolon` to avoid an infinite loop when auto-correcting. ([@lumeet][])
|
24
|
+
* [#1873](https://github.com/bbatsov/rubocop/issues/1873): Move `ParallelAssignment` cop from Performance to Style. ([@rrosenblum][])
|
25
|
+
* Add `getlocal` to acceptable methods of `Rails/TimeZone`. ([@ojab][])
|
26
|
+
* [#1851](https://github.com/bbatsov/rubocop/issues/1851), [#1948](https://github.com/bbatsov/rubocop/issues/1948): Change offense message for `ClassLength` and `ModuleLength` to match that of `MethodLength`. ([@bquorning][])
|
27
|
+
|
28
|
+
### Bugs fixed
|
29
|
+
|
30
|
+
* Don't count required keyword args when specifying `CountKeywordArgs: false` for `ParameterLists`. ([@sumeet][])
|
31
|
+
* [#1879](https://github.com/bbatsov/rubocop/issues/1879): Avoid auto-correcting hash with trailing comma into invalid code in `BracesAroundHashParameters`. ([@jonas054][])
|
32
|
+
* [#1868](https://github.com/bbatsov/rubocop/issues/1868): Do not register an offense in `Performance/Count` when `select` is called with symbols or strings as the parameters. ([@rrosenblum][])
|
33
|
+
* `Sample` rewritten to properly handle shuffle randomness source, first/last params and non-literal ranges. ([@chastell][])
|
34
|
+
* [#1873](https://github.com/bbatsov/rubocop/issues/1873): Modify `ParallelAssignment` to properly autocorrect when the assignment is protected by a modifier statement. ([@rrosenblum][])
|
35
|
+
* Configure `ParallelAssignment` to work with non-standard `IndentationWidths`. ([@rrosenblum][])
|
36
|
+
* [#1899](https://github.com/bbatsov/rubocop/issues/1899): Be careful about comments when auto-correcting in `BracesAroundHashParameters`. ([@jonas054][])
|
37
|
+
* [#1897](https://github.com/bbatsov/rubocop/issues/1897): Don't report that semicolon separated statements can be converted to modifier form in `IfUnlessModifier` (and don't auto-correct them). ([@jonas054][])
|
38
|
+
* [#1644](https://github.com/bbatsov/rubocop/issues/1644): Don't search the entire file system when a folder is named `,` (fix for jruby and rbx). ([@rrosenblum][])
|
39
|
+
* [#1803](https://github.com/bbatsov/rubocop/issues/1803): Don't warn for `return` from `lambda` block in `NonLocalExitFromIterator`. ([@ypresto][])
|
40
|
+
* [#1905](https://github.com/bbatsov/rubocop/issues/1905): Ignore sparse and trailing comments in `Style/Documentation`. ([@RGBD][])
|
41
|
+
* [#1923](https://github.com/bbatsov/rubocop/issues/1923): Handle properly `for` without body in `Style/Next`. ([@bbatsov][])
|
42
|
+
* [#1901](https://github.com/bbatsov/rubocop/issues/1901): Do not auto correct comments that are missing a note. ([@rrosenblum][])
|
43
|
+
* [#1926](https://github.com/bbatsov/rubocop/issues/1926): Fix crash in `Style/AlignHash` when correcting a hash with a splat in it. ([@rrosenblum][])
|
44
|
+
* [#1935](https://github.com/bbatsov/rubocop/issues/1935): Allow `Symbol#to_proc` blocks in Performance/Size. ([@m1foley][])
|
45
|
+
|
5
46
|
## 0.31.0 (05/05/2015)
|
6
47
|
|
7
48
|
### New features
|
@@ -1393,3 +1434,12 @@
|
|
1393
1434
|
[@tmr08c]: https://github.com/tmr08c
|
1394
1435
|
[@hbd225]: https://github.com/hbd225
|
1395
1436
|
[@l8nite]: https://github.com/l8nite
|
1437
|
+
[@sumeet]: https://github.com/sumeet
|
1438
|
+
[@ojab]: https://github.com/ojab
|
1439
|
+
[@chastell]: https://github.com/chastell
|
1440
|
+
[@glasnt]: https://github.com/glasnt
|
1441
|
+
[@crazydog115]: https://github.com/crazydog115
|
1442
|
+
[@RGBD]: https://github.com/RGBD
|
1443
|
+
[@panthomakos]: https://github.com/panthomakos
|
1444
|
+
[@matugm]: https://github.com/matugm
|
1445
|
+
[@m1foley]: https://github.com/m1foley
|
data/README.md
CHANGED
@@ -70,6 +70,7 @@ specific RuboCop release.**
|
|
70
70
|
- [LightTable](#lighttable)
|
71
71
|
- [RubyMine](#rubymine)
|
72
72
|
- [Other Editors](#other-editors)
|
73
|
+
- [Git pre-commit hook integration](#git-pre-commit-hook-integration)
|
73
74
|
- [Guard integration](#guard-integration)
|
74
75
|
- [Rake integration](#rake-integration)
|
75
76
|
- [Extensions](#extensions)
|
@@ -738,6 +739,18 @@ provides basic RuboCop integration for RubyMine/IntelliJ IDEA.
|
|
738
739
|
Here's one great opportunity to contribute to RuboCop - implement
|
739
740
|
RuboCop integration for your favorite editor.
|
740
741
|
|
742
|
+
## Git pre-commit hook integration
|
743
|
+
|
744
|
+
[overcommit](https://github.com/brigade/overcommit) is a fully configurable and
|
745
|
+
extendable Git commit hook manager. To use RuboCop with overcommit, add the
|
746
|
+
following to your `.overcommit.yml` file:
|
747
|
+
|
748
|
+
```yaml
|
749
|
+
PreCommit:
|
750
|
+
RuboCop:
|
751
|
+
enabled: true
|
752
|
+
```
|
753
|
+
|
741
754
|
## Guard integration
|
742
755
|
|
743
756
|
If you're fond of [Guard](https://github.com/guard/guard) you might
|
data/config/disabled.yml
CHANGED
data/config/enabled.yml
CHANGED
@@ -120,7 +120,7 @@ Style/ClassCheck:
|
|
120
120
|
|
121
121
|
Style/ClassMethods:
|
122
122
|
Description: 'Use self when defining module/class methods.'
|
123
|
-
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#def-self-
|
123
|
+
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#def-self-class-methods'
|
124
124
|
Enabled: true
|
125
125
|
|
126
126
|
Style/ClassVars:
|
@@ -270,6 +270,7 @@ Style/FormatString:
|
|
270
270
|
Style/GlobalVars:
|
271
271
|
Description: 'Do not introduce global variables.'
|
272
272
|
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#instance-vars'
|
273
|
+
Reference: 'http://www.zenspider.com/Languages/Ruby/QuickRef.html'
|
273
274
|
Enabled: true
|
274
275
|
|
275
276
|
Style/GuardClause:
|
@@ -446,6 +447,16 @@ Style/OpMethod:
|
|
446
447
|
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#other-arg'
|
447
448
|
Enabled: true
|
448
449
|
|
450
|
+
Style/ParallelAssignment:
|
451
|
+
Description: >-
|
452
|
+
Check for simple usages of parallel assignment.
|
453
|
+
It will only warn when the number of variables
|
454
|
+
matches on both sides of the assignment.
|
455
|
+
This also provides performance benefits
|
456
|
+
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#parallel-assignment'
|
457
|
+
Reference: 'https://github.com/JuanitoFatas/fast-ruby#parallel-assignment-vs-sequential-assignment-code'
|
458
|
+
Enabled: true
|
459
|
+
|
449
460
|
Style/ParenthesesAroundCondition:
|
450
461
|
Description: >-
|
451
462
|
Don't use parentheses around the condition of an
|
@@ -644,6 +655,11 @@ Style/SpaceInsideRangeLiteral:
|
|
644
655
|
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-space-inside-range-literals'
|
645
656
|
Enabled: true
|
646
657
|
|
658
|
+
Style/SpaceInsideStringInterpolation:
|
659
|
+
Description: 'Checks for padding/surrounding spaces inside string interpolation.'
|
660
|
+
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#string-interpolation'
|
661
|
+
Enabled: true
|
662
|
+
|
647
663
|
Style/SpecialGlobalVars:
|
648
664
|
Description: 'Avoid Perl-style global variables.'
|
649
665
|
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-cryptic-perlisms'
|
@@ -760,6 +776,7 @@ Metrics/AbcSize:
|
|
760
776
|
Description: >-
|
761
777
|
A calculated magnitude based on number of assignments,
|
762
778
|
branches, and conditions.
|
779
|
+
Reference: 'http://c2.com/cgi/wiki?AbcMetric'
|
763
780
|
Enabled: true
|
764
781
|
|
765
782
|
Metrics/BlockNesting:
|
@@ -909,6 +926,11 @@ Lint/Loop:
|
|
909
926
|
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#loop-with-break'
|
910
927
|
Enabled: true
|
911
928
|
|
929
|
+
Lint/NestedMethodDefinition:
|
930
|
+
Description: 'Do not use nested method definitions.'
|
931
|
+
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-nested-methods'
|
932
|
+
Enabled: true
|
933
|
+
|
912
934
|
Lint/NonLocalExitFromIterator:
|
913
935
|
Description: 'Do not use return in iterator to cause non-local exit.'
|
914
936
|
Enabled: true
|
@@ -952,6 +974,10 @@ Lint/UnderscorePrefixedVariableName:
|
|
952
974
|
Description: 'Do not use prefix `_` for a variable that is used.'
|
953
975
|
Enabled: true
|
954
976
|
|
977
|
+
Lint/UnneededDisable:
|
978
|
+
Description: 'Checks for rubocop:disable comments that can be removed.'
|
979
|
+
Enabled: true
|
980
|
+
|
955
981
|
Lint/UnusedBlockArgument:
|
956
982
|
Description: 'Checks for unused block arguments.'
|
957
983
|
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#underscore-unused-vars'
|
@@ -1004,6 +1030,7 @@ Performance/Detect:
|
|
1004
1030
|
Description: >-
|
1005
1031
|
Use `detect` instead of `select.first`, `find_all.first`,
|
1006
1032
|
`select.last`, and `find_all.last`.
|
1033
|
+
Reference: 'https://github.com/JuanitoFatas/fast-ruby#enumerabledetect-vs-enumerableselectfirst-code'
|
1007
1034
|
Enabled: true
|
1008
1035
|
|
1009
1036
|
Performance/FlatMap:
|
@@ -1011,6 +1038,7 @@ Performance/FlatMap:
|
|
1011
1038
|
Use `Enumerable#flat_map`
|
1012
1039
|
instead of `Enumerable#map...Array#flatten(1)`
|
1013
1040
|
or `Enumberable#collect..Array#flatten(1)`
|
1041
|
+
Reference: 'https://github.com/JuanitoFatas/fast-ruby#enumerablemaparrayflatten-vs-enumerableflat_map-code'
|
1014
1042
|
Enabled: true
|
1015
1043
|
EnabledForFlattenWithoutParams: false
|
1016
1044
|
# If enabled, this cop will warn about usages of
|
@@ -1018,27 +1046,23 @@ Performance/FlatMap:
|
|
1018
1046
|
# This can be dangerous since `flat_map` will only flatten 1 level, and
|
1019
1047
|
# `flatten` without any parameters can flatten multiple levels.
|
1020
1048
|
|
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
|
-
|
1028
1049
|
Performance/ReverseEach:
|
1029
1050
|
Description: 'Use `reverse_each` instead of `reverse.each`.'
|
1051
|
+
Reference: 'https://github.com/JuanitoFatas/fast-ruby#enumerablereverseeach-vs-enumerablereverse_each-code'
|
1030
1052
|
Enabled: true
|
1031
1053
|
|
1032
1054
|
Performance/Sample:
|
1033
1055
|
Description: >-
|
1034
1056
|
Use `sample` instead of `shuffle.first`,
|
1035
1057
|
`shuffle.last`, and `shuffle[Fixnum]`.
|
1058
|
+
Reference: 'https://github.com/JuanitoFatas/fast-ruby#arrayshufflefirst-vs-arraysample-code'
|
1036
1059
|
Enabled: true
|
1037
1060
|
|
1038
1061
|
Performance/Size:
|
1039
1062
|
Description: >-
|
1040
1063
|
Use `size` instead of `count` for counting
|
1041
1064
|
the number of elements in `Array` and `Hash`.
|
1065
|
+
Reference: 'https://github.com/JuanitoFatas/fast-ruby#arraycount-vs-arraysize-code'
|
1042
1066
|
Enabled: true
|
1043
1067
|
|
1044
1068
|
##################### Rails ##################################
|
@@ -1089,6 +1113,8 @@ Rails/ScopeArgs:
|
|
1089
1113
|
|
1090
1114
|
Rails/TimeZone:
|
1091
1115
|
Description: 'Checks the correct usage of time zone aware methods.'
|
1116
|
+
StyleGuide: 'https://github.com/bbatsov/rails-style-guide#time'
|
1117
|
+
Reference: 'http://danilenko.org/2012/7/6/rails_timezones'
|
1092
1118
|
Enabled: true
|
1093
1119
|
|
1094
1120
|
Rails/Validation:
|
data/lib/rubocop.rb
CHANGED
@@ -90,6 +90,7 @@ require 'rubocop/cop/lint/invalid_character_literal'
|
|
90
90
|
require 'rubocop/cop/lint/literal_in_condition'
|
91
91
|
require 'rubocop/cop/lint/literal_in_interpolation'
|
92
92
|
require 'rubocop/cop/lint/loop'
|
93
|
+
require 'rubocop/cop/lint/nested_method_definition'
|
93
94
|
require 'rubocop/cop/lint/non_local_exit_from_iterator'
|
94
95
|
require 'rubocop/cop/lint/parentheses_as_grouped_expression'
|
95
96
|
require 'rubocop/cop/lint/require_parentheses'
|
@@ -99,6 +100,7 @@ require 'rubocop/cop/lint/space_before_first_arg'
|
|
99
100
|
require 'rubocop/cop/lint/string_conversion_in_interpolation'
|
100
101
|
require 'rubocop/cop/lint/syntax'
|
101
102
|
require 'rubocop/cop/lint/underscore_prefixed_variable_name'
|
103
|
+
require 'rubocop/cop/lint/unneeded_disable'
|
102
104
|
require 'rubocop/cop/lint/unreachable_code'
|
103
105
|
require 'rubocop/cop/lint/unused_block_argument'
|
104
106
|
require 'rubocop/cop/lint/unused_method_argument'
|
@@ -122,7 +124,6 @@ require 'rubocop/cop/metrics/perceived_complexity'
|
|
122
124
|
require 'rubocop/cop/performance/count'
|
123
125
|
require 'rubocop/cop/performance/detect'
|
124
126
|
require 'rubocop/cop/performance/flat_map'
|
125
|
-
require 'rubocop/cop/performance/parallel_assignment'
|
126
127
|
require 'rubocop/cop/performance/reverse_each'
|
127
128
|
require 'rubocop/cop/performance/sample'
|
128
129
|
require 'rubocop/cop/performance/size'
|
@@ -223,6 +224,7 @@ require 'rubocop/cop/style/not'
|
|
223
224
|
require 'rubocop/cop/style/numeric_literals'
|
224
225
|
require 'rubocop/cop/style/one_line_conditional'
|
225
226
|
require 'rubocop/cop/style/op_method'
|
227
|
+
require 'rubocop/cop/style/parallel_assignment'
|
226
228
|
require 'rubocop/cop/style/parentheses_around_condition'
|
227
229
|
require 'rubocop/cop/style/percent_literal_delimiters'
|
228
230
|
require 'rubocop/cop/style/percent_q_literals'
|
@@ -261,6 +263,7 @@ require 'rubocop/cop/style/space_inside_brackets'
|
|
261
263
|
require 'rubocop/cop/style/space_inside_hash_literal_braces'
|
262
264
|
require 'rubocop/cop/style/space_inside_parens'
|
263
265
|
require 'rubocop/cop/style/space_inside_range_literal'
|
266
|
+
require 'rubocop/cop/style/space_inside_string_interpolation'
|
264
267
|
require 'rubocop/cop/style/special_global_vars'
|
265
268
|
require 'rubocop/cop/style/string_literals'
|
266
269
|
require 'rubocop/cop/style/string_literals_in_interpolation'
|
data/lib/rubocop/cop/cop.rb
CHANGED
@@ -133,7 +133,7 @@ module RuboCop
|
|
133
133
|
end
|
134
134
|
|
135
135
|
def display_style_guide?
|
136
|
-
style_guide_url &&
|
136
|
+
(style_guide_url || reference_url) &&
|
137
137
|
(@options[:display_style_guide] ||
|
138
138
|
config['AllCops'] && config['AllCops']['DisplayStyleGuide'])
|
139
139
|
end
|
@@ -154,30 +154,28 @@ module RuboCop
|
|
154
154
|
def add_offense(node, loc, message = nil, severity = nil)
|
155
155
|
location = loc.is_a?(Symbol) ? node.loc.send(loc) : loc
|
156
156
|
|
157
|
-
return unless enabled_line?(location.line)
|
158
|
-
|
159
157
|
# Don't include the same location twice for one cop.
|
160
|
-
return if @offenses.
|
158
|
+
return if @offenses.any? { |o| o.location == location }
|
161
159
|
|
162
160
|
severity = custom_severity || severity || default_severity
|
163
161
|
|
164
162
|
message ||= message(node)
|
165
163
|
message = annotate_message(message)
|
166
164
|
|
167
|
-
|
165
|
+
status = enabled_line?(location.line) ? correct(node) : :disabled
|
168
166
|
|
169
|
-
@offenses << Offense.new(severity, location, message, name,
|
170
|
-
yield if block_given?
|
167
|
+
@offenses << Offense.new(severity, location, message, name, status)
|
168
|
+
yield if block_given? && status != :disabled
|
171
169
|
end
|
172
170
|
|
173
171
|
def correct(node)
|
174
|
-
return
|
175
|
-
return
|
172
|
+
return :unsupported unless support_autocorrect?
|
173
|
+
return :uncorrected unless autocorrect?
|
176
174
|
|
177
175
|
correction = autocorrect(node)
|
178
|
-
return
|
176
|
+
return :uncorrected unless correction
|
179
177
|
@corrections << correction
|
180
|
-
|
178
|
+
:corrected
|
181
179
|
end
|
182
180
|
|
183
181
|
def config_to_allow_offenses
|
@@ -205,11 +203,19 @@ module RuboCop
|
|
205
203
|
(url.nil? || url.empty?) ? nil : url
|
206
204
|
end
|
207
205
|
|
206
|
+
def reference_url
|
207
|
+
url = cop_config && cop_config['Reference']
|
208
|
+
(url.nil? || url.empty?) ? nil : url
|
209
|
+
end
|
210
|
+
|
208
211
|
private
|
209
212
|
|
210
213
|
def annotate_message(message)
|
211
214
|
message = "#{name}: #{message}" if display_cop_names?
|
212
|
-
|
215
|
+
if display_style_guide?
|
216
|
+
links = [style_guide_url, reference_url].compact.join(', ')
|
217
|
+
message = "#{message} (#{links})"
|
218
|
+
end
|
213
219
|
message
|
214
220
|
end
|
215
221
|
|
@@ -43,7 +43,12 @@ module RuboCop
|
|
43
43
|
# save_and_open_screenshot
|
44
44
|
#
|
45
45
|
# (send nil :save_and_open_screenshot)
|
46
|
-
|
46
|
+
CAPYBARA_SAVE_OPEN_SCREENSHOT = s(:send, nil, :save_and_open_screenshot)
|
47
|
+
|
48
|
+
# save_screenshot
|
49
|
+
#
|
50
|
+
# (send nil :save_screenshot)
|
51
|
+
CAPYBARA_SAVE_SCREENSHOT = s(:send, nil, :save_screenshot)
|
47
52
|
|
48
53
|
DEBUGGER_NODES = [
|
49
54
|
DEBUGGER_NODE,
|
@@ -52,6 +57,7 @@ module RuboCop
|
|
52
57
|
REMOTE_PRY_NODE,
|
53
58
|
PRY_REMOTE_NODE,
|
54
59
|
CAPYBARA_SAVE_PAGE,
|
60
|
+
CAPYBARA_SAVE_OPEN_SCREENSHOT,
|
55
61
|
CAPYBARA_SAVE_SCREENSHOT
|
56
62
|
]
|
57
63
|
|
@@ -25,6 +25,12 @@ module RuboCop
|
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
|
+
def autocorrect(node)
|
29
|
+
expr = node.parent.loc.expression
|
30
|
+
value = autocorrected_value(node)
|
31
|
+
->(corrector) { corrector.replace(expr, value) }
|
32
|
+
end
|
33
|
+
|
28
34
|
private
|
29
35
|
|
30
36
|
def special_keyword?(node)
|
@@ -32,6 +38,10 @@ module RuboCop
|
|
32
38
|
(node.type == :str && !node.loc.respond_to?(:begin)) ||
|
33
39
|
node.loc.expression.is?('__LINE__')
|
34
40
|
end
|
41
|
+
|
42
|
+
def autocorrected_value(node)
|
43
|
+
node.str_type? ? node.children.last : node.loc.expression.source
|
44
|
+
end
|
35
45
|
end
|
36
46
|
end
|
37
47
|
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module Lint
|
6
|
+
# This cop checks for nested method definitions.
|
7
|
+
#
|
8
|
+
# @example
|
9
|
+
# # `bar` definition actually produces methods in the same scope
|
10
|
+
# # as the outer `foo` method. Furthermore, the `bar` method
|
11
|
+
# # will be redefined every time the `foo` is invoked
|
12
|
+
# def foo
|
13
|
+
# def bar
|
14
|
+
# end
|
15
|
+
# end
|
16
|
+
#
|
17
|
+
class NestedMethodDefinition < Cop
|
18
|
+
include OnMethodDef
|
19
|
+
|
20
|
+
MSG = 'Method definitions must not be nested. ' \
|
21
|
+
'Use `lambda` instead.'
|
22
|
+
|
23
|
+
def on_method_def(node, _method_name, _args, _body)
|
24
|
+
node.each_descendant(:def) do |nested_def_node|
|
25
|
+
add_offense(nested_def_node, :expression)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -39,6 +39,10 @@ module RuboCop
|
|
39
39
|
return if return_value?(return_node)
|
40
40
|
return_node.each_ancestor(:block) do |block_node|
|
41
41
|
send_node, args_node, _body_node = *block_node
|
42
|
+
|
43
|
+
# `return` does not exit to outside of lambda block, this is safe.
|
44
|
+
break if lambda?(send_node)
|
45
|
+
|
42
46
|
next if args_node.children.empty?
|
43
47
|
if chained_send?(send_node)
|
44
48
|
add_offense(return_node, :keyword)
|
@@ -55,6 +59,11 @@ module RuboCop
|
|
55
59
|
receiver_node, _selector_node = *send_node
|
56
60
|
!receiver_node.nil?
|
57
61
|
end
|
62
|
+
|
63
|
+
def lambda?(send_node)
|
64
|
+
receiver_node, selector_node = *send_node
|
65
|
+
receiver_node.nil? && selector_node == :lambda
|
66
|
+
end
|
58
67
|
end
|
59
68
|
end
|
60
69
|
end
|