code_analyzer 0.4.8 → 0.5.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/workflows/main.yml +31 -0
- data/.ruby-version +1 -0
- data/README.md +1 -7
- data/code_analyzer.gemspec +2 -1
- data/lib/code_analyzer/analyzer_exception.rb +2 -1
- data/lib/code_analyzer/checker.rb +5 -8
- data/lib/code_analyzer/checking_visitor/base.rb +3 -2
- data/lib/code_analyzer/checking_visitor/default.rb +9 -12
- data/lib/code_analyzer/checking_visitor/plain.rb +3 -4
- data/lib/code_analyzer/checking_visitor.rb +5 -4
- data/lib/code_analyzer/nil.rb +2 -1
- data/lib/code_analyzer/sexp.rb +132 -111
- data/lib/code_analyzer/version.rb +3 -2
- data/lib/code_analyzer/warning.rb +3 -2
- data/lib/code_analyzer.rb +10 -9
- data/spec/code_analyzer/checker_spec.rb +19 -17
- data/spec/code_analyzer/checking_visitor/base_spec.rb +2 -0
- data/spec/code_analyzer/checking_visitor/default_spec.rb +14 -12
- data/spec/code_analyzer/checking_visitor/plain_spec.rb +6 -4
- data/spec/code_analyzer/nil_spec.rb +12 -10
- data/spec/code_analyzer/sexp_spec.rb +469 -339
- data/spec/code_analyzer/warning_spec.rb +6 -6
- data/spec/spec_helper.rb +3 -1
- metadata +8 -8
- data/.travis.yml +0 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 4455e3247da8def6aaed2fd3a0f677be5e563c38f67c58e3afda1292958685d1
|
4
|
+
data.tar.gz: 9f9034f8704c2df789d5182be9c6bb01ea8d83785dd91699e7d5f2b73a2a3c72
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c8e7a551087cf2be47f0dfb3d8e34dc2234227bd12a2f97d26747f1d2682c54c4aa3e59c70b6ff3c930f74210e27c845bd8897b5d1c82155a8b596d2defba025
|
7
|
+
data.tar.gz: 50a1841f6e96d84c6839d6ba30cee28d0be769ac80d9905f36a77709c59c1a57ee72ecdee36aa72bc80d6e30b373d1a0dde881036b728b89a0b254d425e277f2
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# This workflow uses actions that are not certified by GitHub.
|
2
|
+
# They are provided by a third-party and are governed by
|
3
|
+
# separate terms of service, privacy policy, and support
|
4
|
+
# documentation.
|
5
|
+
# This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
|
6
|
+
# For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
|
7
|
+
|
8
|
+
name: CI
|
9
|
+
|
10
|
+
on:
|
11
|
+
push:
|
12
|
+
branches: [ master ]
|
13
|
+
pull_request:
|
14
|
+
branches: [ master ]
|
15
|
+
|
16
|
+
jobs:
|
17
|
+
test:
|
18
|
+
runs-on: ubuntu-latest
|
19
|
+
strategy:
|
20
|
+
matrix:
|
21
|
+
ruby-version: ['2.6', '2.7', '3.0', '3.1']
|
22
|
+
|
23
|
+
steps:
|
24
|
+
- uses: actions/checkout@v2
|
25
|
+
- name: Set up Ruby
|
26
|
+
uses: ruby/setup-ruby@v1
|
27
|
+
with:
|
28
|
+
ruby-version: ${{ matrix.ruby-version }}
|
29
|
+
bundler-cache: true
|
30
|
+
- name: Run tests
|
31
|
+
run: bundle exec rspec spec
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
3.1.0
|
data/README.md
CHANGED
@@ -1,11 +1,6 @@
|
|
1
1
|
# CodeAnalyzer
|
2
2
|
|
3
|
-
|
4
|
-
|:---------|:--------------------------------------------
|
5
|
-
| Homepage | https://github.com/flyerhzm/code_analyzer
|
6
|
-
| Document | http://rubydoc.info/gems/code_analyzer/frames
|
7
|
-
| CI | [![Build Status](https://travis-ci.org/flyerhzm/code_analyzer.png)](https://travis-ci.org/flyerhzm/code_analyzer)
|
8
|
-
| Author | [Richard Huang][0]
|
3
|
+
[![CI](https://github.com/flyerhzm/code_analyzer/actions/workflows/main.yml/badge.svg)](https://github.com/flyerhzm/code_analyzer/actions/workflows/main.yml)
|
9
4
|
|
10
5
|
code_analyzer is extracted from [rails_best_practices][1], it helps you
|
11
6
|
easily build your own code analyzer tool.
|
@@ -36,5 +31,4 @@ Or install it yourself as:
|
|
36
31
|
4. Push to the branch (`git push origin my-new-feature`)
|
37
32
|
5. Create new Pull Request
|
38
33
|
|
39
|
-
[0]: http://huangzhimin.com
|
40
34
|
[1]: https://github.com/railsbp/rails_best_practices
|
data/code_analyzer.gemspec
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
2
3
|
module CodeAnalyzer
|
3
4
|
# A checker class that takes charge of checking the sexp.
|
4
5
|
class Checker
|
@@ -28,9 +29,7 @@ module CodeAnalyzer
|
|
28
29
|
# @param [Sexp] node
|
29
30
|
def node_start(node)
|
30
31
|
@node = node
|
31
|
-
self.class.get_callbacks("start_#{node.sexp_type}".to_sym).each
|
32
|
-
self.instance_exec(node, &block)
|
33
|
-
end
|
32
|
+
self.class.get_callbacks("start_#{node.sexp_type}".to_sym).each { |block| self.instance_exec(node, &block) }
|
34
33
|
end
|
35
34
|
|
36
35
|
# delegate to end_### according to the sexp_type, like
|
@@ -41,9 +40,7 @@ module CodeAnalyzer
|
|
41
40
|
# @param [Sexp] node
|
42
41
|
def node_end(node)
|
43
42
|
@node = node
|
44
|
-
self.class.get_callbacks("end_#{node.sexp_type}".to_sym).each
|
45
|
-
self.instance_exec(node, &block)
|
46
|
-
end
|
43
|
+
self.class.get_callbacks("end_#{node.sexp_type}".to_sym).each { |block| self.instance_exec(node, &block) }
|
47
44
|
end
|
48
45
|
|
49
46
|
# add an warning.
|
@@ -60,7 +57,7 @@ module CodeAnalyzer
|
|
60
57
|
@warnings ||= []
|
61
58
|
end
|
62
59
|
|
63
|
-
class <<self
|
60
|
+
class << self
|
64
61
|
def interesting_nodes(*nodes)
|
65
62
|
@interesting_nodes ||= []
|
66
63
|
@interesting_nodes += nodes
|
@@ -1,8 +1,9 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
2
3
|
module CodeAnalyzer::CheckingVisitor
|
3
4
|
# This is the default checking visitor to check ruby sexp nodes.
|
4
5
|
class Default < Base
|
5
|
-
def initialize(options={})
|
6
|
+
def initialize(options = {})
|
6
7
|
super
|
7
8
|
@checks = {}
|
8
9
|
@checkers.each do |checker|
|
@@ -28,9 +29,7 @@ module CodeAnalyzer::CheckingVisitor
|
|
28
29
|
def after_check
|
29
30
|
@checkers.each do |checker|
|
30
31
|
after_check_callbacks = checker.class.get_callbacks(:after_check)
|
31
|
-
after_check_callbacks.each
|
32
|
-
checker.instance_exec &block
|
33
|
-
end
|
32
|
+
after_check_callbacks.each { |block| checker.instance_exec &block }
|
34
33
|
end
|
35
34
|
end
|
36
35
|
|
@@ -51,16 +50,14 @@ module CodeAnalyzer::CheckingVisitor
|
|
51
50
|
# 3. it triggers the interesting checkers' end callbacks.
|
52
51
|
def check_node(node)
|
53
52
|
checkers = @checks[node.sexp_type]
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
node.children.each { |child_node|
|
53
|
+
|
54
|
+
checkers.each { |checker| checker.node_start(node) if checker.parse_file?(node.file) } if checkers
|
55
|
+
node.children.each do |child_node|
|
58
56
|
child_node.file = node.file
|
59
57
|
check_node(child_node)
|
60
|
-
}
|
61
|
-
if checkers
|
62
|
-
checkers.each { |checker| checker.node_end(node) if checker.parse_file?(node.file) }
|
63
58
|
end
|
59
|
+
|
60
|
+
checkers.each { |checker| checker.node_end(node) if checker.parse_file?(node.file) } if checkers
|
64
61
|
end
|
65
62
|
end
|
66
63
|
end
|
@@ -1,4 +1,5 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
2
3
|
module CodeAnalyzer::CheckingVisitor
|
3
4
|
# This is the checking visitor to check ruby plain code.
|
4
5
|
class Plain < Base
|
@@ -7,9 +8,7 @@ module CodeAnalyzer::CheckingVisitor
|
|
7
8
|
# @param [String] filename is the filename of ruby code.
|
8
9
|
# @param [String] content is the content of ruby file.
|
9
10
|
def check(filename, content)
|
10
|
-
@checkers.each
|
11
|
-
checker.check(filename, content) if checker.parse_file?(filename)
|
12
|
-
end
|
11
|
+
@checkers.each { |checker| checker.check(filename, content) if checker.parse_file?(filename) }
|
13
12
|
end
|
14
13
|
end
|
15
14
|
end
|
@@ -1,8 +1,9 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
2
3
|
module CodeAnalyzer
|
3
4
|
module CheckingVisitor
|
4
|
-
autoload :Base,
|
5
|
-
autoload :Plain,
|
6
|
-
autoload :Default,
|
5
|
+
autoload :Base, 'code_analyzer/checking_visitor/base'
|
6
|
+
autoload :Plain, 'code_analyzer/checking_visitor/plain'
|
7
|
+
autoload :Default, 'code_analyzer/checking_visitor/default'
|
7
8
|
end
|
8
9
|
end
|
data/lib/code_analyzer/nil.rb
CHANGED