rubocop 0.40.0 → 0.41.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 (103) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +7 -1014
  3. data/config/default.yml +61 -5
  4. data/config/disabled.yml +6 -0
  5. data/config/enabled.yml +63 -4
  6. data/lib/rubocop.rb +17 -1
  7. data/lib/rubocop/ast_node.rb +56 -42
  8. data/lib/rubocop/ast_node/traversal.rb +3 -3
  9. data/lib/rubocop/cli.rb +14 -9
  10. data/lib/rubocop/comment_config.rb +85 -32
  11. data/lib/rubocop/config.rb +29 -8
  12. data/lib/rubocop/config_loader.rb +1 -1
  13. data/lib/rubocop/cop/cop.rb +1 -1
  14. data/lib/rubocop/cop/corrector.rb +13 -0
  15. data/lib/rubocop/cop/lint/block_alignment.rb +25 -11
  16. data/lib/rubocop/cop/lint/format_parameter_mismatch.rb +5 -2
  17. data/lib/rubocop/cop/lint/inherit_exception.rb +69 -0
  18. data/lib/rubocop/cop/lint/percent_string_array.rb +60 -0
  19. data/lib/rubocop/cop/lint/percent_symbol_array.rb +57 -0
  20. data/lib/rubocop/cop/lint/shadowed_exception.rb +95 -0
  21. data/lib/rubocop/cop/lint/useless_access_modifier.rb +28 -13
  22. data/lib/rubocop/cop/mixin/autocorrect_alignment.rb +25 -19
  23. data/lib/rubocop/cop/mixin/end_keyword_alignment.rb +16 -8
  24. data/lib/rubocop/cop/mixin/if_node.rb +1 -2
  25. data/lib/rubocop/cop/mixin/integer_node.rb +13 -0
  26. data/lib/rubocop/cop/mixin/match_range.rb +26 -0
  27. data/lib/rubocop/cop/mixin/multiline_expression_indentation.rb +16 -7
  28. data/lib/rubocop/cop/mixin/multiline_literal_brace_layout.rb +18 -1
  29. data/lib/rubocop/cop/mixin/negative_conditional.rb +6 -4
  30. data/lib/rubocop/cop/mixin/percent_literal.rb +10 -0
  31. data/lib/rubocop/cop/mixin/space_after_punctuation.rb +24 -6
  32. data/lib/rubocop/cop/mixin/space_before_punctuation.rb +20 -7
  33. data/lib/rubocop/cop/mixin/string_literals_help.rb +2 -2
  34. data/lib/rubocop/cop/mixin/trailing_comma.rb +34 -20
  35. data/lib/rubocop/cop/performance/flat_map.rb +23 -10
  36. data/lib/rubocop/cop/performance/push_splat.rb +47 -0
  37. data/lib/rubocop/cop/performance/redundant_block_call.rb +24 -1
  38. data/lib/rubocop/cop/performance/redundant_merge.rb +3 -5
  39. data/lib/rubocop/cop/performance/sample.rb +15 -11
  40. data/lib/rubocop/cop/rails/exit.rb +62 -0
  41. data/lib/rubocop/cop/rails/output_safety.rb +45 -0
  42. data/lib/rubocop/cop/rails/pluralization_grammar.rb +12 -4
  43. data/lib/rubocop/cop/rails/request_referer.rb +40 -0
  44. data/lib/rubocop/cop/rails/uniq_before_pluck.rb +63 -28
  45. data/lib/rubocop/cop/rails/validation.rb +37 -23
  46. data/lib/rubocop/cop/style/alias.rb +10 -6
  47. data/lib/rubocop/cop/style/bare_percent_literals.rb +18 -7
  48. data/lib/rubocop/cop/style/block_delimiters.rb +15 -22
  49. data/lib/rubocop/cop/style/closing_parenthesis_indentation.rb +19 -8
  50. data/lib/rubocop/cop/style/comment_indentation.rb +13 -5
  51. data/lib/rubocop/cop/style/conditional_assignment.rb +111 -59
  52. data/lib/rubocop/cop/style/documentation.rb +7 -1
  53. data/lib/rubocop/cop/style/each_for_simple_loop.rb +43 -0
  54. data/lib/rubocop/cop/style/each_with_object.rb +25 -14
  55. data/lib/rubocop/cop/style/empty_else.rb +6 -10
  56. data/lib/rubocop/cop/style/extra_spacing.rb +20 -3
  57. data/lib/rubocop/cop/style/file_name.rb +16 -4
  58. data/lib/rubocop/cop/style/frozen_string_literal_comment.rb +1 -1
  59. data/lib/rubocop/cop/style/hash_syntax.rb +9 -2
  60. data/lib/rubocop/cop/style/if_unless_modifier.rb +20 -13
  61. data/lib/rubocop/cop/style/implicit_runtime_error.rb +32 -0
  62. data/lib/rubocop/cop/style/infinite_loop.rb +42 -5
  63. data/lib/rubocop/cop/style/lambda.rb +22 -0
  64. data/lib/rubocop/cop/style/method_def_parentheses.rb +12 -4
  65. data/lib/rubocop/cop/style/module_function.rb +28 -6
  66. data/lib/rubocop/cop/style/multiline_method_call_indentation.rb +49 -12
  67. data/lib/rubocop/cop/style/mutable_constant.rb +8 -1
  68. data/lib/rubocop/cop/style/nested_modifier.rb +1 -1
  69. data/lib/rubocop/cop/style/next.rb +43 -31
  70. data/lib/rubocop/cop/style/not.rb +33 -13
  71. data/lib/rubocop/cop/style/numeric_literal_prefix.rb +92 -0
  72. data/lib/rubocop/cop/style/numeric_literals.rb +1 -4
  73. data/lib/rubocop/cop/style/parallel_assignment.rb +26 -8
  74. data/lib/rubocop/cop/style/{deprecated_hash_methods.rb → preferred_hash_methods.rb} +8 -8
  75. data/lib/rubocop/cop/style/redundant_parentheses.rb +29 -19
  76. data/lib/rubocop/cop/style/redundant_self.rb +13 -6
  77. data/lib/rubocop/cop/style/space_after_not.rb +7 -5
  78. data/lib/rubocop/cop/style/space_around_keyword.rb +6 -0
  79. data/lib/rubocop/cop/style/space_around_operators.rb +5 -1
  80. data/lib/rubocop/cop/style/space_before_first_arg.rb +21 -9
  81. data/lib/rubocop/cop/style/space_inside_array_percent_literal.rb +53 -0
  82. data/lib/rubocop/cop/style/space_inside_block_braces.rb +2 -2
  83. data/lib/rubocop/cop/style/space_inside_hash_literal_braces.rb +26 -6
  84. data/lib/rubocop/cop/style/space_inside_percent_literal_delimiters.rb +64 -0
  85. data/lib/rubocop/cop/style/string_literals.rb +37 -8
  86. data/lib/rubocop/cop/style/symbol_array.rb +21 -12
  87. data/lib/rubocop/cop/style/symbol_proc.rb +26 -19
  88. data/lib/rubocop/cop/style/word_array.rb +1 -5
  89. data/lib/rubocop/cop/style/zero_length_predicate.rb +6 -6
  90. data/lib/rubocop/cop/team.rb +40 -27
  91. data/lib/rubocop/cop/util.rb +13 -42
  92. data/lib/rubocop/formatter/disabled_config_formatter.rb +37 -14
  93. data/lib/rubocop/formatter/html_formatter.rb +3 -7
  94. data/lib/rubocop/result_cache.rb +18 -4
  95. data/{spec/support → lib/rubocop/rspec}/cop_helper.rb +3 -0
  96. data/lib/rubocop/rspec/host_environment_simulation_helper.rb +33 -0
  97. data/lib/rubocop/rspec/shared_contexts.rb +75 -0
  98. data/lib/rubocop/rspec/shared_examples.rb +101 -0
  99. data/lib/rubocop/rspec/support.rb +9 -0
  100. data/lib/rubocop/runner.rb +2 -2
  101. data/lib/rubocop/string_interpreter.rb +58 -0
  102. data/lib/rubocop/version.rb +1 -1
  103. metadata +27 -7
@@ -25,6 +25,8 @@ AllCops:
25
25
  - '**/Berksfile'
26
26
  - '**/Cheffile'
27
27
  - '**/Vagabondfile'
28
+ - '**/Fastfile'
29
+ - '**/*Fastfile'
28
30
  Exclude:
29
31
  - 'vendor/**/*'
30
32
  # Default formatter will be used if no -f/--format option is given.
@@ -63,6 +65,14 @@ AllCops:
63
65
  # which is "/tmp" on Unix-like systems, but could be something else on other
64
66
  # systems.
65
67
  CacheRootDirectory: /tmp
68
+ # The default cache root directory is /tmp, which on most systems is
69
+ # writable by any system user. This means that it is possible for a
70
+ # malicious user to anticipate the location of Rubocop's cache directory,
71
+ # and create a symlink in its place that could cause Rubocop to overwrite
72
+ # unintended files, or read malicious input. If you are certain that your
73
+ # cache location is secure from this kind of attack, and wish to use a
74
+ # symlinked cache location, set this value to "true".
75
+ AllowSymlinksInCacheRootDirectory: false
66
76
  # What version of the Ruby interpreter is the inspected code intended to
67
77
  # run on? (If there is more than one, set this to the lowest version.)
68
78
  TargetRubyVersion: 2.0
@@ -165,6 +175,9 @@ Style/AlignParameters:
165
175
  SupportedStyles:
166
176
  - with_first_parameter
167
177
  - with_fixed_indentation
178
+ # By default, the indentation width from Style/IndentationWidth is used
179
+ # But it can be overridden by setting this parameter
180
+ IndentationWidth: ~
168
181
 
169
182
  Style/AndOr:
170
183
  # Whether `and` and `or` are banned only in conditionals (conditionals)
@@ -519,8 +532,10 @@ Style/HashSyntax:
519
532
  - ruby19
520
533
  - ruby19_no_mixed_keys
521
534
  - hash_rockets
522
- # Force hashes that have a symbol value to use hash rockets
535
+ # Force hashes that have a symbol value to use hash rockets
523
536
  UseHashRocketsWithSymbolValues: false
537
+ # Do not suggest { a?: 1 } over { :a? => 1 } in ruby19 style
538
+ PreferHashRocketsForNonAlnumEndingSymbols: false
524
539
 
525
540
  Style/IfUnlessModifier:
526
541
  MaxLineLength: 80
@@ -638,6 +653,12 @@ Style/MethodName:
638
653
  - snake_case
639
654
  - camelCase
640
655
 
656
+ Style/ModuleFunction:
657
+ EnforcedStyle: module_function
658
+ SupportedStyles:
659
+ - module_function
660
+ - extend_self
661
+
641
662
  Style/MultilineArrayBraceLayout:
642
663
  EnforcedStyle: symmetrical
643
664
  SupportedStyles:
@@ -691,6 +712,7 @@ Style/MultilineMethodCallIndentation:
691
712
  SupportedStyles:
692
713
  - aligned
693
714
  - indented
715
+ - indented_relative_to_receiver
694
716
  # By default, the indentation width from Style/IndentationWidth is used
695
717
  # But it can be overridden by setting this parameter
696
718
  IndentationWidth: ~
@@ -717,6 +739,12 @@ Style/MultilineOperationIndentation:
717
739
  Style/NumericLiterals:
718
740
  MinDigits: 5
719
741
 
742
+ Style/NumericLiteralPrefix:
743
+ EnforcedOctalStyle: zero_with_o
744
+ SupportedOctalStyles:
745
+ - zero_with_o
746
+ - zero_only
747
+
720
748
  Style/OptionHash:
721
749
  # A list of parameter names that will be flagged by this cop.
722
750
  SuspiciousParamNames:
@@ -898,6 +926,9 @@ Style/SpaceInsideHashLiteralBraces:
898
926
  SupportedStyles:
899
927
  - space
900
928
  - no_space
929
+ # 'compact' normally requires a space inside hash braces, with the exception
930
+ # that successive left braces or right braces are collapsed together
931
+ - compact
901
932
 
902
933
  Style/SpaceInsideStringInterpolation:
903
934
  EnforcedStyle: no_space
@@ -1101,19 +1132,23 @@ Lint/DefEndAlignment:
1101
1132
  - def
1102
1133
  AutoCorrect: false
1103
1134
 
1135
+ Lint/InheritException:
1136
+ # The default base class in favour of `Exception`.
1137
+ EnforcedStyle: runtime_error
1138
+ SupportedStyles:
1139
+ - runtime_error
1140
+ - standard_error
1141
+
1104
1142
  # Checks for unused block arguments
1105
1143
  Lint/UnusedBlockArgument:
1106
1144
  IgnoreEmptyBlocks: true
1145
+ AllowUnusedKeywordArguments: false
1107
1146
 
1108
1147
  # Checks for unused method arguments.
1109
1148
  Lint/UnusedMethodArgument:
1110
1149
  AllowUnusedKeywordArguments: false
1111
1150
  IgnoreEmptyMethods: true
1112
1151
 
1113
- # Checks for unused block arguments.
1114
- Lint/UnusedBlockArgument:
1115
- AllowUnusedKeywordArguments: false
1116
-
1117
1152
  ##################### Performance ############################
1118
1153
 
1119
1154
  Performance/RedundantMerge:
@@ -1141,6 +1176,14 @@ Rails/Date:
1141
1176
  - strict
1142
1177
  - flexible
1143
1178
 
1179
+ Rails/Exit:
1180
+ Include:
1181
+ - app/**/*.rb
1182
+ - config/**/*.rb
1183
+ - lib/**/*.rb
1184
+ Exclude:
1185
+ - lib/**/*.rake
1186
+
1144
1187
  Rails/FindBy:
1145
1188
  Include:
1146
1189
  - app/models/**/*.rb
@@ -1164,6 +1207,12 @@ Rails/ReadWriteAttribute:
1164
1207
  Include:
1165
1208
  - app/models/**/*.rb
1166
1209
 
1210
+ Rails/RequestReferer:
1211
+ EnforcedStyle: referer
1212
+ SupportedStyles:
1213
+ - referer
1214
+ - referrer
1215
+
1167
1216
  Rails/ScopeArgs:
1168
1217
  Include:
1169
1218
  - app/models/**/*.rb
@@ -1176,6 +1225,13 @@ Rails/TimeZone:
1176
1225
  - strict
1177
1226
  - flexible
1178
1227
 
1228
+ Rails/UniqBeforePluck:
1229
+ EnforcementMode: conservative
1230
+ SupportedModes:
1231
+ - conservative
1232
+ - aggressive
1233
+ AutoCorrect: false
1234
+
1179
1235
  Rails/Validation:
1180
1236
  Include:
1181
1237
  - app/models/**/*.rb
@@ -47,6 +47,12 @@ Style/FirstMethodParameterLineBreak:
47
47
  multi-line method parameter definition.
48
48
  Enabled: false
49
49
 
50
+ Style/ImplicitRuntimeError:
51
+ Description: >-
52
+ Use `raise` or `fail` with an explicit exception class and
53
+ message, rather than just a message.
54
+ Enabled: false
55
+
50
56
  Style/InlineComment:
51
57
  Description: 'Avoid inline comments.'
52
58
  Enabled: false
@@ -7,6 +7,7 @@ Style/AccessModifierIndentation:
7
7
 
8
8
  Style/AccessorMethodName:
9
9
  Description: Check the naming of accessor methods for get_/set_.
10
+ StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#accessor_mutator_method_names'
10
11
  Enabled: true
11
12
 
12
13
  Style/Alias:
@@ -170,8 +171,8 @@ Style/DefWithParentheses:
170
171
  StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#method-parens'
171
172
  Enabled: true
172
173
 
173
- Style/DeprecatedHashMethods:
174
- Description: 'Checks for use of deprecated Hash methods.'
174
+ Style/PreferredHashMethods:
175
+ Description: 'Checks use of `has_key?` and `has_value?` Hash methods.'
175
176
  StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#hash-key'
176
177
  Enabled: true
177
178
 
@@ -192,6 +193,12 @@ Style/DoubleNegation:
192
193
  StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-bang-bang'
193
194
  Enabled: true
194
195
 
196
+ Style/EachForSimpleLoop:
197
+ Description: >-
198
+ Use `Integer#times` for a simple loop which iterates a fixed
199
+ number of times.
200
+ Enabled: true
201
+
195
202
  Style/EachWithObject:
196
203
  Description: 'Prefer `each_with_object` over `inject` or `reduce`.'
197
204
  Enabled: true
@@ -535,6 +542,11 @@ Style/NumericLiterals:
535
542
  StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#underscores-in-numerics'
536
543
  Enabled: true
537
544
 
545
+ Style/NumericLiteralPrefix:
546
+ Description: 'Use smallcase prefixes for numeric literals.'
547
+ StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#numeric-literal-prefixes'
548
+ Enabled: true
549
+
538
550
  Style/OneLineConditional:
539
551
  Description: >-
540
552
  Favor the ternary operator(?:) over
@@ -748,6 +760,14 @@ Style/SpaceAroundOperators:
748
760
  StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#spaces-operators'
749
761
  Enabled: true
750
762
 
763
+ Style/SpaceInsideArrayPercentLiteral:
764
+ Description: 'No unnecessary additional spaces between elements in %i/%w literals.'
765
+ Enabled: true
766
+
767
+ Style/SpaceInsidePercentLiteralDelimiters:
768
+ Description: 'No unnecessary spaces inside delimiters of %i/%w/%x literals.'
769
+ Enabled: true
770
+
751
771
  Style/SpaceInsideBrackets:
752
772
  Description: 'No spaces after [ or before ].'
753
773
  StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-spaces-braces'
@@ -819,7 +839,7 @@ Style/TrailingBlankLines:
819
839
 
820
840
  Style/TrailingCommaInArguments:
821
841
  Description: 'Checks for trailing comma in argument lists.'
822
- StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-trailing-array-commas'
842
+ StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-trailing-params-comma'
823
843
  Enabled: true
824
844
 
825
845
  Style/TrailingCommaInLiteral:
@@ -1067,6 +1087,10 @@ Lint/IneffectiveAccessModifier:
1067
1087
  the visibility of a class method, which does not work.
1068
1088
  Enabled: true
1069
1089
 
1090
+ Lint/InheritException:
1091
+ Description: 'Avoid inheriting from the `Exception` class.'
1092
+ Enabled: true
1093
+
1070
1094
  Lint/InvalidCharacterLiteral:
1071
1095
  Description: >-
1072
1096
  Checks for invalid character literals with a non-escaped
@@ -1110,6 +1134,16 @@ Lint/ParenthesesAsGroupedExpression:
1110
1134
  StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#parens-no-spaces'
1111
1135
  Enabled: true
1112
1136
 
1137
+ Lint/PercentStringArray:
1138
+ Description: >-
1139
+ Checks for unwanted commas and quotes in %w/%W literals.
1140
+ Enabled: true
1141
+
1142
+ Lint/PercentSymbolArray:
1143
+ Description: >-
1144
+ Checks for unwanted commas and colons in %i/%I literals.
1145
+ Enabled: true
1146
+
1113
1147
  Lint/RandOne:
1114
1148
  Description: >-
1115
1149
  Checks for `rand(1)` calls. Such calls always return `0`
@@ -1127,6 +1161,12 @@ Lint/RescueException:
1127
1161
  StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-blind-rescues'
1128
1162
  Enabled: true
1129
1163
 
1164
+ Lint/ShadowedException:
1165
+ Description: >-
1166
+ Avoid rescuing a higher level exception
1167
+ before a lower level exception.
1168
+ Enabled: true
1169
+
1130
1170
  Lint/ShadowingOuterLocalVariable:
1131
1171
  Description: >-
1132
1172
  Do not use the same name as outer local variable
@@ -1270,6 +1310,10 @@ Performance/LstripRstrip:
1270
1310
  Description: 'Use `strip` instead of `lstrip.rstrip`.'
1271
1311
  Enabled: true
1272
1312
 
1313
+ Performance/PushSplat:
1314
+ Description: 'Use `concat` instead of `push(*)`.'
1315
+ Enabled: true
1316
+
1273
1317
  Performance/RangeInclude:
1274
1318
  Description: 'Use `Range#cover?` instead of `Range#include?`.'
1275
1319
  Reference: 'https://github.com/JuanitoFatas/fast-ruby#cover-vs-include-code'
@@ -1347,6 +1391,13 @@ Rails/Delegate:
1347
1391
  Description: 'Prefer delegate method for delegations.'
1348
1392
  Enabled: true
1349
1393
 
1394
+ Rails/Exit:
1395
+ Description: >-
1396
+ Favor `fail`, `break`, `return`, etc. over `exit` in
1397
+ application or library code outside of Rake files to avoid
1398
+ exits during unit testing or running in production.
1399
+ Enabled: true
1400
+
1350
1401
  Rails/FindBy:
1351
1402
  Description: 'Prefer find_by over where.first.'
1352
1403
  Enabled: true
@@ -1363,6 +1414,10 @@ Rails/Output:
1363
1414
  Description: 'Checks for calls to puts, print, etc.'
1364
1415
  Enabled: true
1365
1416
 
1417
+ Rails/OutputSafety:
1418
+ Description: 'The use of `html_safe` or `raw` may be a security risk.'
1419
+ Enabled: true
1420
+
1366
1421
  Rails/PluralizationGrammar:
1367
1422
  Description: 'Checks for incorrect grammar when using methods like `3.day.ago`.'
1368
1423
  Enabled: true
@@ -1373,6 +1428,10 @@ Rails/ReadWriteAttribute:
1373
1428
  write_attribute(:attr, val).
1374
1429
  Enabled: true
1375
1430
 
1431
+ Rails/RequestReferer:
1432
+ Description: 'Use consistent syntax for request.referer.'
1433
+ Enabled: true
1434
+
1376
1435
  Rails/ScopeArgs:
1377
1436
  Description: 'Checks the arguments of ActiveRecord scopes.'
1378
1437
  Enabled: true
@@ -1384,7 +1443,7 @@ Rails/TimeZone:
1384
1443
  Enabled: true
1385
1444
 
1386
1445
  Rails/UniqBeforePluck:
1387
- Description: 'Prefer the use of uniq before pluck.'
1446
+ Description: 'Prefer the use of uniq or distinct before pluck.'
1388
1447
  Enabled: true
1389
1448
 
1390
1449
  Rails/Validation:
@@ -19,6 +19,7 @@ require 'rubocop/path_util'
19
19
  require 'rubocop/string_util'
20
20
  require 'rubocop/name_similarity'
21
21
  require 'rubocop/node_pattern'
22
+ require 'rubocop/string_interpreter'
22
23
  require 'rubocop/ast_node/sexp'
23
24
  require 'rubocop/ast_node'
24
25
  require 'rubocop/ast_node/builder'
@@ -61,7 +62,9 @@ require 'rubocop/cop/mixin/first_element_line_break'
61
62
  require 'rubocop/cop/mixin/frozen_string_literal'
62
63
  require 'rubocop/cop/mixin/hash_node'
63
64
  require 'rubocop/cop/mixin/if_node'
65
+ require 'rubocop/cop/mixin/integer_node'
64
66
  require 'rubocop/cop/mixin/on_method_def'
67
+ require 'rubocop/cop/mixin/match_range'
65
68
  require 'rubocop/cop/mixin/method_complexity' # relies on on_method_def
66
69
  require 'rubocop/cop/mixin/method_preference'
67
70
  require 'rubocop/cop/mixin/min_body_length'
@@ -107,6 +110,7 @@ require 'rubocop/cop/lint/float_out_of_range'
107
110
  require 'rubocop/cop/lint/format_parameter_mismatch'
108
111
  require 'rubocop/cop/lint/handle_exceptions'
109
112
  require 'rubocop/cop/lint/implicit_string_concatenation'
113
+ require 'rubocop/cop/lint/inherit_exception'
110
114
  require 'rubocop/cop/lint/ineffective_access_modifier'
111
115
  require 'rubocop/cop/lint/invalid_character_literal'
112
116
  require 'rubocop/cop/lint/literal_in_condition'
@@ -116,9 +120,12 @@ require 'rubocop/cop/lint/nested_method_definition'
116
120
  require 'rubocop/cop/lint/next_without_accumulator'
117
121
  require 'rubocop/cop/lint/non_local_exit_from_iterator'
118
122
  require 'rubocop/cop/lint/parentheses_as_grouped_expression'
123
+ require 'rubocop/cop/lint/percent_string_array'
124
+ require 'rubocop/cop/lint/percent_symbol_array'
119
125
  require 'rubocop/cop/lint/rand_one'
120
126
  require 'rubocop/cop/lint/require_parentheses'
121
127
  require 'rubocop/cop/lint/rescue_exception'
128
+ require 'rubocop/cop/lint/shadowed_exception'
122
129
  require 'rubocop/cop/lint/shadowing_outer_local_variable'
123
130
  require 'rubocop/cop/lint/string_conversion_in_interpolation'
124
131
  require 'rubocop/cop/lint/syntax'
@@ -155,6 +162,7 @@ require 'rubocop/cop/performance/fixed_size'
155
162
  require 'rubocop/cop/performance/flat_map'
156
163
  require 'rubocop/cop/performance/hash_each'
157
164
  require 'rubocop/cop/performance/lstrip_rstrip'
165
+ require 'rubocop/cop/performance/push_splat'
158
166
  require 'rubocop/cop/performance/range_include'
159
167
  require 'rubocop/cop/performance/redundant_block_call'
160
168
  require 'rubocop/cop/performance/redundant_match'
@@ -203,10 +211,11 @@ require 'rubocop/cop/style/conditional_assignment'
203
211
  require 'rubocop/cop/style/constant_name'
204
212
  require 'rubocop/cop/style/copyright'
205
213
  require 'rubocop/cop/style/def_with_parentheses'
206
- require 'rubocop/cop/style/deprecated_hash_methods'
214
+ require 'rubocop/cop/style/preferred_hash_methods'
207
215
  require 'rubocop/cop/style/documentation'
208
216
  require 'rubocop/cop/style/dot_position'
209
217
  require 'rubocop/cop/style/double_negation'
218
+ require 'rubocop/cop/style/each_for_simple_loop'
210
219
  require 'rubocop/cop/style/each_with_object'
211
220
  require 'rubocop/cop/style/else_alignment'
212
221
  require 'rubocop/cop/style/empty_case_condition'
@@ -242,6 +251,7 @@ require 'rubocop/cop/style/if_inside_else'
242
251
  require 'rubocop/cop/style/if_unless_modifier'
243
252
  require 'rubocop/cop/style/if_unless_modifier_of_if_unless'
244
253
  require 'rubocop/cop/style/if_with_semicolon'
254
+ require 'rubocop/cop/style/implicit_runtime_error'
245
255
  require 'rubocop/cop/style/indent_array'
246
256
  require 'rubocop/cop/style/indent_assignment'
247
257
  require 'rubocop/cop/style/indent_hash'
@@ -282,6 +292,7 @@ require 'rubocop/cop/style/nil_comparison'
282
292
  require 'rubocop/cop/style/non_nil_check'
283
293
  require 'rubocop/cop/style/not'
284
294
  require 'rubocop/cop/style/numeric_literals'
295
+ require 'rubocop/cop/style/numeric_literal_prefix'
285
296
  require 'rubocop/cop/style/one_line_conditional'
286
297
  require 'rubocop/cop/style/op_method'
287
298
  require 'rubocop/cop/style/option_hash'
@@ -323,10 +334,12 @@ require 'rubocop/cop/style/space_before_comma'
323
334
  require 'rubocop/cop/style/space_before_comment'
324
335
  require 'rubocop/cop/style/space_before_first_arg'
325
336
  require 'rubocop/cop/style/space_before_semicolon'
337
+ require 'rubocop/cop/style/space_inside_array_percent_literal'
326
338
  require 'rubocop/cop/style/space_inside_block_braces'
327
339
  require 'rubocop/cop/style/space_inside_brackets'
328
340
  require 'rubocop/cop/style/space_inside_hash_literal_braces'
329
341
  require 'rubocop/cop/style/space_inside_parens'
342
+ require 'rubocop/cop/style/space_inside_percent_literal_delimiters'
330
343
  require 'rubocop/cop/style/space_inside_range_literal'
331
344
  require 'rubocop/cop/style/space_inside_string_interpolation'
332
345
  require 'rubocop/cop/style/special_global_vars'
@@ -360,12 +373,15 @@ require 'rubocop/cop/style/zero_length_predicate'
360
373
  require 'rubocop/cop/rails/action_filter'
361
374
  require 'rubocop/cop/rails/date'
362
375
  require 'rubocop/cop/rails/delegate'
376
+ require 'rubocop/cop/rails/exit'
363
377
  require 'rubocop/cop/rails/find_by'
364
378
  require 'rubocop/cop/rails/find_each'
365
379
  require 'rubocop/cop/rails/has_and_belongs_to_many'
380
+ require 'rubocop/cop/rails/output_safety'
366
381
  require 'rubocop/cop/rails/output'
367
382
  require 'rubocop/cop/rails/pluralization_grammar'
368
383
  require 'rubocop/cop/rails/read_write_attribute'
384
+ require 'rubocop/cop/rails/request_referer'
369
385
  require 'rubocop/cop/rails/scope_args'
370
386
  require 'rubocop/cop/rails/time_zone'
371
387
  require 'rubocop/cop/rails/uniq_before_pluck'
@@ -323,55 +323,17 @@ module RuboCop
323
323
  # returns nil if answer cannot be determined
324
324
  ancestors = each_ancestor(:class, :module, :sclass, :casgn, :block)
325
325
  result = ancestors.map do |ancestor|
326
- case ancestor.type
327
- when :class, :module, :casgn
328
- # TODO: if constant name has cbase (leading ::), then we don't need
329
- # to keep traversing up through nested classes/modules
330
- ancestor.defined_module_name
331
- when :sclass
332
- return parent_module_name_for_sclass(ancestor)
333
- else # block
334
- if ancestor.method_name == :class_eval
335
- # `class_eval` with no receiver applies to whatever module or class
336
- # we are currently in
337
- next unless (receiver = ancestor.receiver)
338
- return nil unless receiver.const_type?
339
- receiver.const_name
340
- elsif new_class_or_module_block?(ancestor)
341
- # we will catch this in the `casgn` branch above
342
- next
343
- else
344
- return nil
345
- end
346
- end
326
+ parent_module_name_part(ancestor) { |full_name| return full_name }
347
327
  end.compact.reverse.join('::')
348
328
  result.empty? ? 'Object' : result
349
329
  end
350
330
 
351
- def parent_module_name_for_sclass(sclass_node)
352
- # TODO: look for constant definition and see if it is nested
353
- # inside a class or module
354
- subject = sclass_node.children[0]
355
-
356
- if subject.const_type?
357
- "#<Class:#{subject.const_name}>"
358
- elsif subject.self_type?
359
- "#<Class:#{sclass_node.parent_module_name}>"
360
- end
361
- end
362
-
363
- def new_class_or_module_block?(block_node)
364
- receiver = block_node.receiver
331
+ ## Predicates
365
332
 
366
- block_node.method_name == :new &&
367
- receiver && receiver.const_type? &&
368
- (receiver.const_name == 'Class' || receiver.const_name == 'Module') &&
369
- block_node.parent &&
370
- block_node.parent.casgn_type?
333
+ def modifier_form?
334
+ loc.respond_to?(:end) && loc.end.nil?
371
335
  end
372
336
 
373
- ## Predicates
374
-
375
337
  def multiline?
376
338
  expr = loc.expression
377
339
  expr && (expr.first_line != expr.last_line)
@@ -456,6 +418,11 @@ module RuboCop
456
418
  args.empty? && method_name == :! && loc.selector.is?('not'.freeze)
457
419
  end
458
420
 
421
+ def keyword_bang?
422
+ _receiver, method_name, *args = *self
423
+ args.empty? && method_name == :! && loc.selector.is?('!'.freeze)
424
+ end
425
+
459
426
  def unary_operation?
460
427
  return false unless loc.respond_to?(:selector) && loc.selector
461
428
  Cop::Util.operator?(loc.selector.source.to_sym) &&
@@ -604,5 +571,52 @@ module RuboCop
604
571
  # (while <condition> <body>) -> always evaluates to `nil`
605
572
  sibling_index == 0
606
573
  end
574
+
575
+ def parent_module_name_part(node)
576
+ case node.type
577
+ when :class, :module, :casgn
578
+ # TODO: if constant name has cbase (leading ::), then we don't need
579
+ # to keep traversing up through nested classes/modules
580
+ node.defined_module_name
581
+ when :sclass
582
+ yield parent_module_name_for_sclass(node)
583
+ else # block
584
+ parent_module_name_for_block(node) { yield nil }
585
+ end
586
+ end
587
+
588
+ def parent_module_name_for_sclass(sclass_node)
589
+ # TODO: look for constant definition and see if it is nested
590
+ # inside a class or module
591
+ subject = sclass_node.children[0]
592
+
593
+ if subject.const_type?
594
+ "#<Class:#{subject.const_name}>"
595
+ elsif subject.self_type?
596
+ "#<Class:#{sclass_node.parent_module_name}>"
597
+ end
598
+ end
599
+
600
+ def parent_module_name_for_block(ancestor)
601
+ if ancestor.method_name == :class_eval
602
+ # `class_eval` with no receiver applies to whatever module or class
603
+ # we are currently in
604
+ return unless (receiver = ancestor.receiver)
605
+ yield unless receiver.const_type?
606
+ receiver.const_name
607
+ elsif !new_class_or_module_block?(ancestor)
608
+ yield
609
+ end
610
+ end
611
+
612
+ def new_class_or_module_block?(block_node)
613
+ receiver = block_node.receiver
614
+
615
+ block_node.method_name == :new &&
616
+ receiver && receiver.const_type? &&
617
+ (receiver.const_name == 'Class' || receiver.const_name == 'Module') &&
618
+ block_node.parent &&
619
+ block_node.parent.casgn_type?
620
+ end
607
621
  end
608
622
  end