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 +4 -4
- data/CHANGELOG.md +6 -0
- data/README.md +11 -0
- data/lib/factory_sloth/cli.rb +4 -0
- data/lib/factory_sloth/create_call_finder.rb +19 -6
- data/lib/factory_sloth/version.rb +1 -1
- data/lib/factory_sloth.rb +7 -1
- metadata +3 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c9c56ba87b89aec371bdf53b61c50c66a0f0c51b8ba75c4edc12245967face48
|
4
|
+
data.tar.gz: f1ead7cb06982fd34eedde94bc017dfb5612c744266d9e76fa014864fdaccc7c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1016ee245df8b06fb396f12806004c6ea63f88944b3286723623906dca43be42a5b39dae87db377f9616f35f6b5b3bea2d080eaa0818a14f429f110c388c9a4f
|
7
|
+
data.tar.gz: 96c402e4c4a287e69cb641ccf281365da5ea4f64f6d1092534483b9971d93fd0196bcb22c870516b3df5b88eaabe9097ae2a12758acc28f7616b2615e56935f6
|
data/CHANGELOG.md
CHANGED
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.
|
data/lib/factory_sloth/cli.rb
CHANGED
@@ -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
|
-
|
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,
|
28
|
-
store_call(
|
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,
|
32
|
-
store_call(
|
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, *)
|
data/lib/factory_sloth.rb
CHANGED
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.
|
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:
|
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.
|
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: []
|