rubocop-standard 2.1.1 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a278ae17b941dde291fbf9b0917c87731c0cb00c7f57ba6686e07708ad9d3ed1
4
- data.tar.gz: 5679d32a6f9a89bd56e1458e8ca23b6c5728dff8b5a5419569153cebec67f578
3
+ metadata.gz: 255673146dc715318488a00c6acf2b2f028c3c447824e01dc120e78bd6be3478
4
+ data.tar.gz: 3c477ce44365e81ac03f027e23ab2b2b479cdfdc8e8d0bbb329b3de64e97faea
5
5
  SHA512:
6
- metadata.gz: 914945a7573c9c7a30e0a4b4b0a5c80755d39967a098f126459a5d0f16f5a5a2a9f018528ac0397b588bddb54eafb8cc69c9cb50455a41fb0242b7eede98ba3b
7
- data.tar.gz: b6478eb87ba36ffcc66f88852708f00ac9d372e5568d41e00be0f9ba61caf4a1d900298d57271acd8a5aad61f4858a62b5e34635a1cac66e7689a5eeda6e9903
6
+ metadata.gz: 63b8c5b720621c03508c3bbc07c5f904456fb2330a83446f862c7cab921c8eb596e05d1ab69f71c98b806635916e9763c46af3d0af364bad90a482031f6952cb
7
+ data.tar.gz: ccfd489f536affc8d5bf7594480f79aa687be847d02f6af98b8f071649b69e2430da0eb8f7168b3f397c64c2c8ec8239d8fbb86d4bc6793dc0151b709c0d6a7b
data/config/default.yml CHANGED
@@ -1,5 +1,4 @@
1
1
  require:
2
- - rubocop/cop/standard
3
2
  - rubocop-performance
4
3
 
5
4
  Bundler/DuplicatedGem:
@@ -29,6 +28,9 @@ Layout/EndOfLine:
29
28
  Layout/InitialIndentation:
30
29
  Enabled: true
31
30
 
31
+ Layout/LineLength:
32
+ Enabled: false
33
+
32
34
  Layout/SpaceAfterColon:
33
35
  Enabled: true
34
36
 
@@ -183,9 +185,6 @@ Metrics/ClassLength:
183
185
  Metrics/CyclomaticComplexity:
184
186
  Enabled: false
185
187
 
186
- Metrics/LineLength:
187
- Enabled: false
188
-
189
188
  Metrics/MethodLength:
190
189
  Enabled: false
191
190
 
@@ -274,6 +273,9 @@ Style/Copyright:
274
273
  Style/DefWithParentheses:
275
274
  Enabled: true
276
275
 
276
+ Style/Documentation:
277
+ Enabled: false
278
+
277
279
  Style/EndBlock:
278
280
  Enabled: true
279
281
 
data/config/rails.yml CHANGED
@@ -1,5 +1,6 @@
1
1
  require:
2
2
  - rubocop-rails
3
+ - rubocop/cop/standard/rails
3
4
 
4
5
  Rails/OutputSafety:
5
6
  Enabled: true
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rubocop/cop/standard/rails/rails_application_record'
4
+ require 'rubocop/cop/standard/rails/rails_controller_render_action_symbol'
5
+ require 'rubocop/cop/standard/rails/rails_controller_render_literal'
6
+ require 'rubocop/cop/standard/rails/rails_controller_render_paths_exist'
7
+ require 'rubocop/cop/standard/rails/rails_controller_render_shorthand'
8
+ require 'rubocop/cop/standard/rails/rails_render_inline'
9
+ require 'rubocop/cop/standard/rails/rails_render_object_collection'
10
+ require 'rubocop/cop/standard/rails/rails_view_render_literal'
11
+ require 'rubocop/cop/standard/rails/rails_view_render_paths_exist'
12
+ require 'rubocop/cop/standard/rails/rails_view_render_shorthand'
@@ -21,11 +21,11 @@ module RuboCop
21
21
  PATTERN
22
22
 
23
23
  def on_send(node)
24
- if sym_node = render_sym?(node)
24
+ if (sym_node = render_sym?(node))
25
25
  add_offense(sym_node, location: :expression)
26
- elsif option_pairs = render_with_options?(node)
26
+ elsif (option_pairs = render_with_options?(node))
27
27
  option_pairs.each do |pair|
28
- if sym_node = action_key?(pair)
28
+ if (sym_node = action_key?(pair))
29
29
  add_offense(sym_node, location: :expression)
30
30
  end
31
31
  end
@@ -72,18 +72,18 @@ module RuboCop
72
72
  return unless render?(node)
73
73
 
74
74
  if render_literal?(node) || render_inst?(node) || render_const?(node)
75
- elsif option_pairs = render_with_options?(node)
75
+ elsif (option_pairs = render_with_options?(node))
76
76
  option_pairs = option_pairs.reject { |pair| options_key?(pair) }
77
77
 
78
78
  return if option_pairs.any? { |pair| ignore_key?(pair) }
79
79
 
80
- if template_node = option_pairs.map { |pair| template_key?(pair) }.compact.first
80
+ if (template_node = option_pairs.map { |pair| template_key?(pair) }.compact.first)
81
81
  add_offense(node, location: :expression) unless literal?(template_node)
82
82
  else
83
83
  add_offense(node, location: :expression)
84
84
  end
85
85
 
86
- if layout_node = option_pairs.map { |pair| layout_key?(pair) }.compact.first
86
+ if (layout_node = option_pairs.map { |pair| layout_key?(pair) }.compact.first)
87
87
  add_offense(node, location: :expression) unless literal?(layout_node)
88
88
  end
89
89
  else
@@ -25,11 +25,11 @@ module RuboCop
25
25
  def on_send(node)
26
26
  return unless cop_config['ViewPath']
27
27
 
28
- if args = render_str?(node)
28
+ if (args = render_str?(node))
29
29
  node, path = args
30
30
  add_offense(node, location: :expression, message: 'Template could not be found') unless resolve_template(path.to_s)
31
- elsif pairs = render_options?(node)
32
- if pair = pairs.detect { |p| render_key?(p) }
31
+ elsif (pairs = render_options?(node))
32
+ if (pair = pairs.detect { |p| render_key?(p) })
33
33
  key, node, path = render_key?(pair)
34
34
 
35
35
  case key
@@ -44,7 +44,7 @@ module RuboCop
44
44
 
45
45
  def resolve_template(path)
46
46
  cop_config['ViewPath'].each do |view_path|
47
- if m = Dir[File.join(config.path_relative_to_config(view_path), path) + '*'].first
47
+ if (m = Dir[File.join(config.path_relative_to_config(view_path), path) + '*'].first)
48
48
  return m
49
49
  end
50
50
  end
@@ -29,20 +29,20 @@ module RuboCop
29
29
  end
30
30
 
31
31
  def on_send(node)
32
- if option_pairs = render_with_options?(node)
33
- option_pairs.each do |pair|
34
- next unless value_node = action_key?(pair)
35
-
36
- comma = option_pairs.length > 1 ? ', ' : ''
37
- corrected_source = node.source
38
- .sub(/#{pair.source}(,\s*)?/, '')
39
- .sub('render ', "render \"#{str(value_node)}\"#{comma}")
40
-
41
- @autocorrect[node] = lambda do |corrector|
42
- corrector.replace(node.source_range, corrected_source)
43
- end
44
- add_offense(node, location: :expression, message: "Use `#{corrected_source}` instead")
32
+ return unless (option_pairs = render_with_options?(node))
33
+
34
+ option_pairs.each do |pair|
35
+ next unless (value_node = action_key?(pair))
36
+
37
+ comma = option_pairs.length > 1 ? ', ' : ''
38
+ corrected_source = node.source
39
+ .sub(/#{pair.source}(,\s*)?/, '')
40
+ .sub('render ', "render \"#{str(value_node)}\"#{comma}")
41
+
42
+ @autocorrect[node] = lambda do |corrector|
43
+ corrector.replace(node.source_range, corrected_source)
45
44
  end
45
+ add_offense(node, location: :expression, message: "Use `#{corrected_source}` instead")
46
46
  end
47
47
  end
48
48
  end
@@ -17,9 +17,9 @@ module RuboCop
17
17
  PATTERN
18
18
 
19
19
  def on_send(node)
20
- if option_pairs = render_with_options?(node)
21
- add_offense(node, location: :expression) if option_pairs.detect { |pair| inline_key?(pair) }
22
- end
20
+ return unless (option_pairs = render_with_options?(node))
21
+
22
+ add_offense(node, location: :expression) if option_pairs.detect { |pair| inline_key?(pair) }
23
23
  end
24
24
  end
25
25
  end
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rubocop'
4
+
5
+ module RuboCop
6
+ module Cop
7
+ module Standard
8
+ class RailsRenderObjectCollection < Cop
9
+ MSG = 'Avoid `render object:`'
10
+
11
+ def_node_matcher :render_with_options?, <<-PATTERN
12
+ (send nil? :render (hash $...) ...)
13
+ PATTERN
14
+
15
+ def_node_matcher :partial_key?, <<-PATTERN
16
+ (pair (sym :partial) $_)
17
+ PATTERN
18
+
19
+ def_node_matcher :object_key?, <<-PATTERN
20
+ (pair (sym ${:object :collection :spacer_template}) $_)
21
+ PATTERN
22
+
23
+ def on_send(node)
24
+ return unless (option_pairs = render_with_options?(node))
25
+
26
+ partial_pair = option_pairs.detect { |pair| partial_key?(pair) }
27
+ object_pair = option_pairs.detect { |pair| object_key?(pair) }
28
+
29
+ return unless partial_pair && object_pair
30
+
31
+ partial_name = partial_key?(partial_pair)
32
+ object_sym, object_node = object_key?(object_pair)
33
+
34
+ case object_sym
35
+ when :object
36
+ suggestion = ", instead `render partial: #{partial_name.source}, locals: { #{File.basename(partial_name.children[0], '.html.erb')}: #{object_node.source} }`" if partial_name.children[0].is_a?(String)
37
+ add_offense(node, location: :expression, message: "Avoid `render object:`#{suggestion}")
38
+ when :collection, :spacer_template
39
+ add_offense(node, location: :expression, message: 'Avoid `render collection:`')
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -51,10 +51,10 @@ module RuboCop
51
51
  return unless render?(node)
52
52
 
53
53
  if render_literal?(node) || render_inst?(node) || render_const?(node)
54
- elsif option_pairs = render_with_options?(node)
54
+ elsif (option_pairs = render_with_options?(node))
55
55
  return if option_pairs.any? { |pair| ignore_key?(pair) }
56
56
 
57
- if partial_node = option_pairs.map { |pair| partial_key?(pair) }.compact.first
57
+ if (partial_node = option_pairs.map { |pair| partial_key?(pair) }.compact.first)
58
58
  add_offense(node, location: :expression) unless literal?(partial_node)
59
59
  else
60
60
  add_offense(node, location: :expression)
@@ -25,11 +25,11 @@ module RuboCop
25
25
  def on_send(node)
26
26
  return unless cop_config['ViewPath']
27
27
 
28
- if args = render_str?(node)
28
+ if (args = render_str?(node))
29
29
  node, path = args
30
30
  add_offense(node, location: :expression, message: 'Partial template could not be found') unless resolve_partial(path.to_s)
31
- elsif pairs = render_options?(node)
32
- if pair = pairs.detect { |p| partial_key?(p) }
31
+ elsif (pairs = render_options?(node))
32
+ if (pair = pairs.detect { |p| partial_key?(p) })
33
33
  node, path = partial_key?(pair)
34
34
 
35
35
  add_offense(node, location: :expression, message: 'Partial template could not be found') unless resolve_partial(path.to_s)
@@ -43,7 +43,7 @@ module RuboCop
43
43
  path = parts.join(File::SEPARATOR)
44
44
 
45
45
  cop_config['ViewPath'].each do |view_path|
46
- if m = Dir[File.join(config.path_relative_to_config(view_path), path) + '*'].first
46
+ if (m = Dir[File.join(config.path_relative_to_config(view_path), path) + '*'].first)
47
47
  return m
48
48
  end
49
49
  end
@@ -21,15 +21,15 @@ module RuboCop
21
21
  PATTERN
22
22
 
23
23
  def on_send(node)
24
- if option_pairs = render_with_options?(node)
25
- partial_key = option_pairs.map { |pair| partial_key?(pair) }.compact.first
26
- locals_key = option_pairs.map { |pair| locals_key?(pair) }.compact.first
27
-
28
- if option_pairs.length == 1 && partial_key
29
- add_offense(node, location: :expression, message: "Use `render #{partial_key.source}` instead")
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")
32
- end
24
+ return unless (option_pairs = render_with_options?(node))
25
+
26
+ partial_key = option_pairs.map { |pair| partial_key?(pair) }.compact.first
27
+ locals_key = option_pairs.map { |pair| locals_key?(pair) }.compact.first
28
+
29
+ if option_pairs.length == 1 && partial_key
30
+ add_offense(node, location: :expression, message: "Use `render #{partial_key.source}` instead")
31
+ elsif option_pairs.length == 2 && partial_key && locals_key
32
+ add_offense(node, location: :expression, message: "Use `render #{partial_key.source}, #{locals_key.source}` instead")
33
33
  end
34
34
  end
35
35
  end
@@ -0,0 +1 @@
1
+ # frozen_string_literal: true
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubocop-standard
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.1
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Garen Torikian
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-12-09 00:00:00.000000000 Z
11
+ date: 2019-12-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubocop
@@ -109,17 +109,18 @@ files:
109
109
  - guides/rails-controller-render-shorthand.md
110
110
  - guides/rails-render-inline.md
111
111
  - guides/rails-render-literal.md
112
- - lib/rubocop/cop/standard.rb
113
- - lib/rubocop/cop/standard/rails_application_record.rb
114
- - lib/rubocop/cop/standard/rails_controller_render_action_symbol.rb
115
- - lib/rubocop/cop/standard/rails_controller_render_literal.rb
116
- - lib/rubocop/cop/standard/rails_controller_render_paths_exist.rb
117
- - lib/rubocop/cop/standard/rails_controller_render_shorthand.rb
118
- - lib/rubocop/cop/standard/rails_render_inline.rb
119
- - lib/rubocop/cop/standard/rails_render_object_collection.rb
120
- - lib/rubocop/cop/standard/rails_view_render_literal.rb
121
- - lib/rubocop/cop/standard/rails_view_render_paths_exist.rb
122
- - lib/rubocop/cop/standard/rails_view_render_shorthand.rb
112
+ - lib/rubocop/cop/standard/rails/rails.rb
113
+ - lib/rubocop/cop/standard/rails/rails_application_record.rb
114
+ - lib/rubocop/cop/standard/rails/rails_controller_render_action_symbol.rb
115
+ - lib/rubocop/cop/standard/rails/rails_controller_render_literal.rb
116
+ - lib/rubocop/cop/standard/rails/rails_controller_render_paths_exist.rb
117
+ - lib/rubocop/cop/standard/rails/rails_controller_render_shorthand.rb
118
+ - lib/rubocop/cop/standard/rails/rails_render_inline.rb
119
+ - lib/rubocop/cop/standard/rails/rails_render_object_collection.rb
120
+ - lib/rubocop/cop/standard/rails/rails_view_render_literal.rb
121
+ - lib/rubocop/cop/standard/rails/rails_view_render_paths_exist.rb
122
+ - lib/rubocop/cop/standard/rails/rails_view_render_shorthand.rb
123
+ - lib/rubocop/cop/standard/standard.rb
123
124
  homepage: https://github.com/gjtorikian/rubocop-standard
124
125
  licenses:
125
126
  - MIT
@@ -1,12 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'rubocop/cop/standard/rails_application_record'
4
- require 'rubocop/cop/standard/rails_controller_render_action_symbol'
5
- require 'rubocop/cop/standard/rails_controller_render_literal'
6
- require 'rubocop/cop/standard/rails_controller_render_paths_exist'
7
- require 'rubocop/cop/standard/rails_controller_render_shorthand'
8
- require 'rubocop/cop/standard/rails_render_inline'
9
- require 'rubocop/cop/standard/rails_render_object_collection'
10
- require 'rubocop/cop/standard/rails_view_render_literal'
11
- require 'rubocop/cop/standard/rails_view_render_paths_exist'
12
- require 'rubocop/cop/standard/rails_view_render_shorthand'
@@ -1,45 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'rubocop'
4
-
5
- module RuboCop
6
- module Cop
7
- module Standard
8
- class RailsRenderObjectCollection < Cop
9
- MSG = 'Avoid `render object:`'
10
-
11
- def_node_matcher :render_with_options?, <<-PATTERN
12
- (send nil? :render (hash $...) ...)
13
- PATTERN
14
-
15
- def_node_matcher :partial_key?, <<-PATTERN
16
- (pair (sym :partial) $_)
17
- PATTERN
18
-
19
- def_node_matcher :object_key?, <<-PATTERN
20
- (pair (sym ${:object :collection :spacer_template}) $_)
21
- PATTERN
22
-
23
- def on_send(node)
24
- if option_pairs = render_with_options?(node)
25
- partial_pair = option_pairs.detect { |pair| partial_key?(pair) }
26
- object_pair = option_pairs.detect { |pair| object_key?(pair) }
27
-
28
- if partial_pair && object_pair
29
- partial_name = partial_key?(partial_pair)
30
- object_sym, object_node = object_key?(object_pair)
31
-
32
- case object_sym
33
- when :object
34
- suggestion = ", instead `render partial: #{partial_name.source}, locals: { #{File.basename(partial_name.children[0], '.html.erb')}: #{object_node.source} }`" if partial_name.children[0].is_a?(String)
35
- add_offense(node, location: :expression, message: "Avoid `render object:`#{suggestion}")
36
- when :collection, :spacer_template
37
- add_offense(node, location: :expression, message: 'Avoid `render collection:`')
38
- end
39
- end
40
- end
41
- end
42
- end
43
- end
44
- end
45
- end