code_analyzer 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
data/.rvmrc CHANGED
@@ -1,2 +1,2 @@
1
1
  rvm_gemset_create_on_use_flag=1
2
- rvm gemset use ruby-1.9.3-p194@code_analyzer
2
+ rvm gemset use code_analyzer
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.2
4
+ - 1.9.3
data/README.md CHANGED
@@ -1,6 +1,13 @@
1
1
  # CodeAnalyzer
2
2
 
3
- code_analyzer is extracted from [rails_best_practices][0], it helps you
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]
9
+
10
+ code_analyzer is extracted from [rails_best_practices][1], it helps you
4
11
  easily build your own code analyzer tool.
5
12
 
6
13
  ## Installation
@@ -29,4 +36,5 @@ Or install it yourself as:
29
36
  4. Push to the branch (`git push origin my-new-feature`)
30
37
  5. Create new Pull Request
31
38
 
32
- [0]: https://github.com/railsbp/rails_best_practices
39
+ [0]: http://huangzhimin.com
40
+ [1]: https://github.com/railsbp/rails_best_practices
data/Rakefile CHANGED
@@ -1,2 +1,8 @@
1
1
  #!/usr/bin/env rake
2
2
  require "bundler/gem_tasks"
3
+ require "rspec/core/rake_task"
4
+
5
+ RSpec::Core::RakeTask.new(:spec) do |t|
6
+ t.rspec_opts = %w( --color )
7
+ end
8
+ task :default => :spec
@@ -17,4 +17,5 @@ Gem::Specification.new do |gem|
17
17
 
18
18
  gem.add_dependency "sexp_processor"
19
19
  gem.add_development_dependency "rspec"
20
+ gem.add_development_dependency "rake"
20
21
  end
@@ -16,7 +16,8 @@ class Sexp
16
16
  def line
17
17
  case sexp_type
18
18
  when :def, :defs, :command, :command_call, :call, :fcall, :method_add_arg, :method_add_block,
19
- :var_ref, :vcall, :const_ref, :const_path_ref, :class, :module, :if, :unless, :elsif, :ifop, :binary,
19
+ :var_ref, :vcall, :const_ref, :const_path_ref, :class, :module,
20
+ :if, :unless, :elsif, :ifop, :if_mod, :unless_mod, :binary,
20
21
  :alias, :symbol_literal, :symbol, :aref, :hash, :assoc_new, :string_literal,
21
22
  :massign
22
23
  self[1].line
@@ -329,7 +330,7 @@ class Sexp
329
330
  #
330
331
  # @return [Sexp] conditional statement of if node
331
332
  def conditional_statement
332
- if [:if, :unless, :elsif, :ifop].include? sexp_type
333
+ if [:if, :unless, :elsif, :ifop, :if_mod, :unless_mod].include? sexp_type
333
334
  self[1]
334
335
  end
335
336
  end
@@ -431,7 +432,7 @@ class Sexp
431
432
  case sexp_type
432
433
  when :else
433
434
  self[1]
434
- when :module, :if, :elsif, :unless
435
+ when :module, :if, :elsif, :unless, :if_mod, :unless_mod, :ifop
435
436
  self[2]
436
437
  when :class, :def
437
438
  self[3]
@@ -1,4 +1,4 @@
1
1
  # encoding: utf-8
2
2
  module CodeAnalyzer
3
- VERSION = "0.3.0"
3
+ VERSION = "0.3.1"
4
4
  end
@@ -16,6 +16,12 @@ describe Sexp do
16
16
  def opassign(a, b)
17
17
  a+= b
18
18
  end
19
+ def condition
20
+ if success?
21
+ puts "unknown" if output?
22
+ elsif fail?
23
+ end
24
+ end
19
25
  end
20
26
  EOF
21
27
  @node = parse_content(content)
@@ -52,6 +58,18 @@ describe Sexp do
52
58
  it "should return opassign line" do
53
59
  @node.grep_node(sexp_type: :opassign).line.should == 11
54
60
  end
61
+
62
+ it "should return if line" do
63
+ expect(@node.grep_node(sexp_type: :if).line).to eq 14
64
+ end
65
+
66
+ it "should return elsif line" do
67
+ expect(@node.grep_node(sexp_type: :elsif).line).to eq 16
68
+ end
69
+
70
+ it "should return if_mod line" do
71
+ expect(@node.grep_node(sexp_type: :if_mod).line).to eq 15
72
+ end
55
73
  end
56
74
 
57
75
  describe "grep_nodes" do
@@ -313,30 +331,32 @@ describe Sexp do
313
331
  describe "conditional_statement" do
314
332
  it "should get conditional statement of if" do
315
333
  node = parse_content("if true; end").grep_node(sexp_type: :if)
316
- node.conditional_statement.to_s.should == "true"
334
+ expect(node.conditional_statement.to_s).to eq "true"
317
335
  end
318
336
 
319
337
  it "should get conditional statement of unless" do
320
- node = parse_content("unless true; end").grep_node(sexp_type: :unless)
321
- node.conditional_statement.to_s.should == "true"
338
+ node = parse_content("unless false; end").grep_node(sexp_type: :unless)
339
+ expect(node.conditional_statement.to_s).to eq "false"
322
340
  end
323
341
 
324
342
  it "should get conditional statement of elsif" do
325
- content =<<-EOF
326
- if true
327
- elsif false
328
- end
329
- EOF
330
- node = parse_content(content).grep_node(sexp_type: :elsif)
331
- node.conditional_statement.to_s.should == "false"
343
+ node = parse_content("if true; elsif false; end").grep_node(sexp_type: :elsif)
344
+ expect(node.conditional_statement.to_s).to eq "false"
345
+ end
346
+
347
+ it "should get conditional statement of if_mod" do
348
+ node = parse_content("'OK' if true").grep_node(sexp_type: :if_mod)
349
+ expect(node.conditional_statement.to_s).to eq "true"
350
+ end
351
+
352
+ it "should get conditional statement of unless_mod" do
353
+ node = parse_content("'OK' unless false").grep_node(sexp_type: :unless_mod)
354
+ expect(node.conditional_statement.to_s).to eq "false"
332
355
  end
333
356
 
334
357
  it "should get conditional statement of ifop" do
335
- content =<<-EOF
336
- user ? user.name : nil
337
- EOF
338
- node = parse_content(content).grep_node(sexp_type: :ifop)
339
- node.conditional_statement.to_s.should == "user"
358
+ node = parse_content("true ? 'OK' : 'NO'").grep_node(sexp_type: :ifop)
359
+ expect(node.conditional_statement.to_s).to eq "true"
340
360
  end
341
361
  end
342
362
 
@@ -381,23 +401,38 @@ describe Sexp do
381
401
  end
382
402
 
383
403
  it "should get body of if" do
384
- node = parse_content("if true; puts 'hello world'; end").grep_node(sexp_type: :if)
385
- node.body.sexp_type.should == :stmts_add
404
+ node = parse_content("if true; 'OK'; end").grep_node(sexp_type: :if)
405
+ expect(node.body.sexp_type).to eq :stmts_add
386
406
  end
387
407
 
388
408
  it "should get body of elsif" do
389
- node = parse_content("if true; elsif true; puts 'hello world'; end").grep_node(sexp_type: :elsif)
390
- node.body.sexp_type.should == :stmts_add
409
+ node = parse_content("if true; elsif true; 'OK'; end").grep_node(sexp_type: :elsif)
410
+ expect(node.body.sexp_type).to eq :stmts_add
391
411
  end
392
412
 
393
413
  it "should get body of unless" do
394
- node = parse_content("unless true; puts 'hello world'; end").grep_node(sexp_type: :unless)
395
- node.body.sexp_type.should == :stmts_add
414
+ node = parse_content("unless true; 'OK'; end").grep_node(sexp_type: :unless)
415
+ expect(node.body.sexp_type).to eq :stmts_add
396
416
  end
397
417
 
398
418
  it "should get body of else" do
399
- node = parse_content("if true; else; puts 'hello world'; end").grep_node(sexp_type: :else)
400
- node.body.sexp_type.should == :stmts_add
419
+ node = parse_content("if true; else; 'OK'; end").grep_node(sexp_type: :else)
420
+ expect(node.body.sexp_type).to eq :stmts_add
421
+ end
422
+
423
+ it "should get body of if_mod" do
424
+ node = parse_content("'OK' if true").grep_node(sexp_type: :if_mod)
425
+ expect(node.body.to_s).to eq "OK"
426
+ end
427
+
428
+ it "should get body of unless_mod" do
429
+ node = parse_content("'OK' unless false").grep_node(sexp_type: :unless_mod)
430
+ expect(node.body.to_s).to eq "OK"
431
+ end
432
+
433
+ it "should get body of if_op" do
434
+ node = parse_content("true ? 'OK' : 'NO'").grep_node(sexp_type: :ifop)
435
+ expect(node.body.to_s).to eq "OK"
401
436
  end
402
437
  end
403
438
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: code_analyzer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-02 00:00:00.000000000 Z
12
+ date: 2012-12-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sexp_processor
@@ -43,6 +43,22 @@ dependencies:
43
43
  - - ! '>='
44
44
  - !ruby/object:Gem::Version
45
45
  version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rake
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
46
62
  description: a code analyzer tool which extracted from rails_best_practices, it helps
47
63
  you easily build your own code analyzer tool.
48
64
  email:
@@ -54,6 +70,7 @@ files:
54
70
  - .gitignore
55
71
  - .rspec
56
72
  - .rvmrc
73
+ - .travis.yml
57
74
  - Gemfile
58
75
  - LICENSE
59
76
  - README.md
@@ -90,12 +107,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
90
107
  - - ! '>='
91
108
  - !ruby/object:Gem::Version
92
109
  version: '0'
110
+ segments:
111
+ - 0
112
+ hash: -3700642731172846945
93
113
  required_rubygems_version: !ruby/object:Gem::Requirement
94
114
  none: false
95
115
  requirements:
96
116
  - - ! '>='
97
117
  - !ruby/object:Gem::Version
98
118
  version: '0'
119
+ segments:
120
+ - 0
121
+ hash: -3700642731172846945
99
122
  requirements: []
100
123
  rubyforge_project:
101
124
  rubygems_version: 1.8.24
@@ -111,4 +134,3 @@ test_files:
111
134
  - spec/code_analyzer/sexp_spec.rb
112
135
  - spec/code_analyzer/warning_spec.rb
113
136
  - spec/spec_helper.rb
114
- has_rdoc: