rubocop-discourse 3.7.0 → 3.7.1

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: eb795aa24e9b2d88571ef2140d2dce87afd493b20c5d1d643b8a58b3d7b97fd5
4
+ data.tar.gz: 7950d13ba0da8dbeb2a690f48f33f1df8e72dbfd00240f4da07172dfbe3f91c6
5
5
  SHA512:
6
- metadata.gz: 98c56b4b42703f8fc1fe0b3f68344507e2001d7a71d5530c89b8f21a29b5276fc518542b445e9dd9a902cb30be38ce0d4df18218b2cf08bfb50465411d7c7d77
7
- data.tar.gz: f7f5f50325374fe530a26c20ed113b4cb827ed7541a8a9f6dbae1a81c0dca29be2cc7073c8f543b5200dab2e2238617984a7f4dbd87d838ff8a1d4cfa8da0db6
6
+ metadata.gz: f47590c8de489ac68e8ca6d4d5ec012a5cf07455ad63c123aa14963c6ef6dec3d9f934a5106b45f01fbdca5b34e70542ac77fe9e0b46d9bb828b06d21a934d41
7
+ data.tar.gz: be49ff2f39df90a0dec57f813b621570b7fe895656ac7b65f54e4938490bc6714fdbc9fb0b9b92fe19b82fa26fe1997ceae6c3cf2734eb637714e9880569ba97
@@ -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.7.1"
6
6
  s.summary = "Custom rubocop cops used by Discourse"
7
7
  s.authors = ["Discourse Team"]
8
8
  s.license = "MIT"
@@ -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
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.7.1
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-02-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport