rubocop-standard 1.15.1 → 2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +2 -4
- data/config/default.yml +3 -8
- data/config/rails.yml +51 -46
- data/lib/rubocop/cop/standard/rails_application_record.rb +2 -4
- data/lib/rubocop/cop/standard/rails_controller_render_literal.rb +13 -11
- data/lib/rubocop/cop/standard/rails_controller_render_paths_exist.rb +3 -9
- data/lib/rubocop/cop/standard/rails_controller_render_shorthand.rb +10 -10
- data/lib/rubocop/cop/standard/rails_render_inline.rb +1 -3
- data/lib/rubocop/cop/standard/rails_render_object_collection.rb +1 -3
- data/lib/rubocop/cop/standard/rails_view_render_literal.rb +12 -8
- data/lib/rubocop/cop/standard/rails_view_render_paths_exist.rb +2 -6
- metadata +19 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4ff86603c5200d0aaf96d6141ee15b32b84484a970b6fda00b6509689d837c59
|
4
|
+
data.tar.gz: 42c8bf7bf7f5c126bd6f307c4562c05cad20f38c6034b6a0a600e3d899c9dcd6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7583c6adb7b95deed066c99466b574143635da619506f283ba7071189977692f3386fcc36aa625b0314c832ea2e979d2a7814ff24bd1479cb49bfccb2df92119
|
7
|
+
data.tar.gz: b97e83353026c7fb74f4c99a85706012d608dbdff507741bf7b786b635241a3816caf906dad13e6c16e270ae2cdc571033e0cdc71e50de99fd05b22c198410f0
|
data/README.md
CHANGED
data/config/default.yml
CHANGED
@@ -1,9 +1,4 @@
|
|
1
|
-
require:
|
2
|
-
- rubocop/cop/standard
|
3
|
-
- rubocop-performance
|
4
|
-
|
5
|
-
AllCops:
|
6
|
-
DisabledByDefault: true
|
1
|
+
require: rubocop/cop/standard
|
7
2
|
|
8
3
|
Bundler/DuplicatedGem:
|
9
4
|
Enabled: true
|
@@ -153,10 +148,10 @@ Lint/StringConversionInInterpolation:
|
|
153
148
|
Lint/UnderscorePrefixedVariableName:
|
154
149
|
Enabled: true
|
155
150
|
|
156
|
-
Lint/
|
151
|
+
Lint/RedundantCopDisableDirective:
|
157
152
|
Enabled: true
|
158
153
|
|
159
|
-
Lint/
|
154
|
+
Lint/RedundantSplatExpansion:
|
160
155
|
Enabled: true
|
161
156
|
|
162
157
|
Lint/UnreachableCode:
|
data/config/rails.yml
CHANGED
@@ -1,8 +1,5 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
Rails/FindEach:
|
5
|
-
Enabled: false
|
1
|
+
require:
|
2
|
+
- rubocop-rails
|
6
3
|
|
7
4
|
Rails/OutputSafety:
|
8
5
|
Enabled: true
|
@@ -20,99 +17,107 @@ Rails/ScopeArgs:
|
|
20
17
|
Rails/UniqBeforePluck:
|
21
18
|
Enabled: true
|
22
19
|
|
23
|
-
|
20
|
+
GitHub/RailsApplicationRecord:
|
24
21
|
Enabled: true
|
25
22
|
|
26
|
-
|
23
|
+
GitHub/RailsControllerRenderActionSymbol:
|
27
24
|
Enabled: true
|
28
25
|
Include:
|
29
|
-
-
|
26
|
+
- "app/controllers/**/*.rb"
|
30
27
|
|
31
|
-
|
28
|
+
GitHub/RailsControllerRenderLiteral:
|
32
29
|
Enabled: true
|
33
|
-
StyleGuide: https://github.com/
|
30
|
+
StyleGuide: https://github.com/github/rubocop-github/blob/master/guides/rails-render-literal.md
|
34
31
|
Include:
|
35
|
-
-
|
32
|
+
- "app/controllers/**/*.rb"
|
36
33
|
|
37
|
-
|
34
|
+
GitHub/RailsControllerRenderPathsExist:
|
38
35
|
Enabled: true
|
39
36
|
ViewPath:
|
40
|
-
-
|
37
|
+
- "app/views"
|
41
38
|
Include:
|
42
|
-
-
|
39
|
+
- "app/controllers/**/*.rb"
|
43
40
|
|
44
|
-
|
41
|
+
GitHub/RailsControllerRenderShorthand:
|
45
42
|
Enabled: true
|
46
|
-
StyleGuide: https://github.com/
|
43
|
+
StyleGuide: https://github.com/github/rubocop-github/blob/master/guides/rails-controller-render-shorthand.md
|
47
44
|
Include:
|
48
|
-
-
|
45
|
+
- "app/controllers/**/*.rb"
|
49
46
|
|
50
|
-
|
47
|
+
GitHub/RailsRenderInline:
|
51
48
|
Enabled: true
|
52
|
-
StyleGuide: https://github.com/
|
49
|
+
StyleGuide: https://github.com/github/rubocop-github/blob/master/guides/rails-controller-render-inline.md
|
53
50
|
Include:
|
54
|
-
-
|
55
|
-
-
|
56
|
-
-
|
57
|
-
-
|
51
|
+
- "app/controllers/**/*.rb"
|
52
|
+
- "app/helpers/**/*.rb"
|
53
|
+
- "app/view_models/**/*.rb"
|
54
|
+
- "app/views/**/*.erb"
|
58
55
|
|
59
|
-
|
56
|
+
GitHub/RailsRenderObjectCollection:
|
60
57
|
Enabled: false
|
61
58
|
|
62
|
-
|
59
|
+
GitHub/RailsViewRenderLiteral:
|
63
60
|
Enabled: true
|
64
|
-
StyleGuide: https://github.com/
|
61
|
+
StyleGuide: https://github.com/github/rubocop-github/blob/master/guides/rails-render-literal.md
|
65
62
|
Include:
|
66
|
-
-
|
67
|
-
-
|
68
|
-
-
|
63
|
+
- "app/helpers/**/*.rb"
|
64
|
+
- "app/view_models/**/*.rb"
|
65
|
+
- "app/views/**/*.erb"
|
69
66
|
|
70
|
-
|
67
|
+
GitHub/RailsViewRenderPathsExist:
|
71
68
|
Enabled: true
|
72
69
|
ViewPath:
|
73
|
-
-
|
70
|
+
- "app/views"
|
74
71
|
Include:
|
75
|
-
-
|
76
|
-
-
|
77
|
-
-
|
72
|
+
- "app/helpers/**/*.rb"
|
73
|
+
- "app/view_models/**/*.rb"
|
74
|
+
- "app/views/**/*.erb"
|
78
75
|
|
79
|
-
|
76
|
+
GitHub/RailsViewRenderShorthand:
|
80
77
|
Enabled: true
|
81
78
|
Include:
|
82
|
-
-
|
83
|
-
-
|
84
|
-
-
|
79
|
+
- "app/helpers/**/*.rb"
|
80
|
+
- "app/view_models/**/*.rb"
|
81
|
+
- "app/views/**/*.erb"
|
85
82
|
|
86
83
|
# Exclude Rails ERB files from incompatible cops
|
87
84
|
|
88
85
|
Layout/BlockAlignment:
|
89
86
|
Exclude:
|
90
|
-
-
|
87
|
+
- "app/views/**/*.erb"
|
91
88
|
|
92
89
|
Style/For:
|
93
90
|
Exclude:
|
94
|
-
-
|
91
|
+
- "app/views/**/*.erb"
|
95
92
|
|
96
93
|
Style/OneLineConditional:
|
97
94
|
Exclude:
|
98
|
-
-
|
95
|
+
- "app/views/**/*.erb"
|
99
96
|
|
100
97
|
Style/Semicolon:
|
101
98
|
Exclude:
|
102
|
-
-
|
99
|
+
- "app/views/**/*.erb"
|
103
100
|
|
104
101
|
Layout/SpaceInsideParens:
|
105
102
|
Exclude:
|
106
|
-
-
|
103
|
+
- "app/views/**/*.erb"
|
107
104
|
|
108
105
|
Style/StringLiterals:
|
109
106
|
Exclude:
|
110
|
-
-
|
107
|
+
- "app/views/**/*.erb"
|
111
108
|
|
112
109
|
Layout/TrailingBlankLines:
|
113
110
|
Exclude:
|
114
|
-
-
|
111
|
+
- "app/views/**/*.erb"
|
115
112
|
|
116
113
|
Layout/TrailingWhitespace:
|
117
114
|
Exclude:
|
118
|
-
-
|
115
|
+
- "app/views/**/*.erb"
|
116
|
+
|
117
|
+
Layout/InitialIndentation:
|
118
|
+
Exclude:
|
119
|
+
- "app/views/**/*.erb"
|
120
|
+
|
121
|
+
Lint/UselessAccessModifier:
|
122
|
+
ContextCreatingMethods:
|
123
|
+
- concerning
|
@@ -17,11 +17,9 @@ module RuboCop
|
|
17
17
|
PATTERN
|
18
18
|
|
19
19
|
def on_class(node)
|
20
|
-
klass, superclass,
|
20
|
+
klass, superclass, = *node
|
21
21
|
|
22
|
-
if active_record_base_const?(superclass) && !
|
23
|
-
add_offense(superclass, location: :expression)
|
24
|
-
end
|
22
|
+
add_offense(superclass, location: :expression) if active_record_base_const?(superclass) && !application_record_const?(klass)
|
25
23
|
end
|
26
24
|
end
|
27
25
|
end
|
@@ -6,7 +6,7 @@ module RuboCop
|
|
6
6
|
module Cop
|
7
7
|
module Standard
|
8
8
|
class RailsControllerRenderLiteral < Cop
|
9
|
-
MSG = 'render must be used with a string literal'
|
9
|
+
MSG = 'render must be used with a string literal or an instance of a Class'
|
10
10
|
|
11
11
|
def_node_matcher :literal?, <<-PATTERN
|
12
12
|
({str sym true false nil?} ...)
|
@@ -20,6 +20,14 @@ module RuboCop
|
|
20
20
|
(send nil? :render ({str sym} $_) $...)
|
21
21
|
PATTERN
|
22
22
|
|
23
|
+
def_node_matcher :render_const?, <<-PATTERN
|
24
|
+
(send nil? :render (const _ _) ...)
|
25
|
+
PATTERN
|
26
|
+
|
27
|
+
def_node_matcher :render_inst?, <<-PATTERN
|
28
|
+
(send nil? :render (send _ :new ...) ...)
|
29
|
+
PATTERN
|
30
|
+
|
23
31
|
def_node_matcher :render_with_options?, <<-PATTERN
|
24
32
|
(send nil? :render (hash $...))
|
25
33
|
PATTERN
|
@@ -63,26 +71,20 @@ module RuboCop
|
|
63
71
|
def on_send(node)
|
64
72
|
return unless render?(node)
|
65
73
|
|
66
|
-
if render_literal?(node)
|
74
|
+
if render_literal?(node) || render_inst?(node) || render_const?(node)
|
67
75
|
elsif option_pairs = render_with_options?(node)
|
68
76
|
option_pairs = option_pairs.reject { |pair| options_key?(pair) }
|
69
77
|
|
70
|
-
if option_pairs.any? { |pair| ignore_key?(pair) }
|
71
|
-
return
|
72
|
-
end
|
78
|
+
return if option_pairs.any? { |pair| ignore_key?(pair) }
|
73
79
|
|
74
80
|
if template_node = option_pairs.map { |pair| template_key?(pair) }.compact.first
|
75
|
-
|
76
|
-
add_offense(node, location: :expression)
|
77
|
-
end
|
81
|
+
add_offense(node, location: :expression) unless literal?(template_node)
|
78
82
|
else
|
79
83
|
add_offense(node, location: :expression)
|
80
84
|
end
|
81
85
|
|
82
86
|
if layout_node = option_pairs.map { |pair| layout_key?(pair) }.compact.first
|
83
|
-
|
84
|
-
add_offense(node, location: :expression)
|
85
|
-
end
|
87
|
+
add_offense(node, location: :expression) unless literal?(layout_node)
|
86
88
|
end
|
87
89
|
else
|
88
90
|
add_offense(node, location: :expression)
|
@@ -27,22 +27,16 @@ module RuboCop
|
|
27
27
|
|
28
28
|
if args = render_str?(node)
|
29
29
|
node, path = args
|
30
|
-
unless resolve_template(path.to_s)
|
31
|
-
add_offense(node, location: :expression, message: 'Template could not be found')
|
32
|
-
end
|
30
|
+
add_offense(node, location: :expression, message: 'Template could not be found') unless resolve_template(path.to_s)
|
33
31
|
elsif pairs = render_options?(node)
|
34
32
|
if pair = pairs.detect { |p| render_key?(p) }
|
35
33
|
key, node, path = render_key?(pair)
|
36
34
|
|
37
35
|
case key
|
38
36
|
when :action, :template
|
39
|
-
unless resolve_template(path.to_s)
|
40
|
-
add_offense(node, location: :expression, message: 'Template could not be found')
|
41
|
-
end
|
37
|
+
add_offense(node, location: :expression, message: 'Template could not be found') unless resolve_template(path.to_s)
|
42
38
|
when :partial
|
43
|
-
unless resolve_partial(path.to_s)
|
44
|
-
add_offense(node, location: :expression, message: 'Partial template could not be found')
|
45
|
-
end
|
39
|
+
add_offense(node, location: :expression, message: 'Partial template could not be found') unless resolve_partial(path.to_s)
|
46
40
|
end
|
47
41
|
end
|
48
42
|
end
|
@@ -31,17 +31,17 @@ module RuboCop
|
|
31
31
|
def on_send(node)
|
32
32
|
if option_pairs = render_with_options?(node)
|
33
33
|
option_pairs.each do |pair|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
add_offense(node, location: :expression, message: "Use `#{corrected_source}` instead")
|
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)
|
44
43
|
end
|
44
|
+
add_offense(node, location: :expression, message: "Use `#{corrected_source}` instead")
|
45
45
|
end
|
46
46
|
end
|
47
47
|
end
|
@@ -18,9 +18,7 @@ module RuboCop
|
|
18
18
|
|
19
19
|
def on_send(node)
|
20
20
|
if option_pairs = render_with_options?(node)
|
21
|
-
if option_pairs.detect { |pair| inline_key?(pair) }
|
22
|
-
add_offense(node, location: :expression)
|
23
|
-
end
|
21
|
+
add_offense(node, location: :expression) if option_pairs.detect { |pair| inline_key?(pair) }
|
24
22
|
end
|
25
23
|
end
|
26
24
|
end
|
@@ -31,9 +31,7 @@ module RuboCop
|
|
31
31
|
|
32
32
|
case object_sym
|
33
33
|
when :object
|
34
|
-
if partial_name.children[0].is_a?(String)
|
35
|
-
suggestion = ", instead `render partial: #{partial_name.source}, locals: { #{File.basename(partial_name.children[0], '.html.erb')}: #{object_node.source} }`"
|
36
|
-
end
|
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)
|
37
35
|
add_offense(node, location: :expression, message: "Avoid `render object:`#{suggestion}")
|
38
36
|
when :collection, :spacer_template
|
39
37
|
add_offense(node, location: :expression, message: 'Avoid `render collection:`')
|
@@ -6,7 +6,7 @@ module RuboCop
|
|
6
6
|
module Cop
|
7
7
|
module Standard
|
8
8
|
class RailsViewRenderLiteral < Cop
|
9
|
-
MSG = 'render must be used with a string literal'
|
9
|
+
MSG = 'render must be used with a string literal or an instance of a Class'
|
10
10
|
|
11
11
|
def_node_matcher :literal?, <<-PATTERN
|
12
12
|
({str sym true false nil?} ...)
|
@@ -20,6 +20,14 @@ module RuboCop
|
|
20
20
|
(send nil? :render ({str sym} $_) $...)
|
21
21
|
PATTERN
|
22
22
|
|
23
|
+
def_node_matcher :render_inst?, <<-PATTERN
|
24
|
+
(send nil? :render (send _ :new ...) ...)
|
25
|
+
PATTERN
|
26
|
+
|
27
|
+
def_node_matcher :render_const?, <<-PATTERN
|
28
|
+
(send nil? :render (const _ _) ...)
|
29
|
+
PATTERN
|
30
|
+
|
23
31
|
def_node_matcher :render_with_options?, <<-PATTERN
|
24
32
|
(send nil? :render (hash $...) ...)
|
25
33
|
PATTERN
|
@@ -42,16 +50,12 @@ module RuboCop
|
|
42
50
|
def on_send(node)
|
43
51
|
return unless render?(node)
|
44
52
|
|
45
|
-
if render_literal?(node)
|
53
|
+
if render_literal?(node) || render_inst?(node) || render_const?(node)
|
46
54
|
elsif option_pairs = render_with_options?(node)
|
47
|
-
if option_pairs.any? { |pair| ignore_key?(pair) }
|
48
|
-
return
|
49
|
-
end
|
55
|
+
return if option_pairs.any? { |pair| ignore_key?(pair) }
|
50
56
|
|
51
57
|
if partial_node = option_pairs.map { |pair| partial_key?(pair) }.compact.first
|
52
|
-
|
53
|
-
add_offense(node, location: :expression)
|
54
|
-
end
|
58
|
+
add_offense(node, location: :expression) unless literal?(partial_node)
|
55
59
|
else
|
56
60
|
add_offense(node, location: :expression)
|
57
61
|
end
|
@@ -27,16 +27,12 @@ module RuboCop
|
|
27
27
|
|
28
28
|
if args = render_str?(node)
|
29
29
|
node, path = args
|
30
|
-
unless resolve_partial(path.to_s)
|
31
|
-
add_offense(node, location: :expression, message: 'Partial template could not be found')
|
32
|
-
end
|
30
|
+
add_offense(node, location: :expression, message: 'Partial template could not be found') unless resolve_partial(path.to_s)
|
33
31
|
elsif pairs = render_options?(node)
|
34
32
|
if pair = pairs.detect { |p| partial_key?(p) }
|
35
33
|
node, path = partial_key?(pair)
|
36
34
|
|
37
|
-
unless resolve_partial(path.to_s)
|
38
|
-
add_offense(node, location: :expression, message: 'Partial template could not be found')
|
39
|
-
end
|
35
|
+
add_offense(node, location: :expression, message: 'Partial template could not be found') unless resolve_partial(path.to_s)
|
40
36
|
end
|
41
37
|
end
|
42
38
|
end
|
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:
|
4
|
+
version: '2.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-
|
11
|
+
date: 2019-11-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rubocop
|
@@ -30,14 +30,28 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '1.
|
33
|
+
version: '1.5'
|
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.
|
40
|
+
version: '1.5'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rubocop-rails
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '2.3'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '2.3'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: actionview
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -125,8 +139,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
125
139
|
- !ruby/object:Gem::Version
|
126
140
|
version: '0'
|
127
141
|
requirements: []
|
128
|
-
|
129
|
-
rubygems_version: 2.7.6
|
142
|
+
rubygems_version: 3.0.6
|
130
143
|
signing_key:
|
131
144
|
specification_version: 4
|
132
145
|
summary: RuboCop Standard
|