code_analyzer 0.5.4 → 0.7.0
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/.github/workflows/main.yml +2 -2
- data/.gitignore +0 -1
- data/.ruby-version +1 -1
- data/CHANGELOG.md +127 -0
- data/Gemfile.lock +38 -0
- data/code_analyzer.gemspec +2 -1
- data/lib/code_analyzer/checker.rb +7 -7
- data/lib/code_analyzer/checking_visitor/default.rb +7 -7
- data/lib/code_analyzer/node.rb +1186 -0
- data/lib/code_analyzer/version.rb +1 -1
- data/lib/code_analyzer.rb +1 -3
- data/spec/code_analyzer/{sexp_spec.rb → node_spec.rb} +194 -195
- data/spec/spec_helper.rb +1 -1
- metadata +12 -16
- data/lib/code_analyzer/nil.rb +0 -36
- data/lib/code_analyzer/sexp.rb +0 -911
- data/spec/code_analyzer/nil_spec.rb +0 -39
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 4a2671b0f8875aba53408b7ed31712608aa0ab5077ec0aa723822178a256b108
|
|
4
|
+
data.tar.gz: bb9602cc445024903c59064dfb9047e6ae86a9bed4ec964a9a7960bb2e0221e8
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 7ec6b3f50d536f0adf09699c6a3360b3ce912e18953977060c4989194aa61866bda897c95fe1106a3d9fd741ed6afa61b2ad2e2e5983fe4a9a0d858456f31fe2
|
|
7
|
+
data.tar.gz: 36d2d1046c44777c147c9e3a41514610ddfb4704c9de7ac2a700f77292bee74d8f298c5d418fb2c81032f495084f6fa7f89218db697b67d45590bf8d474cb3b6
|
data/.github/workflows/main.yml
CHANGED
|
@@ -18,10 +18,10 @@ jobs:
|
|
|
18
18
|
runs-on: ubuntu-latest
|
|
19
19
|
strategy:
|
|
20
20
|
matrix:
|
|
21
|
-
ruby-version: ['
|
|
21
|
+
ruby-version: ['3.3', '3.4', '4.0']
|
|
22
22
|
|
|
23
23
|
steps:
|
|
24
|
-
- uses: actions/checkout@
|
|
24
|
+
- uses: actions/checkout@v4
|
|
25
25
|
- name: Set up Ruby
|
|
26
26
|
uses: ruby/setup-ruby@v1
|
|
27
27
|
with:
|
data/.gitignore
CHANGED
data/.ruby-version
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
4.0.10
|
data/CHANGELOG.md
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.7.0 (2026-12-04)
|
|
4
|
+
|
|
5
|
+
* Parse Ruby with Prism instead of Ripper, drop sexp_processor
|
|
6
|
+
* Rename `Sexp` to `CodeAnalyzer::Node` and `sexp_type` to `node_type`
|
|
7
|
+
* Remove `CodeAnalyzer::Nil`, missing nodes and lookups return nil
|
|
8
|
+
* Require Ruby >= 3.3 and prism >= 1.9.0
|
|
9
|
+
|
|
10
|
+
## 0.5.5 (2022-01-30)
|
|
11
|
+
|
|
12
|
+
* support nil value of :assoc_new
|
|
13
|
+
|
|
14
|
+
## 0.5.4 (2022-01-30)
|
|
15
|
+
|
|
16
|
+
* support array value of :assoc_new
|
|
17
|
+
|
|
18
|
+
## 0.5.3 (2022-01-30)
|
|
19
|
+
|
|
20
|
+
* support key and value of :assoc_new
|
|
21
|
+
* set ruby version to 3.1.0
|
|
22
|
+
* move travis to github
|
|
23
|
+
* update README
|
|
24
|
+
|
|
25
|
+
## 0.5.2 (2020-07-01)
|
|
26
|
+
|
|
27
|
+
* Auto corrected by following Lint Ruby MagicComment
|
|
28
|
+
* Auto corrected by following Format Ruby Code
|
|
29
|
+
* Auto corrected by following Lint Ruby EmptyLine
|
|
30
|
+
* Fix `Sexp#line_number` on `:unary`
|
|
31
|
+
* Fix `Sexp#line_number` on various types
|
|
32
|
+
* Update Ruby versions on Travis CI (updated: 2.6.6, added: 2.7.1)
|
|
33
|
+
* Fix `Sexp#line_number` on `:top_const_ref`, `:dot2`, and `:dot3` types
|
|
34
|
+
* remove encoding: utf-8 comment
|
|
35
|
+
|
|
36
|
+
## 0.5.1 (2019-12-28)
|
|
37
|
+
|
|
38
|
+
* remove 1.9.3 compatible tests
|
|
39
|
+
* support :@period for to_s
|
|
40
|
+
|
|
41
|
+
## 0.5.0 (2019-12-28)
|
|
42
|
+
|
|
43
|
+
* Auto corrected by following Format Ruby Code
|
|
44
|
+
* fix after upgrading to ruby 2.6
|
|
45
|
+
|
|
46
|
+
## 0.4.8 (2017-07-26)
|
|
47
|
+
|
|
48
|
+
* Supports `%I()` in array_values
|
|
49
|
+
|
|
50
|
+
## 0.4.7 (2016-08-23)
|
|
51
|
+
|
|
52
|
+
* return empty array in %w(), %W(), %i()
|
|
53
|
+
|
|
54
|
+
## 0.4.6 (2016-08-07)
|
|
55
|
+
|
|
56
|
+
* Use documentation instead of nested
|
|
57
|
+
* Use `be true` instead of `be_true`
|
|
58
|
+
* Use `not_to receive` instead of `should_not_receive`
|
|
59
|
+
* Call check_node directly to avoid stack over flow
|
|
60
|
+
* use ruby 2.3.1 on travis
|
|
61
|
+
* fix indent
|
|
62
|
+
|
|
63
|
+
## 0.4.5 (2014-03-31)
|
|
64
|
+
|
|
65
|
+
* remove ruby version and gemset
|
|
66
|
+
* support :top_const_ref node to_s
|
|
67
|
+
* use rspec new syntax by synvert
|
|
68
|
+
|
|
69
|
+
## 0.4.4 (2014-01-06)
|
|
70
|
+
|
|
71
|
+
* run with ruby 1.9.3 and 2.0.0 on travis-ci
|
|
72
|
+
* qsymbols_add is available only from ruby 2.0.0
|
|
73
|
+
* fix typo
|
|
74
|
+
* add 2.1.0 on travis
|
|
75
|
+
|
|
76
|
+
## 0.4.3 (2013-09-26)
|
|
77
|
+
|
|
78
|
+
* to support %i() syntax
|
|
79
|
+
|
|
80
|
+
## 0.4.2 (2013-08-25)
|
|
81
|
+
|
|
82
|
+
* fix %W() parser
|
|
83
|
+
|
|
84
|
+
## 0.4.1 (2013-08-25)
|
|
85
|
+
|
|
86
|
+
* Specify MIT license in gemspec
|
|
87
|
+
* rename Sexp#block to Sexp#block_node
|
|
88
|
+
|
|
89
|
+
## 0.4.0 (2013-08-13)
|
|
90
|
+
|
|
91
|
+
* Rename :line to :line_number so as not to over-write the :line method
|
|
92
|
+
* use latest ruby 2.0.0
|
|
93
|
+
|
|
94
|
+
## 0.3.2 (2013-06-14)
|
|
95
|
+
|
|
96
|
+
* use ruby-version and ruby-gemset instead of rvmrc
|
|
97
|
+
* plain checking_visitor also checks interesting_files
|
|
98
|
+
|
|
99
|
+
## 0.3.1 (2012-12-18)
|
|
100
|
+
|
|
101
|
+
* update README
|
|
102
|
+
* add rake dependecy per travis suggestion
|
|
103
|
+
* add default rake task
|
|
104
|
+
* update README
|
|
105
|
+
* use new ruby 1.9.3
|
|
106
|
+
* add :if_mod and unless_mod in sexp
|
|
107
|
+
|
|
108
|
+
## 0.3.0 (2012-11-02)
|
|
109
|
+
|
|
110
|
+
* add exception_class and exception_variable for rescue node
|
|
111
|
+
* check empty rescue node
|
|
112
|
+
|
|
113
|
+
## 0.2.0 (2012-09-22)
|
|
114
|
+
|
|
115
|
+
* update README
|
|
116
|
+
* add more comments
|
|
117
|
+
* CheckingVisitor#warnings returns all checkers' warnings
|
|
118
|
+
|
|
119
|
+
## 0.1.1 (2012-09-17)
|
|
120
|
+
|
|
121
|
+
* support line for Sexp :massign
|
|
122
|
+
* support line for Sexp :opassign
|
|
123
|
+
|
|
124
|
+
## 0.1.0 (2012-09-04)
|
|
125
|
+
|
|
126
|
+
* extract from rails_best_practices
|
|
127
|
+
* update description, summary and homepage in gemspec
|
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: .
|
|
3
|
+
specs:
|
|
4
|
+
code_analyzer (0.7.0)
|
|
5
|
+
prism (>= 1.9.0)
|
|
6
|
+
|
|
7
|
+
GEM
|
|
8
|
+
remote: https://rubygems.org/
|
|
9
|
+
specs:
|
|
10
|
+
diff-lcs (1.6.2)
|
|
11
|
+
prism (2.1.0)
|
|
12
|
+
prism (2.1.0-arm64-darwin)
|
|
13
|
+
rake (13.4.2)
|
|
14
|
+
rspec (3.13.2)
|
|
15
|
+
rspec-core (~> 3.13.0)
|
|
16
|
+
rspec-expectations (~> 3.13.0)
|
|
17
|
+
rspec-mocks (~> 3.13.0)
|
|
18
|
+
rspec-core (3.13.7)
|
|
19
|
+
rspec-support (~> 3.13.0)
|
|
20
|
+
rspec-expectations (3.13.6)
|
|
21
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
22
|
+
rspec-support (~> 3.13.0)
|
|
23
|
+
rspec-mocks (3.13.9)
|
|
24
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
25
|
+
rspec-support (~> 3.13.0)
|
|
26
|
+
rspec-support (3.13.8)
|
|
27
|
+
|
|
28
|
+
PLATFORMS
|
|
29
|
+
arm64-darwin-25
|
|
30
|
+
ruby
|
|
31
|
+
|
|
32
|
+
DEPENDENCIES
|
|
33
|
+
code_analyzer!
|
|
34
|
+
rake
|
|
35
|
+
rspec
|
|
36
|
+
|
|
37
|
+
BUNDLED WITH
|
|
38
|
+
4.0.20
|
data/code_analyzer.gemspec
CHANGED
|
@@ -16,8 +16,9 @@ Gem::Specification.new do |gem|
|
|
|
16
16
|
gem.name = "code_analyzer"
|
|
17
17
|
gem.require_paths = ["lib"]
|
|
18
18
|
gem.version = CodeAnalyzer::VERSION
|
|
19
|
+
gem.required_ruby_version = ">= 3.3"
|
|
19
20
|
|
|
20
|
-
gem.add_dependency "
|
|
21
|
+
gem.add_dependency "prism", ">= 1.9.0"
|
|
21
22
|
gem.add_development_dependency "rspec"
|
|
22
23
|
gem.add_development_dependency "rake"
|
|
23
24
|
end
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
module CodeAnalyzer
|
|
4
|
-
# A checker class that takes charge of checking the
|
|
4
|
+
# A checker class that takes charge of checking the ruby nodes.
|
|
5
5
|
class Checker
|
|
6
6
|
# interesting nodes that the check will parse.
|
|
7
7
|
def interesting_nodes
|
|
@@ -21,26 +21,26 @@ module CodeAnalyzer
|
|
|
21
21
|
interesting_files.any? { |pattern| node_file =~ pattern }
|
|
22
22
|
end
|
|
23
23
|
|
|
24
|
-
# delegate to start_### according to the
|
|
24
|
+
# delegate to start_### according to the node_type, like
|
|
25
25
|
#
|
|
26
26
|
# start_call
|
|
27
27
|
# start_def
|
|
28
28
|
#
|
|
29
|
-
# @param [
|
|
29
|
+
# @param [CodeAnalyzer::Node] node
|
|
30
30
|
def node_start(node)
|
|
31
31
|
@node = node
|
|
32
|
-
self.class.get_callbacks("start_#{node.
|
|
32
|
+
self.class.get_callbacks("start_#{node.node_type}".to_sym).each { |block| self.instance_exec(node, &block) }
|
|
33
33
|
end
|
|
34
34
|
|
|
35
|
-
# delegate to end_### according to the
|
|
35
|
+
# delegate to end_### according to the node_type, like
|
|
36
36
|
#
|
|
37
37
|
# end_call
|
|
38
38
|
# end_def
|
|
39
39
|
#
|
|
40
|
-
# @param [
|
|
40
|
+
# @param [CodeAnalyzer::Node] node
|
|
41
41
|
def node_end(node)
|
|
42
42
|
@node = node
|
|
43
|
-
self.class.get_callbacks("end_#{node.
|
|
43
|
+
self.class.get_callbacks("end_#{node.node_type}".to_sym).each { |block| self.instance_exec(node, &block) }
|
|
44
44
|
end
|
|
45
45
|
|
|
46
46
|
# add an warning.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
module CodeAnalyzer::CheckingVisitor
|
|
4
|
-
# This is the default checking visitor to check ruby
|
|
4
|
+
# This is the default checking visitor to check ruby nodes.
|
|
5
5
|
class Default < Base
|
|
6
6
|
def initialize(options = {})
|
|
7
7
|
super
|
|
@@ -15,7 +15,7 @@ module CodeAnalyzer::CheckingVisitor
|
|
|
15
15
|
end
|
|
16
16
|
end
|
|
17
17
|
|
|
18
|
-
# check the ruby
|
|
18
|
+
# check the ruby nodes for the ruby file.
|
|
19
19
|
#
|
|
20
20
|
# @param [String] filename is the filename of ruby code.
|
|
21
21
|
# @param [String] content is the content of ruby file.
|
|
@@ -38,18 +38,18 @@ module CodeAnalyzer::CheckingVisitor
|
|
|
38
38
|
# @param [String] filename is the filename of ruby code.
|
|
39
39
|
# @param [String] content is the content of ruby file.
|
|
40
40
|
def parse(filename, content)
|
|
41
|
-
|
|
41
|
+
CodeAnalyzer::Node.from_prism(Prism.parse(content).value)
|
|
42
42
|
rescue Exception
|
|
43
|
-
raise AnalyzerException.new("#{filename} looks like it's not a valid Ruby file. Skipping...")
|
|
43
|
+
raise CodeAnalyzer::AnalyzerException.new("#{filename} looks like it's not a valid Ruby file. Skipping...")
|
|
44
44
|
end
|
|
45
45
|
|
|
46
|
-
# recursively check ruby
|
|
46
|
+
# recursively check ruby node.
|
|
47
47
|
#
|
|
48
48
|
# 1. it triggers the interesting checkers' start callbacks.
|
|
49
|
-
# 2. recursively check the
|
|
49
|
+
# 2. recursively check the node children.
|
|
50
50
|
# 3. it triggers the interesting checkers' end callbacks.
|
|
51
51
|
def check_node(node)
|
|
52
|
-
checkers = @checks[node.
|
|
52
|
+
checkers = @checks[node.node_type]
|
|
53
53
|
|
|
54
54
|
checkers.each { |checker| checker.node_start(node) if checker.parse_file?(node.file) } if checkers
|
|
55
55
|
node.children.each do |child_node|
|