rubocop-discourse 3.7.0 → 3.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rubocop/cop/discourse/fabricator_shorthand.rb +15 -5
- data/rubocop-discourse.gemspec +2 -1
- data/rubocop-rails.yml +11 -0
- data/rubocop-rspec.yml +1 -1
- data/spec/lib/rubocop/cop/fabricator_shorthand_spec.rb +15 -0
- data/stree-compat.yml +1 -0
- metadata +17 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e5b75497583add89cff544cd40ac534768c6694e53ff350469e6a4a83bf5e285
|
4
|
+
data.tar.gz: 840195a9bbe85b1fc5d83c3d87af5b137418fe037e1890997de40bb3a1b61692
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f082de2cc3cad1becdb56cceb6576d653337a93d3912012be3fbb2fe9b18dcfde6c8182051b3a71389f9c943f36122817e7f52bc5c409357c98d0d077796d4b5
|
7
|
+
data.tar.gz: c3eaf22eb291495aae7ee022585892e451361b30e59b59c176d37ffee91fa53e3c57d650189a543e591166a4759ff5c90c531e4a4779f3a1e765474576d8b82b
|
@@ -26,9 +26,12 @@ module RuboCop
|
|
26
26
|
# # good
|
27
27
|
# fab!(:another_user) { Fabricate(:user) }
|
28
28
|
class FabricatorShorthand < Base
|
29
|
+
extend AutoCorrector
|
30
|
+
include IgnoredNode
|
31
|
+
|
29
32
|
def_node_matcher :offending_fabricator?, <<-MATCHER
|
30
33
|
(block
|
31
|
-
(send nil? :fab!
|
34
|
+
$(send nil? :fab!
|
32
35
|
(sym $_identifier))
|
33
36
|
(args)
|
34
37
|
(send nil? :Fabricate
|
@@ -36,15 +39,22 @@ module RuboCop
|
|
36
39
|
MATCHER
|
37
40
|
|
38
41
|
def on_block(node)
|
39
|
-
offending_fabricator?(node) do |
|
40
|
-
add_offense(
|
42
|
+
offending_fabricator?(node) do |expression, _identifier|
|
43
|
+
add_offense(
|
44
|
+
node,
|
45
|
+
message: message(expression.source)
|
46
|
+
) do |corrector|
|
47
|
+
next if part_of_ignored_node?(node)
|
48
|
+
corrector.replace(node, expression.source)
|
49
|
+
end
|
50
|
+
ignore_node(node)
|
41
51
|
end
|
42
52
|
end
|
43
53
|
|
44
54
|
private
|
45
55
|
|
46
|
-
def message(
|
47
|
-
"Use the fabricator shorthand:
|
56
|
+
def message(expression)
|
57
|
+
"Use the fabricator shorthand: `#{expression}`"
|
48
58
|
end
|
49
59
|
end
|
50
60
|
end
|
data/rubocop-discourse.gemspec
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = "rubocop-discourse"
|
5
|
-
s.version = "3.
|
5
|
+
s.version = "3.8.0"
|
6
6
|
s.summary = "Custom rubocop cops used by Discourse"
|
7
7
|
s.authors = ["Discourse Team"]
|
8
8
|
s.license = "MIT"
|
@@ -16,6 +16,7 @@ Gem::Specification.new do |s|
|
|
16
16
|
s.add_runtime_dependency "rubocop-rspec", ">= 2.25.0"
|
17
17
|
s.add_runtime_dependency "rubocop-factory_bot", ">= 2.0.0"
|
18
18
|
s.add_runtime_dependency "rubocop-capybara", ">= 2.0.0"
|
19
|
+
s.add_runtime_dependency "rubocop-rails", ">= 2.25.0"
|
19
20
|
|
20
21
|
s.add_development_dependency "rake", "~> 13.1.0"
|
21
22
|
s.add_development_dependency "rspec", "~> 3.12.0"
|
data/rubocop-rails.yml
ADDED
data/rubocop-rspec.yml
CHANGED
@@ -31,4 +31,19 @@ describe RuboCop::Cop::Discourse::FabricatorShorthand, :config do
|
|
31
31
|
end
|
32
32
|
RUBY
|
33
33
|
end
|
34
|
+
|
35
|
+
it "supports autocorrect" do
|
36
|
+
expect_offense(<<~RUBY)
|
37
|
+
RSpec.describe "Foo" do
|
38
|
+
fab!(:foo) { Fabricate(:foo) }
|
39
|
+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Discourse/FabricatorShorthand: Use the fabricator shorthand: `fab!(:foo)`
|
40
|
+
end
|
41
|
+
RUBY
|
42
|
+
|
43
|
+
expect_correction(<<~RUBY)
|
44
|
+
RSpec.describe "Foo" do
|
45
|
+
fab!(:foo)
|
46
|
+
end
|
47
|
+
RUBY
|
48
|
+
end
|
34
49
|
end
|
data/stree-compat.yml
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubocop-discourse
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Discourse Team
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-05-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -80,6 +80,20 @@ dependencies:
|
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: 2.0.0
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rubocop-rails
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 2.25.0
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 2.25.0
|
83
97
|
- !ruby/object:Gem::Dependency
|
84
98
|
name: rake
|
85
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -151,6 +165,7 @@ files:
|
|
151
165
|
- rubocop-discourse.gemspec
|
152
166
|
- rubocop-factory_bot.yml
|
153
167
|
- rubocop-layout.yml
|
168
|
+
- rubocop-rails.yml
|
154
169
|
- rubocop-rspec.yml
|
155
170
|
- spec/fixtures/controllers/bad_controller.rb
|
156
171
|
- spec/fixtures/controllers/base_controller.rb
|