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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: b18a16f794a38af603dcc6036257fb4718bcaf7f
4
- data.tar.gz: 194f1c7fd4eeda9b5feb90af63a5c0e695144a06
2
+ SHA256:
3
+ metadata.gz: 4455e3247da8def6aaed2fd3a0f677be5e563c38f67c58e3afda1292958685d1
4
+ data.tar.gz: 9f9034f8704c2df789d5182be9c6bb01ea8d83785dd91699e7d5f2b73a2a3c72
5
5
  SHA512:
6
- metadata.gz: 10840f679ab73b8e69f324be82c95de6eb11d2002ac984528c224923daf06f0c829590b4d47345cf4fe9086d5258c5e66822ed99bb8d52767729fb8920bc8368
7
- data.tar.gz: a7222ce5efb0197e63e61bc20e86bbc730275494cd315a890602a0cafccae8abf9582d14578e35da962d5cdc7d2ea8e94f026b86c11f3517cf921a2679480f3c
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
- | Project | code_analyzer
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
@@ -1,4 +1,5 @@
1
- # -*- encoding: utf-8 -*-
1
+ # frozen_string_literal: true
2
+
2
3
  require File.expand_path('../lib/code_analyzer/version', __FILE__)
3
4
 
4
5
  Gem::Specification.new do |gem|
@@ -1,4 +1,5 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
+
2
3
  module CodeAnalyzer
3
4
  class AnalyzerException < Exception; end
4
5
  end
@@ -1,4 +1,5 @@
1
- # encoding: utf-8
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 do |block|
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 do |block|
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
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
+
2
3
  module CodeAnalyzer::CheckingVisitor
3
4
  # Base class for checking visitor.
4
5
  class Base
5
- def initialize(options={})
6
+ def initialize(options = {})
6
7
  @checkers = options[:checkers]
7
8
  end
8
9
 
@@ -1,8 +1,9 @@
1
- # encoding: utf-8
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 do |block|
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
- if checkers
55
- checkers.each { |checker| checker.node_start(node) if checker.parse_file?(node.file) }
56
- end
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
- # encoding: utf-8
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 do |checker|
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
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
+
2
3
  module CodeAnalyzer
3
4
  module CheckingVisitor
4
- autoload :Base, "code_analyzer/checking_visitor/base"
5
- autoload :Plain, "code_analyzer/checking_visitor/plain"
6
- autoload :Default, "code_analyzer/checking_visitor/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
@@ -1,4 +1,5 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
+
2
3
  module CodeAnalyzer
3
4
  # Fake nil.
4
5
  class Nil