referral 0.0.4 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2b444d6e3e344bd102380397e714039e2b72834f1f2f6c1023837fa097d215ee
4
- data.tar.gz: 46c19b9d8deccaeb7fd1e6489b765fddce2e039bd09790d7a952de429c87b36d
3
+ metadata.gz: c5cdd1a3baacf145aeb660dbbcdc09a25a42514ae5b6fef5b1d7dc8edd111f0a
4
+ data.tar.gz: b70e542db5e9a56623c2234ced091c083d15cc086068b4626efd1e90417ba1c8
5
5
  SHA512:
6
- metadata.gz: 75394674def26ffe7236d85d5c8bb1bef4af3b10d752cfb4e7a1c544f75730bdd16b1e53054351e2bcf36935ce4dca8339797f32c186965c5b6b6b51773eecce
7
- data.tar.gz: 4d9d68316c18f98ca8f42694bc661e2e7aa1a3549eae2757707c5745240bf23884a0800a2922765482a02e0a531da5ad354d0fcc56419d18a6bffd749b91cc2e
6
+ metadata.gz: 2a654ca517d2add99189f286c81ee79cb0925b776be195245bd18405e72184be1b1f885aa131c5a32d9bf286d4971ed31d95bfbaf407dfb2a11927c979f56221
7
+ data.tar.gz: 551e07877e433de2027d547cf8e20f9ddd26b63fcc41949e39fe395ccbca0b74fe882c344a45a7d4072190b76495b9be406073793af3e55536523b0d0e63b8c0
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- referral (0.0.4)
4
+ referral (0.0.5)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
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)")
@@ -43,6 +43,9 @@ module Referral
43
43
  git_commit_at: ->(token) {
44
44
  GitStore.time(token.file, token.line)&.utc&.iso8601
45
45
  },
46
+ arity: ->(token) {
47
+ token.arity
48
+ },
46
49
 
47
50
  }
48
51
 
@@ -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,
@@ -12,7 +12,8 @@ module Referral
12
12
  parent: parent,
13
13
  file: file,
14
14
  line: node.first_lineno,
15
- column: node.first_column
15
+ column: node.first_column,
16
+ arity: type&.arity_finder&.call(node)
16
17
  )
17
18
  end
18
19
  end
@@ -8,6 +8,7 @@ module Referral
8
8
  :token_type,
9
9
  :reverse_identifiers,
10
10
  :good_parent,
11
+ :arity_finder,
11
12
  keyword_init: true
12
13
  )
13
14
  end
@@ -10,6 +10,7 @@ module Referral
10
10
  :pattern,
11
11
  :type,
12
12
  :include_unnamed,
13
+ :arity,
13
14
  # Sorting
14
15
  :sort,
15
16
  # Printing
@@ -3,7 +3,7 @@ require "digest/sha1"
3
3
  module Referral
4
4
  module Value
5
5
  class Token < Struct.new(
6
- :name, :identifiers, :node_type, :parent, :file, :line, :column,
6
+ :name, :identifiers, :node_type, :parent, :file, :line, :column, :arity,
7
7
  keyword_init: true
8
8
  )
9
9
 
@@ -1,3 +1,3 @@
1
1
  module Referral
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
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
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-07-08 00:00:00.000000000 Z
11
+ date: 2019-11-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler