referral 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +62 -0
- data/lib/referral/filters_tokens.rb +11 -0
- data/lib/referral/parses_options.rb +1 -0
- data/lib/referral/prints_results.rb +3 -0
- data/lib/referral/token_types.rb +4 -2
- data/lib/referral/translates_node_to_token.rb +2 -1
- data/lib/referral/value/node_type.rb +1 -0
- data/lib/referral/value/options.rb +1 -0
- data/lib/referral/value/token.rb +1 -1
- data/lib/referral/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c5cdd1a3baacf145aeb660dbbcdc09a25a42514ae5b6fef5b1d7dc8edd111f0a
|
4
|
+
data.tar.gz: b70e542db5e9a56623c2234ced091c083d15cc086068b4626efd1e90417ba1c8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2a654ca517d2add99189f286c81ee79cb0925b776be195245bd18405e72184be1b1f885aa131c5a32d9bf286d4971ed31d95bfbaf407dfb2a11927c979f56221
|
7
|
+
data.tar.gz: 551e07877e433de2027d547cf8e20f9ddd26b63fcc41949e39fe395ccbca0b74fe882c344a45a7d4072190b76495b9be406073793af3e55536523b0d0e63b8c0
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -204,6 +204,23 @@ app/lib/presents_review_result.rb:60:2: 2019-06-02T02:38:01Z def item_result(s
|
|
204
204
|
|
205
205
|
`find` couldn't have told me that (I don't think)!
|
206
206
|
|
207
|
+
### Recipe: Find calls that have more than 1 argument
|
208
|
+
|
209
|
+
[Recently I was upgrading the i18n gem](http://blog.testdouble.com/posts/2019-10-15-lets-hash-this-out/) and came across some bugs introduced by [this change](https://github.com/ruby-i18n/i18n/commit/5eeaad7fb35f9a30f654e3bdeb6933daa7fd421d#diff-14d9864ac07456d554843dc2a3b174a4L179). To fix the issue, I started looking at all the places `I18n.t` was called from:
|
210
|
+
|
211
|
+
```
|
212
|
+
referral --type call --exact-name I18n.t -c location,source
|
213
|
+
```
|
214
|
+
|
215
|
+
Unfortunately, this produces 250+ false positives because the predominant usage was to pass a single argument to `t`. Only calls with more than 1 argument are affected by this change. `--pattern` doesn't work very well in this codebase, because calls to `t` with multiple arguments are more likely to be multiline.
|
216
|
+
|
217
|
+
```
|
218
|
+
referral --type call --exact-name I18n.t --arity 2+ -c location,source,arity
|
219
|
+
```
|
220
|
+
|
221
|
+
This produced 27 results I could quickly skim through.
|
222
|
+
|
223
|
+
|
207
224
|
## Options
|
208
225
|
|
209
226
|
Referral provides a lot of options. The help output of `referral --help` will
|
@@ -219,6 +236,7 @@ Usage: referral [options] files
|
|
219
236
|
--scope [SCOPE] Scope(s) in which to filter (e.g. Hastack#hide)
|
220
237
|
-p, --pattern [PATTERN] Regex pattern to filter
|
221
238
|
-t, --type [TYPES] Include only certain types. See Referral::TOKEN_TYPES.
|
239
|
+
--arity [ARITY] Number of arguments to a method call. (e.g. 2+)
|
222
240
|
--include-unnamed Include reference without identifiers (default: false)
|
223
241
|
-s, --sort {file,scope} (default: file). See Referral::SORT_FUNCTIONS
|
224
242
|
--print-headers Print header names (default: false)
|
@@ -231,6 +249,11 @@ A few things to note:
|
|
231
249
|
* Each of `--name`, `--exact-name`, `--full-name`, `--scope`, `--type`, and `--columns`
|
232
250
|
accept comma-separated arrays (e.g. `--name foo,bar,baz`)
|
233
251
|
|
252
|
+
* `--arity` accepts a number with an optional `+` or `-`.
|
253
|
+
* `--arity 0` Match calls with 0 arguments
|
254
|
+
* `--arity 1+` Match calls with 1 or more arguments
|
255
|
+
* `--arity 1-` Match calls with 1 or fewer arguments
|
256
|
+
|
234
257
|
* You can browse available sort functions [in
|
235
258
|
Referral::SORT_FUNCTIONS](/lib/referral/sorts_tokens.rb) for use with
|
236
259
|
`--sort`. Each key is the name to be specified on the command line. (If you're
|
@@ -255,6 +278,45 @@ A few things to note:
|
|
255
278
|
the result set twice: once when parsing the AST, and again when printing
|
256
279
|
results
|
257
280
|
|
281
|
+
## Running with Ruby version managers
|
282
|
+
|
283
|
+
Referral requires Ruby version >= 2.6, but your codebase may be running on something
|
284
|
+
older. You have a few options for using `referral`. You could 1) change your project's
|
285
|
+
ruby while you run `referral` and then change it back, but this seems cumbersome and
|
286
|
+
likely to cause annoyance. There are better ways.
|
287
|
+
|
288
|
+
## Run from outside your project's working directory
|
289
|
+
|
290
|
+
If you `cd ..` from your project's working directory (assuming in that context
|
291
|
+
you are running Ruby 2.6.x), you can run `referral` commands on your codebase by passing
|
292
|
+
the path to that codebase to referral:
|
293
|
+
|
294
|
+
```
|
295
|
+
$ referral MyAwesomeProject/
|
296
|
+
```
|
297
|
+
|
298
|
+
This works for many of `referrals` features, but isn't ideal when it comes to git;
|
299
|
+
columns like `git_sha`, `git_author` or `git_commit_at` will show empty results.
|
300
|
+
|
301
|
+
## Running with `rbenv`
|
302
|
+
|
303
|
+
If you're using `rbenv`, you _could_ temporarily switch your project's ruby to 2.6.x,
|
304
|
+
but you'd have to remember to switch it back again before running any of the code in
|
305
|
+
the project. To instantaneously switch to 2.6 and then back again (after the `referral`
|
306
|
+
command finishes), do this (from your `MyAwsomeProject` directory):
|
307
|
+
|
308
|
+
```
|
309
|
+
$ RBENV_VERSION=2.6.3 referral
|
310
|
+
```
|
311
|
+
|
312
|
+
## Running with RVM
|
313
|
+
|
314
|
+
The corresponding way to do this with `rvm` would be:
|
315
|
+
|
316
|
+
```
|
317
|
+
$ rvm 2.6.3 do referral
|
318
|
+
```
|
319
|
+
|
258
320
|
## Code of Conduct
|
259
321
|
|
260
322
|
This project follows Test Double's [code of
|
@@ -35,6 +35,17 @@ module Referral
|
|
35
35
|
true
|
36
36
|
end
|
37
37
|
},
|
38
|
+
arity: ->(token, arity) {
|
39
|
+
if token.arity.nil?
|
40
|
+
false
|
41
|
+
elsif arity.end_with? "+"
|
42
|
+
token.arity.to_i >= arity.to_i
|
43
|
+
elsif arity.end_with? "-"
|
44
|
+
token.arity.to_i <= arity.to_i
|
45
|
+
else
|
46
|
+
token.arity.to_i == arity.to_i
|
47
|
+
end
|
48
|
+
},
|
38
49
|
}
|
39
50
|
class FiltersTokens
|
40
51
|
def call(tokens, options)
|
@@ -25,6 +25,7 @@ module Referral
|
|
25
25
|
op.on("--scope [SCOPE]", Array, "Scope(s) in which to filter (e.g. Hastack#hide)")
|
26
26
|
op.on("-p", "--pattern [PATTERN]", Regexp, "Regex pattern to filter")
|
27
27
|
op.on("-t", "--type [TYPES]", Array, "Include only certain types. See Referral::TOKEN_TYPES.")
|
28
|
+
op.on("--arity [ARITY]", "Number of arguments to a method call. (e.g. 2+)")
|
28
29
|
op.on("--include-unnamed", TrueClass, "Include reference without identifiers (default: false)")
|
29
30
|
op.on("-s", "--sort {file,scope}", "(default: file). See Referral::SORT_FUNCTIONS")
|
30
31
|
op.on("--print-headers", TrueClass, "Print header names (default: false)")
|
data/lib/referral/token_types.rb
CHANGED
@@ -108,7 +108,8 @@ module Referral
|
|
108
108
|
token_type: :reference,
|
109
109
|
reverse_identifiers: true,
|
110
110
|
good_parent: true,
|
111
|
-
name_finder: ->(node) { node.children[1] }
|
111
|
+
name_finder: ->(node) { node.children[1] },
|
112
|
+
arity_finder: ->(node) { node.children.last&.children&.compact&.count || 0 }
|
112
113
|
),
|
113
114
|
function_call: Value::NodeType.new(
|
114
115
|
name: :function_call,
|
@@ -117,7 +118,8 @@ module Referral
|
|
117
118
|
token_type: :reference,
|
118
119
|
reverse_identifiers: true,
|
119
120
|
good_parent: false,
|
120
|
-
name_finder: ->(node) { node.children[0] }
|
121
|
+
name_finder: ->(node) { node.children[0] },
|
122
|
+
arity_finder: ->(node) { node.children.last&.children&.compact&.count || 0 }
|
121
123
|
),
|
122
124
|
local_var: Value::NodeType.new(
|
123
125
|
name: :local_var,
|
data/lib/referral/value/token.rb
CHANGED
data/lib/referral/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: referral
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Justin Searls
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-11-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|