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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3d347009b4a77b64450a20ef3afc5ca102dd361c60e3fbde2e5fd0ea976469cd
4
- data.tar.gz: c98b24bd73f783f154320e337e44f6859e050c43ff9219cfa0be6f63a891fc13
3
+ metadata.gz: e5b75497583add89cff544cd40ac534768c6694e53ff350469e6a4a83bf5e285
4
+ data.tar.gz: 840195a9bbe85b1fc5d83c3d87af5b137418fe037e1890997de40bb3a1b61692
5
5
  SHA512:
6
- metadata.gz: 98c56b4b42703f8fc1fe0b3f68344507e2001d7a71d5530c89b8f21a29b5276fc518542b445e9dd9a902cb30be38ce0d4df18218b2cf08bfb50465411d7c7d77
7
- data.tar.gz: f7f5f50325374fe530a26c20ed113b4cb827ed7541a8a9f6dbae1a81c0dca29be2cc7073c8f543b5200dab2e2238617984a7f4dbd87d838ff8a1d4cfa8da0db6
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 |identifier|
40
- add_offense(node, message: message(identifier))
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(identifier)
47
- "Use the fabricator shorthand: `fab!(:#{identifier})`"
56
+ def message(expression)
57
+ "Use the fabricator shorthand: `#{expression}`"
48
58
  end
49
59
  end
50
60
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "rubocop-discourse"
5
- s.version = "3.7.0"
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
@@ -0,0 +1,11 @@
1
+ require:
2
+ - rubocop-rails
3
+
4
+ Rails:
5
+ Enabled: false
6
+
7
+ Rails/EnumHash:
8
+ Enabled: true
9
+
10
+ Rails/EnumUniqueness:
11
+ Enabled: true
data/rubocop-rspec.yml CHANGED
@@ -226,5 +226,5 @@ RSpec/Yield:
226
226
  RSpec/Capybara/FeatureMethods:
227
227
  Enabled: true
228
228
 
229
- RSpec/Rails/HttpStatus:
229
+ RSpecRails/HttpStatus:
230
230
  Enabled: true
@@ -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
@@ -6,6 +6,7 @@ inherit_from:
6
6
  - ./rubocop-capybara.yml
7
7
  - ./rubocop-factory_bot.yml
8
8
  - ./rubocop-rspec.yml
9
+ - ./rubocop-rails.yml
9
10
 
10
11
  AllCops:
11
12
  TargetRubyVersion: 3.2
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.7.0
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-02-28 00:00:00.000000000 Z
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