rubocop-standard 1.12.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +20 -0
- data/README.md +24 -0
- data/STYLEGUIDE.md +763 -0
- data/config/default.yml +326 -0
- data/config/rails.yml +118 -0
- data/guides/rails-controller-render-shorthand.md +9 -0
- data/guides/rails-render-inline.md +27 -0
- data/guides/rails-render-literal.md +8 -0
- data/lib/rubocop/cop/standard/rails_application_record.rb +29 -0
- data/lib/rubocop/cop/standard/rails_controller_render_action_symbol.rb +43 -0
- data/lib/rubocop/cop/standard/rails_controller_render_literal.rb +94 -0
- data/lib/rubocop/cop/standard/rails_controller_render_paths_exist.rb +69 -0
- data/lib/rubocop/cop/standard/rails_controller_render_shorthand.rb +51 -0
- data/lib/rubocop/cop/standard/rails_render_inline.rb +29 -0
- data/lib/rubocop/cop/standard/rails_render_object_collection.rb +47 -0
- data/lib/rubocop/cop/standard/rails_view_render_literal.rb +65 -0
- data/lib/rubocop/cop/standard/rails_view_render_paths_exist.rb +59 -0
- data/lib/rubocop/cop/standard/rails_view_render_shorthand.rb +38 -0
- data/lib/rubocop/cop/standard.rb +12 -0
- metadata +119 -0
data/config/default.yml
ADDED
@@ -0,0 +1,326 @@
|
|
1
|
+
require: rubocop/cop/standard
|
2
|
+
|
3
|
+
AllCops:
|
4
|
+
DisabledByDefault: true
|
5
|
+
|
6
|
+
Bundler/DuplicatedGem:
|
7
|
+
Enabled: true
|
8
|
+
|
9
|
+
Bundler/OrderedGems:
|
10
|
+
Enabled: true
|
11
|
+
|
12
|
+
Layout/BlockAlignment:
|
13
|
+
Enabled: true
|
14
|
+
|
15
|
+
Layout/BlockEndNewline:
|
16
|
+
Enabled: true
|
17
|
+
|
18
|
+
Layout/ConditionPosition:
|
19
|
+
Enabled: true
|
20
|
+
|
21
|
+
Layout/DefEndAlignment:
|
22
|
+
Enabled: true
|
23
|
+
|
24
|
+
Layout/EndAlignment:
|
25
|
+
Enabled: false
|
26
|
+
|
27
|
+
Layout/EndOfLine:
|
28
|
+
Enabled: true
|
29
|
+
|
30
|
+
Layout/InitialIndentation:
|
31
|
+
Enabled: true
|
32
|
+
|
33
|
+
Layout/SpaceAfterColon:
|
34
|
+
Enabled: true
|
35
|
+
|
36
|
+
Layout/SpaceAfterComma:
|
37
|
+
Enabled: true
|
38
|
+
|
39
|
+
Layout/SpaceAfterMethodName:
|
40
|
+
Enabled: true
|
41
|
+
|
42
|
+
Layout/SpaceAfterNot:
|
43
|
+
Enabled: true
|
44
|
+
|
45
|
+
Layout/SpaceAfterSemicolon:
|
46
|
+
Enabled: true
|
47
|
+
|
48
|
+
Layout/SpaceAroundBlockParameters:
|
49
|
+
Enabled: true
|
50
|
+
|
51
|
+
Layout/SpaceAroundEqualsInParameterDefault:
|
52
|
+
Enabled: true
|
53
|
+
|
54
|
+
Layout/SpaceBeforeBlockBraces:
|
55
|
+
Enabled: true
|
56
|
+
|
57
|
+
Layout/SpaceInsideArrayLiteralBrackets:
|
58
|
+
Enabled: true
|
59
|
+
EnforcedStyle: no_space
|
60
|
+
|
61
|
+
Layout/SpaceInsideArrayPercentLiteral:
|
62
|
+
Enabled: true
|
63
|
+
|
64
|
+
Layout/SpaceInsideBlockBraces:
|
65
|
+
Enabled: true
|
66
|
+
|
67
|
+
Layout/SpaceInsideParens:
|
68
|
+
Enabled: true
|
69
|
+
|
70
|
+
Layout/SpaceInsideRangeLiteral:
|
71
|
+
Enabled: true
|
72
|
+
|
73
|
+
Layout/SpaceInsideReferenceBrackets:
|
74
|
+
Enabled: true
|
75
|
+
|
76
|
+
Layout/Tab:
|
77
|
+
Enabled: true
|
78
|
+
|
79
|
+
Layout/TrailingBlankLines:
|
80
|
+
Enabled: true
|
81
|
+
|
82
|
+
Layout/TrailingWhitespace:
|
83
|
+
Enabled: true
|
84
|
+
|
85
|
+
Lint/CircularArgumentReference:
|
86
|
+
Enabled: true
|
87
|
+
|
88
|
+
Lint/Debugger:
|
89
|
+
Enabled: true
|
90
|
+
|
91
|
+
Lint/DeprecatedClassMethods:
|
92
|
+
Enabled: true
|
93
|
+
|
94
|
+
Lint/DuplicateMethods:
|
95
|
+
Enabled: true
|
96
|
+
|
97
|
+
Lint/DuplicatedKey:
|
98
|
+
Enabled: true
|
99
|
+
|
100
|
+
Lint/EachWithObjectArgument:
|
101
|
+
Enabled: true
|
102
|
+
|
103
|
+
Lint/ElseLayout:
|
104
|
+
Enabled: true
|
105
|
+
|
106
|
+
Lint/EmptyEnsure:
|
107
|
+
Enabled: true
|
108
|
+
|
109
|
+
Lint/EmptyInterpolation:
|
110
|
+
Enabled: true
|
111
|
+
|
112
|
+
Lint/EndInMethod:
|
113
|
+
Enabled: true
|
114
|
+
|
115
|
+
Lint/EnsureReturn:
|
116
|
+
Enabled: true
|
117
|
+
|
118
|
+
Lint/FlipFlop:
|
119
|
+
Enabled: true
|
120
|
+
|
121
|
+
Lint/FloatOutOfRange:
|
122
|
+
Enabled: true
|
123
|
+
|
124
|
+
Lint/FormatParameterMismatch:
|
125
|
+
Enabled: true
|
126
|
+
|
127
|
+
Lint/LiteralAsCondition:
|
128
|
+
Enabled: true
|
129
|
+
|
130
|
+
Lint/LiteralInInterpolation:
|
131
|
+
Enabled: true
|
132
|
+
|
133
|
+
Lint/Loop:
|
134
|
+
Enabled: true
|
135
|
+
|
136
|
+
Lint/NextWithoutAccumulator:
|
137
|
+
Enabled: true
|
138
|
+
|
139
|
+
Lint/RandOne:
|
140
|
+
Enabled: true
|
141
|
+
|
142
|
+
Lint/RequireParentheses:
|
143
|
+
Enabled: true
|
144
|
+
|
145
|
+
Lint/RescueException:
|
146
|
+
Enabled: true
|
147
|
+
|
148
|
+
Lint/StringConversionInInterpolation:
|
149
|
+
Enabled: true
|
150
|
+
|
151
|
+
Lint/UnderscorePrefixedVariableName:
|
152
|
+
Enabled: true
|
153
|
+
|
154
|
+
Lint/UnneededCopDisableDirective:
|
155
|
+
Enabled: true
|
156
|
+
|
157
|
+
Lint/UnneededSplatExpansion:
|
158
|
+
Enabled: true
|
159
|
+
|
160
|
+
Lint/UnreachableCode:
|
161
|
+
Enabled: true
|
162
|
+
|
163
|
+
Lint/UselessComparison:
|
164
|
+
Enabled: true
|
165
|
+
|
166
|
+
Lint/UselessSetterCall:
|
167
|
+
Enabled: true
|
168
|
+
|
169
|
+
Lint/Void:
|
170
|
+
Enabled: true
|
171
|
+
|
172
|
+
Metrics/AbcSize:
|
173
|
+
Enabled: false
|
174
|
+
|
175
|
+
Metrics/BlockLength:
|
176
|
+
Enabled: false
|
177
|
+
|
178
|
+
Metrics/BlockNesting:
|
179
|
+
Enabled: false
|
180
|
+
|
181
|
+
Metrics/ClassLength:
|
182
|
+
Enabled: false
|
183
|
+
|
184
|
+
Metrics/CyclomaticComplexity:
|
185
|
+
Enabled: false
|
186
|
+
|
187
|
+
Metrics/LineLength:
|
188
|
+
Enabled: false
|
189
|
+
|
190
|
+
Metrics/MethodLength:
|
191
|
+
Enabled: false
|
192
|
+
|
193
|
+
Metrics/ModuleLength:
|
194
|
+
Enabled: false
|
195
|
+
|
196
|
+
Metrics/ParameterLists:
|
197
|
+
Enabled: false
|
198
|
+
|
199
|
+
Metrics/PerceivedComplexity:
|
200
|
+
Enabled: false
|
201
|
+
|
202
|
+
Naming/AsciiIdentifiers:
|
203
|
+
Enabled: true
|
204
|
+
|
205
|
+
Naming/ClassAndModuleCamelCase:
|
206
|
+
Enabled: true
|
207
|
+
|
208
|
+
Naming/FileName:
|
209
|
+
Enabled: true
|
210
|
+
|
211
|
+
Naming/MethodName:
|
212
|
+
Enabled: true
|
213
|
+
|
214
|
+
Performance/CaseWhenSplat:
|
215
|
+
Enabled: false
|
216
|
+
|
217
|
+
Performance/Count:
|
218
|
+
Enabled: true
|
219
|
+
|
220
|
+
Performance/Detect:
|
221
|
+
Enabled: true
|
222
|
+
|
223
|
+
Performance/DoubleStartEndWith:
|
224
|
+
Enabled: true
|
225
|
+
|
226
|
+
Performance/EndWith:
|
227
|
+
Enabled: true
|
228
|
+
|
229
|
+
Performance/FlatMap:
|
230
|
+
Enabled: true
|
231
|
+
|
232
|
+
Performance/LstripRstrip:
|
233
|
+
Enabled: true
|
234
|
+
|
235
|
+
Performance/RangeInclude:
|
236
|
+
Enabled: false
|
237
|
+
|
238
|
+
Performance/RedundantMatch:
|
239
|
+
Enabled: false
|
240
|
+
|
241
|
+
Performance/RedundantMerge:
|
242
|
+
Enabled: true
|
243
|
+
MaxKeyValuePairs: 1
|
244
|
+
|
245
|
+
Performance/RedundantSortBy:
|
246
|
+
Enabled: true
|
247
|
+
|
248
|
+
Performance/ReverseEach:
|
249
|
+
Enabled: true
|
250
|
+
|
251
|
+
Performance/Sample:
|
252
|
+
Enabled: true
|
253
|
+
|
254
|
+
Performance/Size:
|
255
|
+
Enabled: true
|
256
|
+
|
257
|
+
Performance/StartWith:
|
258
|
+
Enabled: true
|
259
|
+
|
260
|
+
Security/Eval:
|
261
|
+
Enabled: true
|
262
|
+
|
263
|
+
Style/ArrayJoin:
|
264
|
+
Enabled: true
|
265
|
+
|
266
|
+
Style/BeginBlock:
|
267
|
+
Enabled: true
|
268
|
+
|
269
|
+
Style/BlockComments:
|
270
|
+
Enabled: true
|
271
|
+
|
272
|
+
Style/CaseEquality:
|
273
|
+
Enabled: true
|
274
|
+
|
275
|
+
Style/CharacterLiteral:
|
276
|
+
Enabled: true
|
277
|
+
|
278
|
+
Style/ClassMethods:
|
279
|
+
Enabled: true
|
280
|
+
|
281
|
+
Style/Copyright:
|
282
|
+
Enabled: false
|
283
|
+
|
284
|
+
Style/DefWithParentheses:
|
285
|
+
Enabled: true
|
286
|
+
|
287
|
+
Style/EndBlock:
|
288
|
+
Enabled: true
|
289
|
+
|
290
|
+
Style/For:
|
291
|
+
Enabled: true
|
292
|
+
|
293
|
+
Style/FrozenStringLiteralComment:
|
294
|
+
Enabled: true
|
295
|
+
|
296
|
+
Style/HashSyntax:
|
297
|
+
Enabled: true
|
298
|
+
EnforcedStyle: ruby19_no_mixed_keys
|
299
|
+
|
300
|
+
Style/LambdaCall:
|
301
|
+
Enabled: true
|
302
|
+
|
303
|
+
Style/MethodCallWithoutArgsParentheses:
|
304
|
+
Enabled: true
|
305
|
+
|
306
|
+
Style/MethodDefParentheses:
|
307
|
+
Enabled: true
|
308
|
+
|
309
|
+
Style/MultilineIfThen:
|
310
|
+
Enabled: true
|
311
|
+
|
312
|
+
Style/NilComparison:
|
313
|
+
Enabled: true
|
314
|
+
|
315
|
+
Style/Not:
|
316
|
+
Enabled: true
|
317
|
+
|
318
|
+
Style/OneLineConditional:
|
319
|
+
Enabled: true
|
320
|
+
|
321
|
+
Style/StabbyLambdaParentheses:
|
322
|
+
Enabled: true
|
323
|
+
|
324
|
+
Style/StringLiterals:
|
325
|
+
Enabled: true
|
326
|
+
EnforcedStyle: double_quotes
|
data/config/rails.yml
ADDED
@@ -0,0 +1,118 @@
|
|
1
|
+
Rails:
|
2
|
+
Enabled: true
|
3
|
+
|
4
|
+
Rails/FindEach:
|
5
|
+
Enabled: false
|
6
|
+
|
7
|
+
Rails/OutputSafety:
|
8
|
+
Enabled: true
|
9
|
+
|
10
|
+
Rails/PluralizationGrammar:
|
11
|
+
Enabled: true
|
12
|
+
|
13
|
+
Rails/RequestReferer:
|
14
|
+
Enabled: true
|
15
|
+
EnforcedStyle: referrer
|
16
|
+
|
17
|
+
Rails/ScopeArgs:
|
18
|
+
Enabled: true
|
19
|
+
|
20
|
+
Rails/UniqBeforePluck:
|
21
|
+
Enabled: true
|
22
|
+
|
23
|
+
Standard/RailsApplicationRecord:
|
24
|
+
Enabled: true
|
25
|
+
|
26
|
+
Standard/RailsControllerRenderActionSymbol:
|
27
|
+
Enabled: true
|
28
|
+
Include:
|
29
|
+
- 'app/controllers/**/*.rb'
|
30
|
+
|
31
|
+
Standard/RailsControllerRenderLiteral:
|
32
|
+
Enabled: true
|
33
|
+
StyleGuide: https://github.com/gjtorikian/rubocop-standard/blob/master/guides/rails-render-literal.md
|
34
|
+
Include:
|
35
|
+
- 'app/controllers/**/*.rb'
|
36
|
+
|
37
|
+
Standard/RailsControllerRenderPathsExist:
|
38
|
+
Enabled: true
|
39
|
+
ViewPath:
|
40
|
+
- 'app/views'
|
41
|
+
Include:
|
42
|
+
- 'app/controllers/**/*.rb'
|
43
|
+
|
44
|
+
Standard/RailsControllerRenderShorthand:
|
45
|
+
Enabled: true
|
46
|
+
StyleGuide: https://github.com/gjtorikian/rubocop-standard/blob/master/guides/rails-controller-render-shorthand.md
|
47
|
+
Include:
|
48
|
+
- 'app/controllers/**/*.rb'
|
49
|
+
|
50
|
+
Standard/RailsRenderInline:
|
51
|
+
Enabled: true
|
52
|
+
StyleGuide: https://github.com/gjtorikian/rubocop-standard/blob/master/guides/rails-controller-render-inline.md
|
53
|
+
Include:
|
54
|
+
- 'app/controllers/**/*.rb'
|
55
|
+
- 'app/helpers/**/*.rb'
|
56
|
+
- 'app/view_models/**/*.rb'
|
57
|
+
- 'app/views/**/*.erb'
|
58
|
+
|
59
|
+
Standard/RailsRenderObjectCollection:
|
60
|
+
Enabled: false
|
61
|
+
|
62
|
+
Standard/RailsViewRenderLiteral:
|
63
|
+
Enabled: true
|
64
|
+
StyleGuide: https://github.com/gjtorikian/rubocop-standard/blob/master/guides/rails-render-literal.md
|
65
|
+
Include:
|
66
|
+
- 'app/helpers/**/*.rb'
|
67
|
+
- 'app/view_models/**/*.rb'
|
68
|
+
- 'app/views/**/*.erb'
|
69
|
+
|
70
|
+
Standard/RailsViewRenderPathsExist:
|
71
|
+
Enabled: true
|
72
|
+
ViewPath:
|
73
|
+
- 'app/views'
|
74
|
+
Include:
|
75
|
+
- 'app/helpers/**/*.rb'
|
76
|
+
- 'app/view_models/**/*.rb'
|
77
|
+
- 'app/views/**/*.erb'
|
78
|
+
|
79
|
+
Standard/RailsViewRenderShorthand:
|
80
|
+
Enabled: true
|
81
|
+
Include:
|
82
|
+
- 'app/helpers/**/*.rb'
|
83
|
+
- 'app/view_models/**/*.rb'
|
84
|
+
- 'app/views/**/*.erb'
|
85
|
+
|
86
|
+
# Exclude Rails ERB files from incompatible cops
|
87
|
+
|
88
|
+
Layout/BlockAlignment:
|
89
|
+
Exclude:
|
90
|
+
- 'app/views/**/*.erb'
|
91
|
+
|
92
|
+
Style/For:
|
93
|
+
Exclude:
|
94
|
+
- 'app/views/**/*.erb'
|
95
|
+
|
96
|
+
Style/OneLineConditional:
|
97
|
+
Exclude:
|
98
|
+
- 'app/views/**/*.erb'
|
99
|
+
|
100
|
+
Style/Semicolon:
|
101
|
+
Exclude:
|
102
|
+
- 'app/views/**/*.erb'
|
103
|
+
|
104
|
+
Layout/SpaceInsideParens:
|
105
|
+
Exclude:
|
106
|
+
- 'app/views/**/*.erb'
|
107
|
+
|
108
|
+
Style/StringLiterals:
|
109
|
+
Exclude:
|
110
|
+
- 'app/views/**/*.erb'
|
111
|
+
|
112
|
+
Layout/TrailingBlankLines:
|
113
|
+
Exclude:
|
114
|
+
- 'app/views/**/*.erb'
|
115
|
+
|
116
|
+
Layout/TrailingWhitespace:
|
117
|
+
Exclude:
|
118
|
+
- 'app/views/**/*.erb'
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# Standard/RailsRenderInline
|
2
|
+
|
3
|
+
tldr; Do not use `render inline:`.
|
4
|
+
|
5
|
+
## Rendering plain text
|
6
|
+
|
7
|
+
``` ruby
|
8
|
+
render inline: "Just plain text" # bad
|
9
|
+
```
|
10
|
+
|
11
|
+
The `inline:` option is often misused when plain text is being returned. Instead use `render plain: "Just plain text"`.
|
12
|
+
|
13
|
+
## Rendering a dynamic ERB string
|
14
|
+
|
15
|
+
String `#{}` interpolation is often misused with `render inline:` instead of using `<%= %>` interpolation. This will lead to a memory leak where an ERB method will be compiled and cached for each invocation of `render inline:`.
|
16
|
+
|
17
|
+
``` ruby
|
18
|
+
render inline: "Hello #{@name}" # bad
|
19
|
+
```
|
20
|
+
|
21
|
+
## Rendering static ERB strings
|
22
|
+
|
23
|
+
``` ruby
|
24
|
+
render inline: "Hello <%= @name %>" # bad
|
25
|
+
```
|
26
|
+
|
27
|
+
If you are passing a static ERB string to `render inline:`, this string is best moved to a `.erb` template under `app/views`. Template files are able to be precompiled at boot time.
|
@@ -0,0 +1,8 @@
|
|
1
|
+
# Standard/RailsRenderLiteral
|
2
|
+
|
3
|
+
tldr; `render` MUST be passed a string literal template path.
|
4
|
+
|
5
|
+
* When used in conjunction with `Standard/RailsViewRenderPathsExist`, linters can ensure the target file exists on disk and would not crash rendering a missing template.
|
6
|
+
* Makes it easier for humans to trace callers of a template. Simply search for the full path of the target template to find **all** call sites.
|
7
|
+
* This same call site tracing enables automated unused template checking. If no callers are found, the template can be safely removed.
|
8
|
+
* Enables render precompilation and inlining optimizations. Target templates can be compiled and inlined on boot time rather than deferring to first render to lazily compile templates.
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "rubocop"
|
4
|
+
|
5
|
+
module RuboCop
|
6
|
+
module Cop
|
7
|
+
module Standard
|
8
|
+
class RailsApplicationRecord < Cop
|
9
|
+
MSG = "Models should subclass from ApplicationRecord"
|
10
|
+
|
11
|
+
def_node_matcher :active_record_base_const?, <<-PATTERN
|
12
|
+
(const (const nil? :ActiveRecord) :Base)
|
13
|
+
PATTERN
|
14
|
+
|
15
|
+
def_node_matcher :application_record_const?, <<-PATTERN
|
16
|
+
(const nil? :ApplicationRecord)
|
17
|
+
PATTERN
|
18
|
+
|
19
|
+
def on_class(node)
|
20
|
+
klass, superclass, _ = *node
|
21
|
+
|
22
|
+
if active_record_base_const?(superclass) && !(application_record_const?(klass))
|
23
|
+
add_offense(superclass, location: :expression)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "rubocop"
|
4
|
+
|
5
|
+
module RuboCop
|
6
|
+
module Cop
|
7
|
+
module Standard
|
8
|
+
class RailsControllerRenderActionSymbol < Cop
|
9
|
+
MSG = "Prefer `render` with string instead of symbol"
|
10
|
+
|
11
|
+
def_node_matcher :render_sym?, <<-PATTERN
|
12
|
+
(send nil? :render $(sym _))
|
13
|
+
PATTERN
|
14
|
+
|
15
|
+
def_node_matcher :render_with_options?, <<-PATTERN
|
16
|
+
(send nil? :render (hash $...))
|
17
|
+
PATTERN
|
18
|
+
|
19
|
+
def_node_matcher :action_key?, <<-PATTERN
|
20
|
+
(pair (sym {:action :template}) $(sym _))
|
21
|
+
PATTERN
|
22
|
+
|
23
|
+
def on_send(node)
|
24
|
+
if sym_node = render_sym?(node)
|
25
|
+
add_offense(sym_node, location: :expression)
|
26
|
+
elsif option_pairs = render_with_options?(node)
|
27
|
+
option_pairs.each do |pair|
|
28
|
+
if sym_node = action_key?(pair)
|
29
|
+
add_offense(sym_node, location: :expression)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def autocorrect(node)
|
36
|
+
lambda do |corrector|
|
37
|
+
corrector.replace(node.source_range, "\"#{node.children[0]}\"")
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,94 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "rubocop"
|
4
|
+
|
5
|
+
module RuboCop
|
6
|
+
module Cop
|
7
|
+
module Standard
|
8
|
+
class RailsControllerRenderLiteral < Cop
|
9
|
+
MSG = "render must be used with a string literal"
|
10
|
+
|
11
|
+
def_node_matcher :literal?, <<-PATTERN
|
12
|
+
({str sym true false nil?} ...)
|
13
|
+
PATTERN
|
14
|
+
|
15
|
+
def_node_matcher :render?, <<-PATTERN
|
16
|
+
(send nil? :render ...)
|
17
|
+
PATTERN
|
18
|
+
|
19
|
+
def_node_matcher :render_literal?, <<-PATTERN
|
20
|
+
(send nil? :render ({str sym} $_) $...)
|
21
|
+
PATTERN
|
22
|
+
|
23
|
+
def_node_matcher :render_with_options?, <<-PATTERN
|
24
|
+
(send nil? :render (hash $...))
|
25
|
+
PATTERN
|
26
|
+
|
27
|
+
def_node_matcher :ignore_key?, <<-PATTERN
|
28
|
+
(pair (sym {
|
29
|
+
:body
|
30
|
+
:file
|
31
|
+
:html
|
32
|
+
:inline
|
33
|
+
:js
|
34
|
+
:json
|
35
|
+
:nothing
|
36
|
+
:plain
|
37
|
+
:text
|
38
|
+
:xml
|
39
|
+
}) $_)
|
40
|
+
PATTERN
|
41
|
+
|
42
|
+
def_node_matcher :template_key?, <<-PATTERN
|
43
|
+
(pair (sym {
|
44
|
+
:action
|
45
|
+
:partial
|
46
|
+
:template
|
47
|
+
}) $_)
|
48
|
+
PATTERN
|
49
|
+
|
50
|
+
def_node_matcher :layout_key?, <<-PATTERN
|
51
|
+
(pair (sym :layout) $_)
|
52
|
+
PATTERN
|
53
|
+
|
54
|
+
def_node_matcher :options_key?, <<-PATTERN
|
55
|
+
(pair (sym {
|
56
|
+
:content_type
|
57
|
+
:location
|
58
|
+
:status
|
59
|
+
:formats
|
60
|
+
}) ...)
|
61
|
+
PATTERN
|
62
|
+
|
63
|
+
def on_send(node)
|
64
|
+
return unless render?(node)
|
65
|
+
|
66
|
+
if render_literal?(node)
|
67
|
+
elsif option_pairs = render_with_options?(node)
|
68
|
+
option_pairs = option_pairs.reject { |pair| options_key?(pair) }
|
69
|
+
|
70
|
+
if option_pairs.any? { |pair| ignore_key?(pair) }
|
71
|
+
return
|
72
|
+
end
|
73
|
+
|
74
|
+
if template_node = option_pairs.map { |pair| template_key?(pair) }.compact.first
|
75
|
+
if !literal?(template_node)
|
76
|
+
add_offense(node, location: :expression)
|
77
|
+
end
|
78
|
+
else
|
79
|
+
add_offense(node, location: :expression)
|
80
|
+
end
|
81
|
+
|
82
|
+
if layout_node = option_pairs.map { |pair| layout_key?(pair) }.compact.first
|
83
|
+
if !literal?(layout_node)
|
84
|
+
add_offense(node, location: :expression)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
else
|
88
|
+
add_offense(node, location: :expression)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|