deprecool 0.1.0 → 0.1.1
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 +4 -4
- data/README.md +30 -3
- data/lib/deprecool/cli.rb +0 -1
- data/lib/deprecool/finder.rb +1 -4
- data/lib/deprecool/registry.rb +2 -3
- data/lib/deprecool/scanner.rb +15 -13
- data/lib/deprecool/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e52876064a919fd936c1ce856a936497321260b30bb28d4af9583f1c4f408b2f
|
|
4
|
+
data.tar.gz: e2f181b5779334b951ab52f209533608d565764a09d9633c22bcc282ff604b04
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 2054d49032593500337f9f406c298852b0fb11b03e745217c0ebdda4d5e26aa89ea06ed9d84855269a7c1079d38c09a6bb27fd5ac5a35b9138ac626f2fc0db72
|
|
7
|
+
data.tar.gz: f5014e5d52b173c5071f5622d892fc72783cbf61585cbed8d8a6845994ec704db0f3152055d2ae1074988b8be0331cac04134c73d797b6b8bc05c4dcdab7af34
|
data/README.md
CHANGED
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
A static ruby code analyzer to find your deprecated code!
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
A helpful tool for any developer who has ever ignored a gem's warning and then ran into an error when they went to update
|
|
6
6
|
|
|
7
7
|
## Usage
|
|
8
8
|
|
|
9
|
-
Add to your
|
|
9
|
+
Add to your Gemfile: `gem 'deprecool'`
|
|
10
10
|
Or directly `gem install deprecool`
|
|
11
11
|
|
|
12
12
|
Then you can run `deprecool` in the command line to get:
|
|
@@ -24,12 +24,39 @@ Commands:
|
|
|
24
24
|
|
|
25
25
|
- `--gem` takes a comma separated list of gems to scan for:
|
|
26
26
|
|
|
27
|
+
_(make sure there are no spaces between the gem names)_
|
|
28
|
+
|
|
27
29
|
```
|
|
28
30
|
deprecool scan --gem=rails,ruby
|
|
29
31
|
```
|
|
30
|
-
_(make sure there are no spaces between the gem names)_
|
|
31
32
|
|
|
32
33
|
- `--format=json` if you want the output as json instead of the default text
|
|
33
34
|
- `--lockfile` takes a path to your `Gemfile.lock`, it defaults to using the current directory
|
|
34
35
|
- `--all` run every finder regardless of applicability
|
|
35
36
|
- `--paths` an array of the files or directories to look for ruby file in, defaults to `'.'`
|
|
37
|
+
|
|
38
|
+
## Contributing
|
|
39
|
+
|
|
40
|
+
This project has an incredibly large scope and I can't do it alone!
|
|
41
|
+
|
|
42
|
+
If you see a deprecation warning in your code that isn't reflected here please either create an issue or make a PR
|
|
43
|
+
|
|
44
|
+
Deprecool is designed to be able to support new deprecation warnings very easily.
|
|
45
|
+
|
|
46
|
+
After cloning the repo, simply add two files:
|
|
47
|
+
|
|
48
|
+
```
|
|
49
|
+
lib/deprecool/finders/< gem name >/< gem version>/<short_name_of_warning>.rb
|
|
50
|
+
|
|
51
|
+
test/deprecool/finders/< gem name >/< gem version>/<short_name_of_warning>_test.rb
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Or, run the `exe/contribute` script and it will prompt you for:
|
|
55
|
+
- the gem name
|
|
56
|
+
- the version the deprecation first appears in
|
|
57
|
+
- a short name for the warning's finder class
|
|
58
|
+
|
|
59
|
+
_(if the script doesn't work, run `chmod +x exe/contribute` and try again)_
|
|
60
|
+
|
|
61
|
+
Then use `rake` to run the test suite.
|
|
62
|
+
|
data/lib/deprecool/cli.rb
CHANGED
data/lib/deprecool/finder.rb
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
# requiring this here so we don't have to remember to add
|
|
4
|
-
# it in individual finders
|
|
5
3
|
require_relative 'helpers/prism_helpers'
|
|
6
4
|
|
|
7
5
|
module Deprecool
|
|
@@ -106,7 +104,6 @@ module Deprecool
|
|
|
106
104
|
# Prism::VisitClassNode => on_class_node
|
|
107
105
|
# Prism::VisitDefNode => on_def_node
|
|
108
106
|
# Prism::VisitModuleNode => on_module_node
|
|
109
|
-
# Prism::
|
|
110
107
|
def hook_methods
|
|
111
108
|
instance_methods(false).grep(/\Aon_\w+_node\z/)
|
|
112
109
|
end
|
|
@@ -116,7 +113,7 @@ module Deprecool
|
|
|
116
113
|
|
|
117
114
|
def initialize(file_path, source, offenses)
|
|
118
115
|
@file_path = file_path
|
|
119
|
-
@source = source # the
|
|
116
|
+
@source = source # the AST from Prism.parse
|
|
120
117
|
@offenses = offenses
|
|
121
118
|
end
|
|
122
119
|
|
data/lib/deprecool/registry.rb
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
module Deprecool
|
|
4
|
-
# Selects which finders should run for a given application
|
|
5
|
-
# (and Ruby) it actually uses and at what versions.
|
|
4
|
+
# Selects which finders should run for a given application
|
|
6
5
|
module Registry
|
|
7
6
|
extend self
|
|
8
7
|
|
|
9
|
-
#
|
|
8
|
+
# All the subclasses of Finder
|
|
10
9
|
def all_finders
|
|
11
10
|
Finder.registry
|
|
12
11
|
end
|
data/lib/deprecool/scanner.rb
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
module Deprecool
|
|
4
|
-
# Parses a source file with Prism and runs a set of finders against it
|
|
5
|
-
# single AST traversal.
|
|
4
|
+
# Parses a source file with Prism and runs a set of finders against it
|
|
6
5
|
class Scanner
|
|
7
6
|
def initialize(finders)
|
|
8
7
|
@finders = Array(finders)
|
|
@@ -12,8 +11,8 @@ module Deprecool
|
|
|
12
11
|
scan_source(File.read(path), path)
|
|
13
12
|
end
|
|
14
13
|
|
|
15
|
-
#
|
|
16
|
-
#
|
|
14
|
+
# pass Prism's AST over to the dispatcher to gather offending
|
|
15
|
+
# snippets of code into an array
|
|
17
16
|
def scan_source(source, path = '(source)')
|
|
18
17
|
result = Prism.parse(source)
|
|
19
18
|
return [] unless result.success?
|
|
@@ -25,36 +24,39 @@ module Deprecool
|
|
|
25
24
|
# and offenses are only needed for the add_offense method, not the actual
|
|
26
25
|
# searching for an offense?
|
|
27
26
|
instances = @finders.map { |finder| finder.new(path, source, offenses) }
|
|
28
|
-
|
|
27
|
+
FinderDispatcher.new(instances).visit(result.value)
|
|
29
28
|
offenses
|
|
30
29
|
end
|
|
31
30
|
|
|
32
|
-
# Combines the given Finder
|
|
31
|
+
# Combines the given Finder instances into one class by
|
|
33
32
|
# defining one method per Prism::Visitor hook (e.g. visit_call_node)
|
|
34
33
|
# based on all the given finders that define a method that matches that
|
|
35
34
|
# hook method name
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
35
|
+
#
|
|
36
|
+
# This pattern makes it so that the Finders can remain as simple as
|
|
37
|
+
# possible while passing off their functionality info this class
|
|
38
|
+
class FinderDispatcher < Prism::Visitor
|
|
39
|
+
# finder_instances is the array passed to the Scanner instance,
|
|
40
|
+
# i.e [Ruby::V4_0_0::ToSetArguments.new, ...]
|
|
39
41
|
def initialize(finder_instances)
|
|
40
42
|
super()
|
|
41
43
|
|
|
42
44
|
dispatch = Hash.new { |hash, key| hash[key] = [] }
|
|
43
45
|
finder_instances.each do |instance|
|
|
44
46
|
# find the hooks and add the instances to the hash of hook methods
|
|
45
|
-
# so { on_call_node: [ToSetArguments.new, ObjectSpaceId2ref.new
|
|
47
|
+
# so { on_call_node: [ToSetArguments.new, ObjectSpaceId2ref.new, ... ], ... }
|
|
46
48
|
instance.class.hook_methods.each { |hook| dispatch[hook] << instance }
|
|
47
49
|
end
|
|
48
50
|
|
|
49
51
|
dispatch.each do |hook, finders|
|
|
50
|
-
# convert the instances' hooks to what
|
|
51
|
-
#
|
|
52
|
+
# convert the instances' hooks to what Prism::Visitor expects.
|
|
53
|
+
# Finder classes must use this pattern to name their visit_*_node methods
|
|
52
54
|
#
|
|
53
55
|
# 'on_call_node' => good
|
|
54
56
|
# 'find_call_node' => bad
|
|
55
57
|
visit_method = hook.to_s.sub(/\Aon_/, 'visit_').to_sym
|
|
56
58
|
|
|
57
|
-
# define the
|
|
59
|
+
# define the Prism::Visitor hook method to loop through each of the
|
|
58
60
|
# related finders and call the name of the hook like so:
|
|
59
61
|
#
|
|
60
62
|
# def visit_call_node(node)
|
data/lib/deprecool/version.rb
CHANGED