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.

Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +50 -0
  3. data/README.md +13 -0
  4. data/config/disabled.yml +4 -0
  5. data/config/enabled.yml +34 -8
  6. data/lib/rubocop.rb +4 -1
  7. data/lib/rubocop/cop/cop.rb +18 -12
  8. data/lib/rubocop/cop/lint/debugger.rb +7 -1
  9. data/lib/rubocop/cop/lint/duplicate_methods.rb +1 -1
  10. data/lib/rubocop/cop/lint/literal_in_interpolation.rb +10 -0
  11. data/lib/rubocop/cop/lint/nested_method_definition.rb +31 -0
  12. data/lib/rubocop/cop/lint/non_local_exit_from_iterator.rb +9 -0
  13. data/lib/rubocop/cop/lint/unneeded_disable.rb +53 -0
  14. data/lib/rubocop/cop/metrics/class_length.rb +1 -1
  15. data/lib/rubocop/cop/metrics/module_length.rb +1 -1
  16. data/lib/rubocop/cop/metrics/parameter_lists.rb +1 -1
  17. data/lib/rubocop/cop/mixin/autocorrect_alignment.rb +1 -1
  18. data/lib/rubocop/cop/mixin/if_node.rb +10 -0
  19. data/lib/rubocop/cop/mixin/space_after_punctuation.rb +8 -1
  20. data/lib/rubocop/cop/mixin/space_before_punctuation.rb +8 -1
  21. data/lib/rubocop/cop/mixin/statement_modifier.rb +2 -5
  22. data/lib/rubocop/cop/mixin/string_help.rb +1 -1
  23. data/lib/rubocop/cop/offense.rb +16 -3
  24. data/lib/rubocop/cop/performance/count.rb +33 -30
  25. data/lib/rubocop/cop/performance/sample.rb +103 -59
  26. data/lib/rubocop/cop/performance/size.rb +2 -1
  27. data/lib/rubocop/cop/rails/time_zone.rb +14 -6
  28. data/lib/rubocop/cop/style/align_hash.rb +7 -3
  29. data/lib/rubocop/cop/style/braces_around_hash_parameters.rb +39 -11
  30. data/lib/rubocop/cop/style/case_indentation.rb +18 -4
  31. data/lib/rubocop/cop/style/comment_annotation.rb +22 -7
  32. data/lib/rubocop/cop/style/documentation.rb +11 -5
  33. data/lib/rubocop/cop/style/empty_else.rb +25 -0
  34. data/lib/rubocop/cop/style/if_unless_modifier.rb +1 -5
  35. data/lib/rubocop/cop/style/indentation_width.rb +1 -5
  36. data/lib/rubocop/cop/style/multiline_operation_indentation.rb +12 -10
  37. data/lib/rubocop/cop/style/next.rb +1 -1
  38. data/lib/rubocop/cop/style/parallel_assignment.rb +196 -0
  39. data/lib/rubocop/cop/style/single_line_methods.rb +1 -4
  40. data/lib/rubocop/cop/style/space_inside_string_interpolation.rb +41 -0
  41. data/lib/rubocop/cop/style/struct_inheritance.rb +11 -10
  42. data/lib/rubocop/cop/style/trailing_blank_lines.rb +8 -0
  43. data/lib/rubocop/cop/style/trailing_comma.rb +1 -1
  44. data/lib/rubocop/cop/team.rb +8 -1
  45. data/lib/rubocop/formatter/disabled_config_formatter.rb +2 -1
  46. data/lib/rubocop/formatter/formatter_set.rb +24 -1
  47. data/lib/rubocop/options.rb +4 -0
  48. data/lib/rubocop/processed_source.rb +4 -1
  49. data/lib/rubocop/runner.rb +12 -7
  50. data/lib/rubocop/target_finder.rb +3 -3
  51. data/lib/rubocop/version.rb +1 -1
  52. data/relnotes/v0.32.0.md +139 -0
  53. data/rubocop.gemspec +2 -2
  54. metadata +12 -8
  55. 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: c41bd779d02cd33eca9911b0c15c002ec42715b7
4
- data.tar.gz: b8cacc39e2c68e7122bf50b78c163fd7b3df3e73
3
+ metadata.gz: 2f00678bddd0c2dc00390310b217cec58ec200d5
4
+ data.tar.gz: b0b294dae0580562e4ff6225e8f7543777c927fc
5
5
  SHA512:
6
- metadata.gz: 8e5e0fd412cc13b16887e3043a2e00d55cf7f65b10bd73fc00729d0ec48c13e9e6a7867616b2ba3b509f43e9a010a2db295fd5ffd944b1755189aeb695690063
7
- data.tar.gz: 583b7509b1ac9536f4d78533a92376501b007275796c87bd7623575a99377610141406613f1ce8c809bbc71a146908ed82e61a9b77765bd2b4e4c387f8168c33
6
+ metadata.gz: 86a0015fe3ff0021b1968662f9212898245754d97bbb02e73dd6f33f338a09c445f749068d1686199a5ec334f61cb5fa584d3271dd9a026926c5efff97677b40
7
+ data.tar.gz: 31af47e5133c430f1f63f0ed44a8e45224a2c78314c00ba447c9a2048796b872f5504acde692fd4ef3ba1a3de5cb269dce1c8c67d1570013c12fbcdf0d8267df
@@ -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
@@ -52,3 +52,7 @@ Style/SymbolArray:
52
52
  Style/ExtraSpacing:
53
53
  Description: 'Do not use unnecessary spacing.'
54
54
  Enabled: false
55
+
56
+ Lint/LiteralInInterpolation:
57
+ Description: 'Avoid interpolating literals in strings'
58
+ AutoCorrect: false
@@ -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-singletons'
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:
@@ -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'
@@ -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.find { |o| o.location == location }
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
- corrected = correct(node)
165
+ status = enabled_line?(location.line) ? correct(node) : :disabled
168
166
 
169
- @offenses << Offense.new(severity, location, message, name, corrected)
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 nil unless support_autocorrect?
175
- return false unless autocorrect?
172
+ return :unsupported unless support_autocorrect?
173
+ return :uncorrected unless autocorrect?
176
174
 
177
175
  correction = autocorrect(node)
178
- return false unless correction
176
+ return :uncorrected unless correction
179
177
  @corrections << correction
180
- true
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
- message = "#{message} (#{style_guide_url})" if display_style_guide?
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
- CAPYBARA_SAVE_SCREENSHOT = s(:send, nil, :save_and_open_screenshot)
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
 
@@ -76,7 +76,7 @@ module RuboCop
76
76
  method, _args, _body = *node
77
77
  elsif node.defs_type?
78
78
  _receiver, method = *node
79
- method = "self.#{ method }"
79
+ method = "self.#{method}"
80
80
  end
81
81
 
82
82
  method ? [method, node] : nil
@@ -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