rubocop-discourse 3.12.1 → 3.13.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
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 01e08f365da90a2bd0cbf1cff4caf796a8ea368a169d8db4bc647df66d689397
|
4
|
+
data.tar.gz: 99a8598e0ad4fe8564f6cbcc106476ca3baace52d16390b81f4cd8b047f3b37d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 795176837d6a53075c5b357673e9198503390772b3a2da8197a713a8c58538c15d5699685343286ae711f9435092092efd49ec348f01ae220b8b91fda98482a9
|
7
|
+
data.tar.gz: d8841c96033254114c4bb52e2d03973274dfbf3f1e88a058e934ff85fe54886f8b20edd00c9662606326d7a4cfbfad0b234f7d8b6f3e3b934679c567b833f291
|
@@ -15,8 +15,18 @@ module RuboCop
|
|
15
15
|
# # good
|
16
16
|
# fab!(:user)
|
17
17
|
#
|
18
|
-
# When
|
19
|
-
#
|
18
|
+
# When the variable name doesn't match the fabricator name but no custom
|
19
|
+
# attributes are used, we can use a more explicit syntax.
|
20
|
+
#
|
21
|
+
# @example
|
22
|
+
#
|
23
|
+
# # bad
|
24
|
+
# fab!(:other_user) { Fabricate(:user) }
|
25
|
+
#
|
26
|
+
# # good
|
27
|
+
# fab!(:other_user, :user)
|
28
|
+
#
|
29
|
+
# When using custom attributes, the block form must be used.
|
20
30
|
#
|
21
31
|
# @example
|
22
32
|
#
|
@@ -24,12 +34,12 @@ module RuboCop
|
|
24
34
|
# fab!(:user) { Fabricate(:user, trust_level: TrustLevel[0]) }
|
25
35
|
#
|
26
36
|
# # good
|
27
|
-
# fab!(:
|
37
|
+
# fab!(:other_user) { Fabricate(:user, trust_level: TrustLevel[0]) }
|
28
38
|
class FabricatorShorthand < Base
|
29
39
|
extend AutoCorrector
|
30
40
|
include IgnoredNode
|
31
41
|
|
32
|
-
def_node_matcher :
|
42
|
+
def_node_matcher :same_name_fabricator?, <<-MATCHER
|
33
43
|
(block
|
34
44
|
$(send nil? :fab!
|
35
45
|
(sym $_identifier))
|
@@ -38,14 +48,35 @@ module RuboCop
|
|
38
48
|
(sym $_identifier)))
|
39
49
|
MATCHER
|
40
50
|
|
51
|
+
def_node_matcher :different_name_fabricator?, <<-MATCHER
|
52
|
+
(block
|
53
|
+
$(send nil? :fab!
|
54
|
+
(sym $_variable_name))
|
55
|
+
(args)
|
56
|
+
(send nil? :Fabricate
|
57
|
+
(sym $_fabricator_name)))
|
58
|
+
MATCHER
|
59
|
+
|
41
60
|
def on_block(node)
|
42
|
-
|
61
|
+
same_name_fabricator?(node) do |expression, _identifier|
|
62
|
+
add_offense(node, message: message_for_matching(expression.source)) do |corrector|
|
63
|
+
next if part_of_ignored_node?(node)
|
64
|
+
corrector.replace(node, expression.source)
|
65
|
+
end
|
66
|
+
ignore_node(node)
|
67
|
+
return
|
68
|
+
end
|
69
|
+
|
70
|
+
different_name_fabricator?(node) do |expression, variable_name, fabricator_name|
|
71
|
+
# Only apply when names don't match but there are no extra arguments
|
72
|
+
next if variable_name == fabricator_name || has_extra_arguments?(node)
|
73
|
+
|
43
74
|
add_offense(
|
44
75
|
node,
|
45
|
-
message:
|
76
|
+
message: message_for_different_names(variable_name, fabricator_name),
|
46
77
|
) do |corrector|
|
47
78
|
next if part_of_ignored_node?(node)
|
48
|
-
corrector.replace(node,
|
79
|
+
corrector.replace(node, "fab!(:#{variable_name}, :#{fabricator_name})")
|
49
80
|
end
|
50
81
|
ignore_node(node)
|
51
82
|
end
|
@@ -53,9 +84,19 @@ module RuboCop
|
|
53
84
|
|
54
85
|
private
|
55
86
|
|
56
|
-
def
|
87
|
+
def has_extra_arguments?(node)
|
88
|
+
fabricate_node = node.children.last
|
89
|
+
# Check if Fabricate has more than one argument
|
90
|
+
fabricate_node.arguments.size > 1
|
91
|
+
end
|
92
|
+
|
93
|
+
def message_for_matching(expression)
|
57
94
|
"Use the fabricator shorthand: `#{expression}`"
|
58
95
|
end
|
96
|
+
|
97
|
+
def message_for_different_names(variable_name, fabricator_name)
|
98
|
+
"Use the fabricator shorthand: `fab!(:#{variable_name}, :#{fabricator_name})`"
|
99
|
+
end
|
59
100
|
end
|
60
101
|
end
|
61
102
|
end
|
data/rubocop-rails.yml
CHANGED
@@ -12,3 +12,94 @@ Rails/EnumUniqueness:
|
|
12
12
|
|
13
13
|
Rails/ReversibleMigrationMethodDefinition:
|
14
14
|
Enabled: true
|
15
|
+
|
16
|
+
Rails/ActiveSupportAliases:
|
17
|
+
Enabled: true
|
18
|
+
|
19
|
+
Rails/AddColumnIndex:
|
20
|
+
Enabled: true
|
21
|
+
AutoCorrect: false
|
22
|
+
|
23
|
+
Rails/AttributeDefaultBlockValue:
|
24
|
+
Enabled: true
|
25
|
+
|
26
|
+
Rails/DurationArithmetic:
|
27
|
+
Enabled: true
|
28
|
+
|
29
|
+
Rails/EnvLocal:
|
30
|
+
Enabled: true
|
31
|
+
|
32
|
+
Rails/EnvironmentComparison:
|
33
|
+
Enabled: true
|
34
|
+
|
35
|
+
Rails/ExpandedDateRange:
|
36
|
+
Enabled: true
|
37
|
+
|
38
|
+
Rails/FindBy:
|
39
|
+
Enabled: true
|
40
|
+
|
41
|
+
Rails/FindById:
|
42
|
+
Enabled: true
|
43
|
+
|
44
|
+
Rails/HttpStatus:
|
45
|
+
Enabled: true
|
46
|
+
|
47
|
+
Rails/IndexBy:
|
48
|
+
Enabled: true
|
49
|
+
|
50
|
+
Rails/MatchRoute:
|
51
|
+
Enabled: true
|
52
|
+
|
53
|
+
Rails/PluralizationGrammar:
|
54
|
+
Enabled: true
|
55
|
+
|
56
|
+
Rails/Presence:
|
57
|
+
Enabled: true
|
58
|
+
|
59
|
+
Rails/Present:
|
60
|
+
Enabled: true
|
61
|
+
Exclude:
|
62
|
+
- "bin/*"
|
63
|
+
|
64
|
+
Rails/ReadWriteAttribute:
|
65
|
+
Enabled: true
|
66
|
+
|
67
|
+
Rails/RedundantAllowNil:
|
68
|
+
Enabled: true
|
69
|
+
|
70
|
+
Rails/RedundantReceiverInWithOptions:
|
71
|
+
Enabled: true
|
72
|
+
|
73
|
+
Rails/RenderPlainText:
|
74
|
+
Enabled: true
|
75
|
+
|
76
|
+
Rails/RootPublicPath:
|
77
|
+
Enabled: true
|
78
|
+
|
79
|
+
Rails/ScopeArgs:
|
80
|
+
Enabled: true
|
81
|
+
|
82
|
+
Rails/StripHeredoc:
|
83
|
+
Enabled: true
|
84
|
+
|
85
|
+
Rails/ToFormattedS:
|
86
|
+
Enabled: true
|
87
|
+
EnforcedStyle: to_formatted_s
|
88
|
+
|
89
|
+
Rails/TopLevelHashWithIndifferentAccess:
|
90
|
+
Enabled: true
|
91
|
+
|
92
|
+
Rails/Validation:
|
93
|
+
Enabled: true
|
94
|
+
|
95
|
+
Rails/UnusedRenderContent:
|
96
|
+
Enabled: true
|
97
|
+
|
98
|
+
Rails/WhereMissing:
|
99
|
+
Enabled: true
|
100
|
+
|
101
|
+
Rails/WhereNot:
|
102
|
+
Enabled: true
|
103
|
+
|
104
|
+
Rails/ActiveRecordCallbacksOrder:
|
105
|
+
Enabled: true
|
@@ -22,15 +22,24 @@ RSpec.describe RuboCop::Cop::Discourse::FabricatorShorthand, :config do
|
|
22
22
|
RUBY
|
23
23
|
end
|
24
24
|
|
25
|
-
it "
|
26
|
-
|
25
|
+
it "registers an offense when the identifier doesn't match and can be simplified" do
|
26
|
+
expect_offense(<<~RUBY)
|
27
27
|
RSpec.describe "Foo" do
|
28
28
|
fab!(:bar) { Fabricate(:foo) }
|
29
|
+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Discourse/FabricatorShorthand: Use the fabricator shorthand: `fab!(:bar, :foo)`
|
30
|
+
end
|
31
|
+
RUBY
|
32
|
+
end
|
33
|
+
|
34
|
+
it "does not register an offense when the identifier doesn't match and the fabricator has attributes" do
|
35
|
+
expect_no_offenses(<<~RUBY)
|
36
|
+
RSpec.describe "Foo" do
|
37
|
+
fab!(:bar) { Fabricate(:foo, bar: 1) }
|
29
38
|
end
|
30
39
|
RUBY
|
31
40
|
end
|
32
41
|
|
33
|
-
it "supports autocorrect" do
|
42
|
+
it "supports autocorrect when the name and fabricator matches" do
|
34
43
|
expect_offense(<<~RUBY)
|
35
44
|
RSpec.describe "Foo" do
|
36
45
|
fab!(:foo) { Fabricate(:foo) }
|
@@ -44,4 +53,19 @@ RSpec.describe RuboCop::Cop::Discourse::FabricatorShorthand, :config do
|
|
44
53
|
end
|
45
54
|
RUBY
|
46
55
|
end
|
56
|
+
|
57
|
+
it "supports autocorrect when the name and fabricator don't match" do
|
58
|
+
expect_offense(<<~RUBY)
|
59
|
+
RSpec.describe "Foo" do
|
60
|
+
fab!(:bar) { Fabricate(:foo) }
|
61
|
+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Discourse/FabricatorShorthand: Use the fabricator shorthand: `fab!(:bar, :foo)`
|
62
|
+
end
|
63
|
+
RUBY
|
64
|
+
|
65
|
+
expect_correction(<<~RUBY)
|
66
|
+
RSpec.describe "Foo" do
|
67
|
+
fab!(:bar, :foo)
|
68
|
+
end
|
69
|
+
RUBY
|
70
|
+
end
|
47
71
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubocop-discourse
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.13.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Discourse Team
|
8
8
|
bindir: bin
|
9
9
|
cert_chain: []
|
10
|
-
date:
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: activesupport
|
@@ -239,7 +239,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
239
239
|
- !ruby/object:Gem::Version
|
240
240
|
version: '0'
|
241
241
|
requirements: []
|
242
|
-
rubygems_version: 3.6.
|
242
|
+
rubygems_version: 3.6.9
|
243
243
|
specification_version: 4
|
244
244
|
summary: Custom rubocop cops used by Discourse
|
245
245
|
test_files: []
|