pelusa 0.2.0 → 0.2.1
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.
- data/lib/pelusa/lint.rb +3 -1
- data/lib/pelusa/lint/eval_usage.rb +42 -0
- data/lib/pelusa/version.rb +1 -1
- data/test/pelusa/lint/eval_usage_test.rb +58 -0
- metadata +32 -49
data/lib/pelusa/lint.rb
CHANGED
@@ -9,6 +9,7 @@ require 'pelusa/lint/collection_wrappers'
|
|
9
9
|
require 'pelusa/lint/short_identifiers'
|
10
10
|
require 'pelusa/lint/case_statements'
|
11
11
|
require 'pelusa/lint/many_arguments'
|
12
|
+
require 'pelusa/lint/eval_usage'
|
12
13
|
|
13
14
|
module Pelusa
|
14
15
|
# Public: A Lint is a quality standard, applicable on a given piece of code to
|
@@ -25,7 +26,8 @@ module Pelusa
|
|
25
26
|
Properties,
|
26
27
|
CollectionWrappers,
|
27
28
|
ShortIdentifiers,
|
28
|
-
ManyArguments
|
29
|
+
ManyArguments,
|
30
|
+
EvalUsage
|
29
31
|
]
|
30
32
|
end
|
31
33
|
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Pelusa
|
4
|
+
module Lint
|
5
|
+
class EvalUsage
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
@violations = Set.new
|
9
|
+
end
|
10
|
+
|
11
|
+
def check(klass)
|
12
|
+
iterate_lines!(klass)
|
13
|
+
|
14
|
+
if @violations.empty?
|
15
|
+
SuccessfulAnalysis.new(name)
|
16
|
+
else
|
17
|
+
FailedAnalysis.new(name, @violations) do |violations|
|
18
|
+
"There are #{violations.length} eval statement in lines #{violations.to_a.join(', ')}"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def name
|
26
|
+
"Doesn't use eval statement"
|
27
|
+
end
|
28
|
+
|
29
|
+
def iterate_lines!(klass)
|
30
|
+
iterator = Iterator.new do |node|
|
31
|
+
@violations << node.line if eval_violation?(node)
|
32
|
+
end
|
33
|
+
Array(klass).each(&iterator)
|
34
|
+
end
|
35
|
+
|
36
|
+
def eval_violation?(node)
|
37
|
+
node.is_a?(Rubinius::AST::SendWithArguments) && node.name == :eval && node.receiver.is_a?(Rubinius::AST::Self)
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
data/lib/pelusa/version.rb
CHANGED
@@ -0,0 +1,58 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'test_helper'
|
3
|
+
|
4
|
+
module Pelusa
|
5
|
+
module Lint
|
6
|
+
describe EvalUsage do
|
7
|
+
before { @lint = EvalUsage.new }
|
8
|
+
|
9
|
+
describe '#check' do
|
10
|
+
describe 'when class does not use eval statement' do
|
11
|
+
it 'return successful analysis' do
|
12
|
+
klass_str = <<RUBY
|
13
|
+
class WithoutEval
|
14
|
+
def initialize
|
15
|
+
@good = true
|
16
|
+
end
|
17
|
+
end
|
18
|
+
RUBY
|
19
|
+
klass = klass_str.to_ast
|
20
|
+
analysis = @lint.check(klass)
|
21
|
+
analysis.successful?.must_equal true
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe 'when class use eval statement' do
|
26
|
+
it 'return failed analysis' do
|
27
|
+
klass_str = <<RUBY
|
28
|
+
class WithEval
|
29
|
+
def initialize
|
30
|
+
eval "@good = false"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
RUBY
|
34
|
+
klass = klass_str.to_ast
|
35
|
+
analysis = @lint.check(klass)
|
36
|
+
analysis.failed?.must_equal true
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe 'when class define method named eval' do
|
41
|
+
it 'return successful analysis' do
|
42
|
+
klass_str = <<RUBY
|
43
|
+
class WithEvalUse
|
44
|
+
def initialize
|
45
|
+
@other_obj = Object.new
|
46
|
+
@other_obj.eval "boom"
|
47
|
+
end
|
48
|
+
end
|
49
|
+
RUBY
|
50
|
+
klass = klass_str.to_ast
|
51
|
+
analysis = @lint.check(klass)
|
52
|
+
analysis.successful?.must_equal true
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
metadata
CHANGED
@@ -1,46 +1,35 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: pelusa
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.1
|
5
5
|
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 2
|
9
|
-
- 0
|
10
|
-
version: 0.2.0
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Josep M. Bach
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
12
|
+
date: 2012-05-29 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
requirement: &7212 !ruby/object:Gem::Requirement
|
16
|
+
none: false
|
17
|
+
requirements:
|
18
|
+
- - ! '>='
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '0'
|
21
21
|
name: mocha
|
22
|
+
version_requirements: *7212
|
22
23
|
prerelease: false
|
23
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
-
none: false
|
25
|
-
requirements:
|
26
|
-
- - ">="
|
27
|
-
- !ruby/object:Gem::Version
|
28
|
-
hash: 2002549777813010636
|
29
|
-
segments:
|
30
|
-
- 0
|
31
|
-
version: "0"
|
32
24
|
type: :development
|
33
|
-
version_requirements: *id001
|
34
25
|
description: Static analysis Lint-type tool to improve your OO Ruby code
|
35
|
-
email:
|
26
|
+
email:
|
36
27
|
- josep.m.bach@gmail.com
|
37
|
-
executables:
|
28
|
+
executables:
|
38
29
|
- pelusa
|
39
30
|
extensions: []
|
40
|
-
|
41
31
|
extra_rdoc_files: []
|
42
|
-
|
43
|
-
files:
|
32
|
+
files:
|
44
33
|
- .gitignore
|
45
34
|
- .pelusa.yml
|
46
35
|
- .rvmrc
|
@@ -61,6 +50,7 @@ files:
|
|
61
50
|
- lib/pelusa/lint/collection_wrappers.rb
|
62
51
|
- lib/pelusa/lint/demeter_law.rb
|
63
52
|
- lib/pelusa/lint/else_clauses.rb
|
53
|
+
- lib/pelusa/lint/eval_usage.rb
|
64
54
|
- lib/pelusa/lint/indentation_level.rb
|
65
55
|
- lib/pelusa/lint/instance_variables.rb
|
66
56
|
- lib/pelusa/lint/line_restriction.rb
|
@@ -85,6 +75,7 @@ files:
|
|
85
75
|
- test/pelusa/lint/collection_wrappers_test.rb
|
86
76
|
- test/pelusa/lint/demeter_law_test.rb
|
87
77
|
- test/pelusa/lint/else_clauses_test.rb
|
78
|
+
- test/pelusa/lint/eval_usage_test.rb
|
88
79
|
- test/pelusa/lint/indentation_level_test.rb
|
89
80
|
- test/pelusa/lint/instance_variables_test.rb
|
90
81
|
- test/pelusa/lint/line_restriction_test.rb
|
@@ -97,38 +88,29 @@ files:
|
|
97
88
|
- test/test_helper.rb
|
98
89
|
homepage: http://github.com/codegram/pelusa
|
99
90
|
licenses: []
|
100
|
-
|
101
91
|
post_install_message:
|
102
92
|
rdoc_options: []
|
103
|
-
|
104
|
-
require_paths:
|
93
|
+
require_paths:
|
105
94
|
- lib
|
106
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
95
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
107
96
|
none: false
|
108
|
-
requirements:
|
109
|
-
- -
|
110
|
-
- !ruby/object:Gem::Version
|
111
|
-
|
112
|
-
|
113
|
-
- 0
|
114
|
-
version: "0"
|
115
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
97
|
+
requirements:
|
98
|
+
- - ! '>='
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: '0'
|
101
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
116
102
|
none: false
|
117
|
-
requirements:
|
118
|
-
- -
|
119
|
-
- !ruby/object:Gem::Version
|
120
|
-
|
121
|
-
segments:
|
122
|
-
- 0
|
123
|
-
version: "0"
|
103
|
+
requirements:
|
104
|
+
- - ! '>='
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: '0'
|
124
107
|
requirements: []
|
125
|
-
|
126
108
|
rubyforge_project: pelusa
|
127
109
|
rubygems_version: 1.8.12
|
128
110
|
signing_key:
|
129
111
|
specification_version: 3
|
130
112
|
summary: Static analysis Lint-type tool to improve your OO Ruby code
|
131
|
-
test_files:
|
113
|
+
test_files:
|
132
114
|
- test/pelusa_test.rb
|
133
115
|
- test/test_helper.rb
|
134
116
|
- test/pelusa/analysis_test.rb
|
@@ -142,6 +124,7 @@ test_files:
|
|
142
124
|
- test/pelusa/lint/collection_wrappers_test.rb
|
143
125
|
- test/pelusa/lint/demeter_law_test.rb
|
144
126
|
- test/pelusa/lint/else_clauses_test.rb
|
127
|
+
- test/pelusa/lint/eval_usage_test.rb
|
145
128
|
- test/pelusa/lint/indentation_level_test.rb
|
146
129
|
- test/pelusa/lint/instance_variables_test.rb
|
147
130
|
- test/pelusa/lint/line_restriction_test.rb
|