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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6649593166b051c563e05a6a3a2130a1d369a6b828e5477a2f3d392f15ea691f
4
- data.tar.gz: e78c03b663ad0951deee38f8202eaa73613a88690ccb5e43b07d81b3ca971f57
3
+ metadata.gz: 4a2671b0f8875aba53408b7ed31712608aa0ab5077ec0aa723822178a256b108
4
+ data.tar.gz: bb9602cc445024903c59064dfb9047e6ae86a9bed4ec964a9a7960bb2e0221e8
5
5
  SHA512:
6
- metadata.gz: 395be11e15e5a7ff181c381c1790b4b826c849d1ae4e1aadb1f002a9825f2976e3c696c4b710593c6b57d7e1d6cc742364ba24b2c9a4b5859e01ba86a1fd8a5b
7
- data.tar.gz: 5aedb0a332cab72f10ad39dff8cc395133f8fb5170ae82ae7d01b8af9073a16d9d6c994af4046ab3f99ffd4edfbb0075fad5c0510b6bcbf83db6f0add433c03a
6
+ metadata.gz: 7ec6b3f50d536f0adf09699c6a3360b3ce912e18953977060c4989194aa61866bda897c95fe1106a3d9fd741ed6afa61b2ad2e2e5983fe4a9a0d858456f31fe2
7
+ data.tar.gz: 36d2d1046c44777c147c9e3a41514610ddfb4704c9de7ac2a700f77292bee74d8f298c5d418fb2c81032f495084f6fa7f89218db697b67d45590bf8d474cb3b6
@@ -18,10 +18,10 @@ jobs:
18
18
  runs-on: ubuntu-latest
19
19
  strategy:
20
20
  matrix:
21
- ruby-version: ['2.6', '2.7', '3.0', '3.1']
21
+ ruby-version: ['3.3', '3.4', '4.0']
22
22
 
23
23
  steps:
24
- - uses: actions/checkout@v2
24
+ - uses: actions/checkout@v4
25
25
  - name: Set up Ruby
26
26
  uses: ruby/setup-ruby@v1
27
27
  with:
data/.gitignore CHANGED
@@ -3,7 +3,6 @@
3
3
  .bundle
4
4
  .config
5
5
  .yardoc
6
- Gemfile.lock
7
6
  InstalledFiles
8
7
  _yardoc
9
8
  coverage
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 3.1.0
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
@@ -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 "sexp_processor"
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 sexp.
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 sexp_type, like
24
+ # delegate to start_### according to the node_type, like
25
25
  #
26
26
  # start_call
27
27
  # start_def
28
28
  #
29
- # @param [Sexp] node
29
+ # @param [CodeAnalyzer::Node] node
30
30
  def node_start(node)
31
31
  @node = node
32
- self.class.get_callbacks("start_#{node.sexp_type}".to_sym).each { |block| self.instance_exec(node, &block) }
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 sexp_type, like
35
+ # delegate to end_### according to the node_type, like
36
36
  #
37
37
  # end_call
38
38
  # end_def
39
39
  #
40
- # @param [Sexp] node
40
+ # @param [CodeAnalyzer::Node] node
41
41
  def node_end(node)
42
42
  @node = node
43
- self.class.get_callbacks("end_#{node.sexp_type}".to_sym).each { |block| self.instance_exec(node, &block) }
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 sexp nodes.
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 sexp nodes for the ruby file.
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
- Sexp.from_array(Ripper::SexpBuilder.new(content).parse)
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 sexp node.
46
+ # recursively check ruby node.
47
47
  #
48
48
  # 1. it triggers the interesting checkers' start callbacks.
49
- # 2. recursively check the sexp children.
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.sexp_type]
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|