rubocop-github 0.16.1 → 0.18.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,7 +5,7 @@ require "rubocop"
5
5
  module RuboCop
6
6
  module Cop
7
7
  module GitHub
8
- class RailsControllerRenderPathsExist < Cop
8
+ class RailsControllerRenderPathsExist < Base
9
9
  def_node_matcher :render?, <<-PATTERN
10
10
  (send nil? {:render :render_to_string} $...)
11
11
  PATTERN
@@ -28,7 +28,7 @@ module RuboCop
28
28
  if args = render_str?(node)
29
29
  node, path = args
30
30
  unless resolve_template(path.to_s)
31
- add_offense(node, location: :expression, message: "Template could not be found")
31
+ add_offense(node, message: "Template could not be found")
32
32
  end
33
33
  elsif pairs = render_options?(node)
34
34
  if pair = pairs.detect { |p| render_key?(p) }
@@ -37,11 +37,11 @@ module RuboCop
37
37
  case key
38
38
  when :action, :template
39
39
  unless resolve_template(path.to_s)
40
- add_offense(node, location: :expression, message: "Template could not be found")
40
+ add_offense(node, message: "Template could not be found")
41
41
  end
42
42
  when :partial
43
43
  unless resolve_partial(path.to_s)
44
- add_offense(node, location: :expression, message: "Partial template could not be found")
44
+ add_offense(node, message: "Partial template could not be found")
45
45
  end
46
46
  end
47
47
  end
@@ -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
@@ -20,10 +20,6 @@ module RuboCop
20
20
  (send nil? {:render :render_to_string} ({str sym} $_) $...)
21
21
  PATTERN
22
22
 
23
- def_node_matcher :render_inst?, <<-PATTERN
24
- (send nil? {:render :render_to_string} (send _ :new ...) ...)
25
- PATTERN
26
-
27
23
  def_node_matcher :render_with_options?, <<-PATTERN
28
24
  (send nil? {:render :render_to_string} (hash $...) ...)
29
25
  PATTERN
@@ -32,6 +28,10 @@ module RuboCop
32
28
  (send nil? {:render :render_to_string} (send _ :new ...) ...)
33
29
  PATTERN
34
30
 
31
+ def_node_matcher :render_view_component_instance_with_content?, <<-PATTERN
32
+ (send nil? {:render :render_to_string} (send (send _ :new ...) `:with_content ...))
33
+ PATTERN
34
+
35
35
  def_node_matcher :render_view_component_collection?, <<-PATTERN
36
36
  (send nil? {:render :render_to_string} (send _ :with_collection ...) ...)
37
37
  PATTERN
@@ -45,7 +45,8 @@ module RuboCop
45
45
  end
46
46
 
47
47
  def render_view_component?(node)
48
- render_view_component_instance?(node) ||
48
+ render_view_component_instance_with_content?(node) ||
49
+ render_view_component_instance?(node) ||
49
50
  render_view_component_collection?(node)
50
51
  end
51
52
  end
metadata CHANGED
@@ -1,99 +1,99 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubocop-github
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.16.1
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: 2021-02-11 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
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "<="
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 1.6.1
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: 1.6.1
26
+ version: 1.0.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rubocop-performance
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "<="
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: 1.7.1
33
+ version: '0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "<="
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: 1.7.1
40
+ version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rubocop-rails
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "<="
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: 2.7.1
47
+ version: '0'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "<="
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: 2.7.1
54
+ version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: actionview
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - "~>"
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
- version: '5.0'
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: '5.0'
68
+ version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: minitest
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - "~>"
73
+ - - ">="
74
74
  - !ruby/object:Gem::Version
75
- version: '5.14'
75
+ version: '0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - "~>"
80
+ - - ">="
81
81
  - !ruby/object:Gem::Version
82
- version: '5.14'
82
+ version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: rake
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - "~>"
87
+ - - ">="
88
88
  - !ruby/object:Gem::Version
89
- version: '12.0'
89
+ version: '0'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - "~>"
94
+ - - ">="
95
95
  - !ruby/object:Gem::Version
96
- version: '12.0'
96
+ version: '0'
97
97
  description: 'Code style checking for GitHub Ruby repositories '
98
98
  email: engineering@github.com
99
99
  executables: []
@@ -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.4
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