factory_sloth 1.3.1 → 1.4.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: 1ca25fc42535f24034b3a52ddb2b88d9e64dbd68b83e2febb7ddb31679daa118
4
- data.tar.gz: 92814709e951c1dc15040496ec1c5dea101f2bdcb8d58eb1298182a91a2df2f1
3
+ metadata.gz: c9c56ba87b89aec371bdf53b61c50c66a0f0c51b8ba75c4edc12245967face48
4
+ data.tar.gz: f1ead7cb06982fd34eedde94bc017dfb5612c744266d9e76fa014864fdaccc7c
5
5
  SHA512:
6
- metadata.gz: 188f7f29920ba9f868171c65c21e7e4611e8c8c9cf41eb229e3f1a17fb98c6c970a491051fac6b501b5544b4298cef22f42335e8306e93370225c9acedfe8182
7
- data.tar.gz: dbc6452a523efb648d0f2d71594d883c469194164b86a8f2f16ece21a171e8d82bd2a8260072e777b731b1001ad9f0eb0c5f51ce1610ebf3f8cc67b7d19e4471
6
+ metadata.gz: 1016ee245df8b06fb396f12806004c6ea63f88944b3286723623906dca43be42a5b39dae87db377f9616f35f6b5b3bea2d080eaa0818a14f429f110c388c9a4f
7
+ data.tar.gz: 96c402e4c4a287e69cb641ccf281365da5ea4f64f6d1092534483b9971d93fd0196bcb22c870516b3df5b88eaabe9097ae2a12758acc28f7616b2615e56935f6
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ### Added
4
+
5
+ ## [1.4.0] - 2024-10-04
6
+
7
+ - ignore underscore-prefixed assignments e.g. `_user = create(:user)`
8
+
3
9
  ## [1.3.1] - 2023-05-24
4
10
 
5
11
  ### Fixed
data/README.md CHANGED
@@ -27,6 +27,7 @@ Examples:
27
27
  Options:
28
28
  -f, --force Ignore ./.factory_sloth_done
29
29
  -l, --lint Dont fix, just list bad create calls
30
+ -u, --underscore Check underscore-prefixed variables
30
31
  -V, --verbose Verbose output, useful for debugging
31
32
  -v, --version Show gem version
32
33
  -h, --help Show this help
@@ -80,6 +81,16 @@ expect { User.delete_all }.to change { User.count }.from(1).to(0)
80
81
 
81
82
  If you have a good idea about how to detect such cases automatically, let me know :)
82
83
 
84
+ ### Underscore-prefixed variable names
85
+
86
+ Prefixing a variable name with an underscore is a common way of saying "I am creating this for side effects":
87
+
88
+ ```ruby
89
+ _user = create(:user)
90
+ ```
91
+
92
+ Therefore `factory_sloth` ignores such cases by default. Use the `-u` flag to check such cases as well.
93
+
83
94
  ## Development
84
95
 
85
96
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -36,6 +36,10 @@ module FactorySloth
36
36
  FactorySloth.lint = true
37
37
  end
38
38
 
39
+ opts.on('-u', '--underscore', 'Check underscore-prefixed variables') do
40
+ FactorySloth.check_underscore_vars = true
41
+ end
42
+
39
43
  opts.on('-V', '--verbose', 'Verbose output, useful for debugging') do
40
44
  FactorySloth.verbose = true
41
45
  end
@@ -17,19 +17,32 @@ class FactorySloth::CreateCallFinder < Ripper
17
17
 
18
18
  def store_call(obj)
19
19
  @calls << obj if obj.is_a?(FactorySloth::CreateCall) && !@disabled
20
+ obj
20
21
  end
21
22
 
22
23
  def on_ident(name, *)
23
- %w[create create_list create_pair].include?(name) &&
24
- FactorySloth::CreateCall.new(name: name, line: lineno, column: column)
24
+ return name unless %w[create create_list create_pair].include?(name)
25
+
26
+ FactorySloth::CreateCall.new(name: name, line: lineno, column: column)
27
+ end
28
+
29
+ def on_assign(left, right)
30
+ if left.to_s.match?(/\A_/) &&
31
+ !FactorySloth.check_underscore_vars &&
32
+ [right, Array(right).last].any? { |v| v.is_a?(FactorySloth::CreateCall) }
33
+ @calls.pop
34
+ end
35
+ [left, right]
25
36
  end
26
37
 
27
- def on_call(mod, _, obj, *)
28
- store_call(obj) if mod == 'FactoryBot'
38
+ def on_call(mod, op, method, *args)
39
+ store_call(method) if mod == 'FactoryBot'
40
+ [mod, op, method, *args]
29
41
  end
30
42
 
31
- def on_command_call(mod, _, obj, *)
32
- store_call(obj) if mod == 'FactoryBot'
43
+ def on_command_call(mod, op, method, *args)
44
+ store_call(method) if mod == 'FactoryBot'
45
+ [mod, op, method, *args]
33
46
  end
34
47
 
35
48
  def on_comment(text, *)
@@ -1,3 +1,3 @@
1
1
  module FactorySloth
2
- VERSION = '1.3.1'
2
+ VERSION = '1.4.0'
3
3
  end
data/lib/factory_sloth.rb CHANGED
@@ -1,5 +1,11 @@
1
1
  module FactorySloth
2
- singleton_class.attr_accessor :dry_run, :force, :lint, :verbose
2
+ singleton_class.attr_accessor(*%i[
3
+ check_underscore_vars
4
+ dry_run
5
+ force
6
+ lint
7
+ verbose
8
+ ])
3
9
  end
4
10
 
5
11
  require_relative 'factory_sloth/cli'
metadata CHANGED
@@ -1,16 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: factory_sloth
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.1
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Janosch Müller
8
- autorequire:
9
8
  bindir: exe
10
9
  cert_chain: []
11
- date: 2023-05-24 00:00:00.000000000 Z
10
+ date: 2024-10-04 00:00:00.000000000 Z
12
11
  dependencies: []
13
- description:
14
12
  email:
15
13
  - janosch84@gmail.com
16
14
  executables:
@@ -44,7 +42,6 @@ metadata:
44
42
  homepage_uri: https://github.com/jaynetics/factory_sloth
45
43
  source_code_uri: https://github.com/jaynetics/factory_sloth
46
44
  changelog_uri: https://github.com/jaynetics/factory_sloth/blob/main/CHANGELOG.md
47
- post_install_message:
48
45
  rdoc_options: []
49
46
  require_paths:
50
47
  - lib
@@ -59,8 +56,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
59
56
  - !ruby/object:Gem::Version
60
57
  version: '0'
61
58
  requirements: []
62
- rubygems_version: 3.4.13
63
- signing_key:
59
+ rubygems_version: 3.6.0.dev
64
60
  specification_version: 4
65
61
  summary: Find and replace unnecessary factory_bot create calls.
66
62
  test_files: []