rubocop-github 0.17.0 → 0.18.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,7 +5,9 @@ require "rubocop"
5
5
  module RuboCop
6
6
  module Cop
7
7
  module GitHub
8
- class RailsControllerRenderShorthand < Cop
8
+ class RailsControllerRenderShorthand < Base
9
+ extend AutoCorrector
10
+
9
11
  MSG = "Prefer `render` template shorthand"
10
12
 
11
13
  def_node_matcher :render_with_options?, <<-PATTERN
@@ -20,14 +22,6 @@ module RuboCop
20
22
  ({str sym} $_)
21
23
  PATTERN
22
24
 
23
- def investigate(*)
24
- @autocorrect = {}
25
- end
26
-
27
- def autocorrect(node)
28
- @autocorrect[node]
29
- end
30
-
31
25
  def on_send(node)
32
26
  if option_pairs = render_with_options?(node)
33
27
  option_pairs.each do |pair|
@@ -37,10 +31,9 @@ module RuboCop
37
31
  .sub(/#{pair.source}(,\s*)?/, "")
38
32
  .sub("render ", "render \"#{str(value_node)}\"#{comma}")
39
33
 
40
- @autocorrect[node] = lambda do |corrector|
34
+ add_offense(node, message: "Use `#{corrected_source}` instead") do |corrector|
41
35
  corrector.replace(node.source_range, corrected_source)
42
36
  end
43
- add_offense(node, location: :expression, message: "Use `#{corrected_source}` instead")
44
37
  end
45
38
  end
46
39
  end
@@ -5,7 +5,7 @@ require "rubocop"
5
5
  module RuboCop
6
6
  module Cop
7
7
  module GitHub
8
- class RailsRenderInline < Cop
8
+ class RailsRenderInline < Base
9
9
  MSG = "Avoid `render inline:`"
10
10
 
11
11
  def_node_matcher :render_with_options?, <<-PATTERN
@@ -19,7 +19,7 @@ module RuboCop
19
19
  def on_send(node)
20
20
  if option_pairs = render_with_options?(node)
21
21
  if option_pairs.detect { |pair| inline_key?(pair) }
22
- add_offense(node, location: :expression)
22
+ add_offense(node)
23
23
  end
24
24
  end
25
25
  end
@@ -5,7 +5,7 @@ require "rubocop"
5
5
  module RuboCop
6
6
  module Cop
7
7
  module GitHub
8
- class RailsRenderObjectCollection < Cop
8
+ class RailsRenderObjectCollection < Base
9
9
  MSG = "Avoid `render object:`"
10
10
 
11
11
  def_node_matcher :render_with_options?, <<-PATTERN
@@ -34,9 +34,9 @@ module RuboCop
34
34
  if partial_name.children[0].is_a?(String)
35
35
  suggestion = ", instead `render partial: #{partial_name.source}, locals: { #{File.basename(partial_name.children[0], '.html.erb')}: #{object_node.source} }`"
36
36
  end
37
- add_offense(node, location: :expression, message: "Avoid `render object:`#{suggestion}")
37
+ add_offense(node, message: "Avoid `render object:`#{suggestion}")
38
38
  when :collection, :spacer_template
39
- add_offense(node, location: :expression, message: "Avoid `render collection:`")
39
+ add_offense(node, message: "Avoid `render collection:`")
40
40
  end
41
41
  end
42
42
  end
@@ -6,7 +6,7 @@ require "rubocop/cop/github/render_literal_helpers"
6
6
  module RuboCop
7
7
  module Cop
8
8
  module GitHub
9
- class RailsViewRenderLiteral < Cop
9
+ class RailsViewRenderLiteral < Base
10
10
  include RenderLiteralHelpers
11
11
 
12
12
  MSG = "render must be used with a literal template and use literals for locals keys"
@@ -40,15 +40,15 @@ module RuboCop
40
40
 
41
41
  if partial_node = option_pairs.map { |pair| partial_key?(pair) }.compact.first
42
42
  if !literal?(partial_node)
43
- add_offense(node, location: :expression)
43
+ add_offense(node)
44
44
  return
45
45
  end
46
46
  else
47
- add_offense(node, location: :expression)
47
+ add_offense(node)
48
48
  return
49
49
  end
50
50
  else
51
- add_offense(node, location: :expression)
51
+ add_offense(node)
52
52
  return
53
53
  end
54
54
 
@@ -61,10 +61,10 @@ module RuboCop
61
61
  if locals
62
62
  if locals.hash_type?
63
63
  if !hash_with_literal_keys?(locals)
64
- add_offense(node, location: :expression)
64
+ add_offense(node)
65
65
  end
66
66
  else
67
- add_offense(node, location: :expression)
67
+ add_offense(node)
68
68
  end
69
69
  end
70
70
  end
@@ -5,7 +5,7 @@ require "rubocop"
5
5
  module RuboCop
6
6
  module Cop
7
7
  module GitHub
8
- class RailsViewRenderPathsExist < Cop
8
+ class RailsViewRenderPathsExist < Base
9
9
  def_node_matcher :render?, <<-PATTERN
10
10
  (send nil? {:render :render_to_string} $...)
11
11
  PATTERN
@@ -28,14 +28,14 @@ module RuboCop
28
28
  if args = render_str?(node)
29
29
  node, path = args
30
30
  unless resolve_partial(path.to_s)
31
- add_offense(node, location: :expression, message: "Partial template could not be found")
31
+ add_offense(node, message: "Partial template could not be found")
32
32
  end
33
33
  elsif pairs = render_options?(node)
34
34
  if pair = pairs.detect { |p| partial_key?(p) }
35
35
  node, path = partial_key?(pair)
36
36
 
37
37
  unless resolve_partial(path.to_s)
38
- add_offense(node, location: :expression, message: "Partial template could not be found")
38
+ add_offense(node, message: "Partial template could not be found")
39
39
  end
40
40
  end
41
41
  end
@@ -5,7 +5,7 @@ require "rubocop"
5
5
  module RuboCop
6
6
  module Cop
7
7
  module GitHub
8
- class RailsViewRenderShorthand < Cop
8
+ class RailsViewRenderShorthand < Base
9
9
  MSG = "Prefer `render` partial shorthand"
10
10
 
11
11
  def_node_matcher :render_with_options?, <<-PATTERN
@@ -26,9 +26,9 @@ module RuboCop
26
26
  locals_key = option_pairs.map { |pair| locals_key?(pair) }.compact.first
27
27
 
28
28
  if option_pairs.length == 1 && partial_key
29
- add_offense(node, location: :expression, message: "Use `render #{partial_key.source}` instead")
29
+ add_offense(node, message: "Use `render #{partial_key.source}` instead")
30
30
  elsif option_pairs.length == 2 && partial_key && locals_key
31
- add_offense(node, location: :expression, message: "Use `render #{partial_key.source}, #{locals_key.source}` instead")
31
+ add_offense(node, message: "Use `render #{partial_key.source}, #{locals_key.source}` instead")
32
32
  end
33
33
  end
34
34
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubocop-github
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.17.0
4
+ version: 0.18.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - GitHub
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-01-19 00:00:00.000000000 Z
11
+ date: 2022-06-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubocop
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: 1.0.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
26
+ version: 1.0.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rubocop-performance
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -56,16 +56,16 @@ dependencies:
56
56
  name: actionview
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - "~>"
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
- version: '6.1'
61
+ version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - "~>"
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
- version: '6.1'
68
+ version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: minitest
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -103,14 +103,8 @@ files:
103
103
  - LICENSE
104
104
  - README.md
105
105
  - STYLEGUIDE.md
106
- - config/_default_shared.yml
107
- - config/_rails_shared.yml
108
106
  - config/default.yml
109
- - config/default_deprecated.yml
110
- - config/default_edge.yml
111
107
  - config/rails.yml
112
- - config/rails_deprecated.yml
113
- - config/rails_edge.yml
114
108
  - guides/rails-controller-render-shorthand.md
115
109
  - guides/rails-render-inline.md
116
110
  - guides/rails-render-literal.md
@@ -146,7 +140,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
146
140
  - !ruby/object:Gem::Version
147
141
  version: '0'
148
142
  requirements: []
149
- rubygems_version: 3.1.6
143
+ rubygems_version: 3.2.22
150
144
  signing_key:
151
145
  specification_version: 4
152
146
  summary: RuboCop GitHub
@@ -1,329 +0,0 @@
1
- require:
2
- - rubocop/cop/github
3
- - rubocop-performance
4
-
5
- # These cops are compatible across supported versions of rubocop
6
-
7
- Bundler/DuplicatedGem:
8
- Enabled: true
9
-
10
- Bundler/OrderedGems:
11
- Enabled: true
12
-
13
- GitHub/InsecureHashAlgorithm:
14
- Enabled: true
15
-
16
- Layout/BlockAlignment:
17
- Enabled: true
18
-
19
- Layout/BlockEndNewline:
20
- Enabled: true
21
-
22
- Layout/ConditionPosition:
23
- Enabled: true
24
-
25
- Layout/DefEndAlignment:
26
- Enabled: true
27
-
28
- Layout/EndAlignment:
29
- Enabled: false
30
-
31
- Layout/EndOfLine:
32
- Enabled: true
33
-
34
- Layout/IndentationStyle:
35
- Enabled: true
36
- EnforcedStyle: spaces
37
- IndentationWidth: 2
38
-
39
- Layout/InitialIndentation:
40
- Enabled: true
41
-
42
- Layout/LineLength:
43
- Enabled: false
44
-
45
- Layout/SpaceAfterColon:
46
- Enabled: true
47
-
48
- Layout/SpaceAfterComma:
49
- Enabled: true
50
-
51
- Layout/SpaceAfterMethodName:
52
- Enabled: true
53
-
54
- Layout/SpaceAfterNot:
55
- Enabled: true
56
-
57
- Layout/SpaceAfterSemicolon:
58
- Enabled: true
59
-
60
- Layout/SpaceAroundBlockParameters:
61
- Enabled: true
62
-
63
- Layout/SpaceAroundEqualsInParameterDefault:
64
- Enabled: true
65
-
66
- Layout/SpaceBeforeBlockBraces:
67
- Enabled: true
68
-
69
- Layout/SpaceInsideArrayLiteralBrackets:
70
- Enabled: true
71
- EnforcedStyle: no_space
72
-
73
- Layout/SpaceInsideArrayPercentLiteral:
74
- Enabled: true
75
-
76
- Layout/SpaceInsideBlockBraces:
77
- Enabled: true
78
-
79
- Layout/SpaceInsideParens:
80
- Enabled: true
81
-
82
- Layout/SpaceInsideRangeLiteral:
83
- Enabled: true
84
-
85
- Layout/SpaceInsideReferenceBrackets:
86
- Enabled: true
87
-
88
- Layout/TrailingEmptyLines:
89
- Enabled: true
90
-
91
- Layout/TrailingWhitespace:
92
- Enabled: true
93
-
94
- Lint/CircularArgumentReference:
95
- Enabled: true
96
-
97
- Lint/Debugger:
98
- Enabled: true
99
-
100
- Lint/DeprecatedClassMethods:
101
- Enabled: true
102
-
103
- Lint/DuplicateMethods:
104
- Enabled: true
105
-
106
- Lint/DuplicateHashKey:
107
- Enabled: true
108
-
109
- Lint/EachWithObjectArgument:
110
- Enabled: true
111
-
112
- Lint/ElseLayout:
113
- Enabled: true
114
-
115
- Lint/EmptyEnsure:
116
- Enabled: true
117
-
118
- Lint/EmptyInterpolation:
119
- Enabled: true
120
-
121
- Lint/EnsureReturn:
122
- Enabled: true
123
-
124
- Lint/FlipFlop:
125
- Enabled: true
126
-
127
- Lint/FloatOutOfRange:
128
- Enabled: true
129
-
130
- Lint/FormatParameterMismatch:
131
- Enabled: true
132
-
133
- Lint/LiteralAsCondition:
134
- Enabled: true
135
-
136
- Lint/LiteralInInterpolation:
137
- Enabled: true
138
-
139
- Lint/Loop:
140
- Enabled: true
141
-
142
- Lint/NextWithoutAccumulator:
143
- Enabled: true
144
-
145
- Lint/RandOne:
146
- Enabled: true
147
-
148
- Lint/RequireParentheses:
149
- Enabled: true
150
-
151
- Lint/RescueException:
152
- Enabled: true
153
-
154
- Lint/RedundantStringCoercion:
155
- Enabled: true
156
-
157
- Lint/UnderscorePrefixedVariableName:
158
- Enabled: true
159
-
160
- Lint/RedundantCopDisableDirective:
161
- Enabled: true
162
-
163
- Lint/RedundantSplatExpansion:
164
- Enabled: true
165
-
166
- Lint/UnreachableCode:
167
- Enabled: true
168
-
169
- Lint/BinaryOperatorWithIdenticalOperands:
170
- Enabled: true
171
-
172
- Lint/UselessSetterCall:
173
- Enabled: true
174
-
175
- Lint/Void:
176
- Enabled: true
177
-
178
- Metrics/AbcSize:
179
- Enabled: false
180
-
181
- Metrics/BlockLength:
182
- Enabled: false
183
-
184
- Metrics/BlockNesting:
185
- Enabled: false
186
-
187
- Metrics/ClassLength:
188
- Enabled: false
189
-
190
- Metrics/CyclomaticComplexity:
191
- Enabled: false
192
-
193
- Metrics/MethodLength:
194
- Enabled: false
195
-
196
- Metrics/ModuleLength:
197
- Enabled: false
198
-
199
- Metrics/ParameterLists:
200
- Enabled: false
201
-
202
- Metrics/PerceivedComplexity:
203
- Enabled: false
204
-
205
- Naming/AsciiIdentifiers:
206
- Enabled: true
207
-
208
- Naming/ClassAndModuleCamelCase:
209
- Enabled: true
210
-
211
- Naming/FileName:
212
- Enabled: true
213
-
214
- Naming/MethodName:
215
- Enabled: true
216
-
217
- Performance/CaseWhenSplat:
218
- Enabled: false
219
-
220
- Performance/Count:
221
- Enabled: true
222
-
223
- Performance/Detect:
224
- Enabled: true
225
-
226
- Performance/DoubleStartEndWith:
227
- Enabled: true
228
-
229
- Performance/EndWith:
230
- Enabled: true
231
-
232
- Performance/FlatMap:
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/ReverseEach:
246
- Enabled: true
247
-
248
- Performance/Size:
249
- Enabled: true
250
-
251
- Performance/StartWith:
252
- Enabled: true
253
-
254
- Security/Eval:
255
- Enabled: true
256
-
257
- Style/ArrayJoin:
258
- Enabled: true
259
-
260
- Style/BeginBlock:
261
- Enabled: true
262
-
263
- Style/BlockComments:
264
- Enabled: true
265
-
266
- Style/CaseEquality:
267
- Enabled: true
268
-
269
- Style/CharacterLiteral:
270
- Enabled: true
271
-
272
- Style/ClassMethods:
273
- Enabled: true
274
-
275
- Style/Copyright:
276
- Enabled: false
277
-
278
- Style/DefWithParentheses:
279
- Enabled: true
280
-
281
- Style/EndBlock:
282
- Enabled: true
283
-
284
- Style/For:
285
- Enabled: true
286
-
287
- Style/FrozenStringLiteralComment:
288
- Enabled: true
289
-
290
- Style/HashSyntax:
291
- Enabled: true
292
- EnforcedStyle: ruby19_no_mixed_keys
293
-
294
- Style/LambdaCall:
295
- Enabled: true
296
-
297
- Style/MethodCallWithoutArgsParentheses:
298
- Enabled: true
299
-
300
- Style/MethodDefParentheses:
301
- Enabled: true
302
-
303
- Style/MultilineIfThen:
304
- Enabled: true
305
-
306
- Style/NilComparison:
307
- Enabled: true
308
-
309
- Style/Not:
310
- Enabled: true
311
-
312
- Style/OneLineConditional:
313
- Enabled: true
314
-
315
- Style/RedundantSortBy:
316
- Enabled: true
317
-
318
- Style/Sample:
319
- Enabled: true
320
-
321
- Style/StabbyLambdaParentheses:
322
- Enabled: true
323
-
324
- Style/Strip:
325
- Enabled: true
326
-
327
- Style/StringLiterals:
328
- Enabled: true
329
- EnforcedStyle: double_quotes
@@ -1,120 +0,0 @@
1
- Rails/OutputSafety:
2
- Enabled: true
3
-
4
- Rails/PluralizationGrammar:
5
- Enabled: true
6
-
7
- Rails/RequestReferer:
8
- Enabled: true
9
- EnforcedStyle: referrer
10
-
11
- Rails/ScopeArgs:
12
- Enabled: true
13
-
14
- Rails/UniqBeforePluck:
15
- Enabled: true
16
-
17
- GitHub/RailsApplicationRecord:
18
- Enabled: true
19
-
20
- GitHub/RailsControllerRenderActionSymbol:
21
- Enabled: true
22
- Include:
23
- - 'app/controllers/**/*.rb'
24
-
25
- GitHub/RailsControllerRenderLiteral:
26
- Enabled: true
27
- StyleGuide: https://github.com/github/rubocop-github/blob/master/guides/rails-render-literal.md
28
- Include:
29
- - 'app/controllers/**/*.rb'
30
-
31
- GitHub/RailsControllerRenderPathsExist:
32
- Enabled: true
33
- ViewPath:
34
- - 'app/views'
35
- Include:
36
- - 'app/controllers/**/*.rb'
37
-
38
- GitHub/RailsControllerRenderShorthand:
39
- Enabled: true
40
- StyleGuide: https://github.com/github/rubocop-github/blob/master/guides/rails-controller-render-shorthand.md
41
- Include:
42
- - 'app/controllers/**/*.rb'
43
-
44
- GitHub/RailsRenderInline:
45
- Enabled: true
46
- StyleGuide: https://github.com/github/rubocop-github/blob/master/guides/rails-controller-render-inline.md
47
- Include:
48
- - 'app/controllers/**/*.rb'
49
- - 'app/helpers/**/*.rb'
50
- - 'app/view_models/**/*.rb'
51
- - 'app/views/**/*.erb'
52
-
53
- GitHub/RailsRenderObjectCollection:
54
- Enabled: false
55
-
56
- GitHub/RailsViewRenderLiteral:
57
- Enabled: true
58
- StyleGuide: https://github.com/github/rubocop-github/blob/master/guides/rails-render-literal.md
59
- Include:
60
- - 'app/helpers/**/*.rb'
61
- - 'app/view_models/**/*.rb'
62
- - 'app/views/**/*.erb'
63
-
64
- GitHub/RailsViewRenderPathsExist:
65
- Enabled: true
66
- ViewPath:
67
- - 'app/views'
68
- Include:
69
- - 'app/helpers/**/*.rb'
70
- - 'app/view_models/**/*.rb'
71
- - 'app/views/**/*.erb'
72
-
73
- GitHub/RailsViewRenderShorthand:
74
- Enabled: true
75
- Include:
76
- - 'app/helpers/**/*.rb'
77
- - 'app/view_models/**/*.rb'
78
- - 'app/views/**/*.erb'
79
-
80
- # Exclude Rails ERB files from incompatible cops
81
-
82
- Layout/BlockAlignment:
83
- Exclude:
84
- - 'app/views/**/*.erb'
85
-
86
- Style/For:
87
- Exclude:
88
- - 'app/views/**/*.erb'
89
-
90
- Style/OneLineConditional:
91
- Exclude:
92
- - 'app/views/**/*.erb'
93
-
94
- Style/Semicolon:
95
- Exclude:
96
- - 'app/views/**/*.erb'
97
-
98
- Layout/SpaceInsideParens:
99
- Exclude:
100
- - 'app/views/**/*.erb'
101
-
102
- Style/StringLiterals:
103
- Exclude:
104
- - 'app/views/**/*.erb'
105
-
106
- Layout/TrailingEmptyLines:
107
- Exclude:
108
- - 'app/views/**/*.erb'
109
-
110
- Layout/TrailingWhitespace:
111
- Exclude:
112
- - 'app/views/**/*.erb'
113
-
114
- Layout/InitialIndentation:
115
- Exclude:
116
- - 'app/views/**/*.erb'
117
-
118
- Lint/UselessAccessModifier:
119
- ContextCreatingMethods:
120
- - concerning
@@ -1,4 +0,0 @@
1
- inherit_from: _default_shared.yml
2
-
3
- AllCops:
4
- DisabledByDefault: true
@@ -1,4 +0,0 @@
1
- inherit_from: _default_shared.yml
2
-
3
- require:
4
- - rubocop-performance
@@ -1,7 +0,0 @@
1
- inherit_from: _rails_shared.yml
2
-
3
- Rails:
4
- Enabled: true
5
-
6
- Rails/FindEach:
7
- Enabled: false