pelusa 0.1.1 → 0.2.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.
- data/Gemfile +2 -0
- data/lib/pelusa.rb +1 -1
- data/lib/pelusa/cli.rb +10 -1
- data/lib/pelusa/configuration.rb +8 -21
- data/lib/pelusa/lint/demeter_law.rb +7 -1
- data/lib/pelusa/runner.rb +1 -10
- data/lib/pelusa/version.rb +1 -1
- data/test/pelusa/cli_test.rb +24 -0
- data/test/pelusa/configuration_test.rb +1 -12
- data/test/pelusa/lint/demeter_law_test.rb +42 -0
- data/test/pelusa/runner_test.rb +4 -10
- metadata +52 -30
data/Gemfile
CHANGED
data/lib/pelusa.rb
CHANGED
data/lib/pelusa/cli.rb
CHANGED
@@ -14,7 +14,16 @@ module Pelusa
|
|
14
14
|
_files = Dir["**/*.rb"]
|
15
15
|
end
|
16
16
|
|
17
|
-
Pelusa.run(_files)
|
17
|
+
reporters = Pelusa.run(_files)
|
18
|
+
|
19
|
+
reporters.first.class.print_banner unless reporters.empty?
|
20
|
+
|
21
|
+
exit_code = 0
|
22
|
+
reporters.each do |reporter|
|
23
|
+
reporter.report
|
24
|
+
exit_code = 1 unless reporter.successful?
|
25
|
+
end
|
26
|
+
exit_code
|
18
27
|
end
|
19
28
|
|
20
29
|
def files
|
data/lib/pelusa/configuration.rb
CHANGED
@@ -4,28 +4,20 @@ module Pelusa
|
|
4
4
|
# Examples
|
5
5
|
#
|
6
6
|
# configuration = Pelusa::Configuration.new('my_pelusa_config.yml')
|
7
|
-
# configuration.present? # => true
|
8
7
|
#
|
9
8
|
class Configuration
|
10
|
-
YAML_PATH
|
9
|
+
YAML_PATH = './.pelusa.yml'
|
10
|
+
DEFAULT_SOURCES = 'lib/**/*.rb'
|
11
11
|
|
12
12
|
# Public: Initializes a configuration instance
|
13
13
|
#
|
14
14
|
# yaml_path - optional path to the configuration file
|
15
15
|
def initialize(yaml_path = YAML_PATH)
|
16
|
-
if File.exist?(yaml_path)
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
# Public: Returns if a custom configuration is present
|
22
|
-
#
|
23
|
-
# Examples
|
24
|
-
#
|
25
|
-
# Pelusa.configuration.present? # => true
|
26
|
-
#
|
27
|
-
def present?
|
28
|
-
not @_configuration.nil?
|
16
|
+
@_configuration = if File.exist?(yaml_path)
|
17
|
+
YAML.load_file(yaml_path)
|
18
|
+
else
|
19
|
+
{}
|
20
|
+
end.freeze
|
29
21
|
end
|
30
22
|
|
31
23
|
# Public: Returns custom configuration for the given lint
|
@@ -46,12 +38,7 @@ module Pelusa
|
|
46
38
|
# Pelusa.configuration.sources # => lib/**/*.rb
|
47
39
|
#
|
48
40
|
def sources
|
49
|
-
|
50
|
-
if present?
|
51
|
-
@_configuration.fetch('sources') { default }
|
52
|
-
else
|
53
|
-
default
|
54
|
-
end
|
41
|
+
@_configuration.fetch('sources') { DEFAULT_SOURCES }
|
55
42
|
end
|
56
43
|
|
57
44
|
# Public: Returns an Array of enabled lints
|
@@ -25,11 +25,17 @@ module Pelusa
|
|
25
25
|
def iterate_lines!(klass)
|
26
26
|
iterator = Iterator.new do |node|
|
27
27
|
if node.is_a?(Rubinius::AST::Send) && node.receiver.is_a?(Rubinius::AST::Send)
|
28
|
-
@violations << node.line
|
28
|
+
@violations << node.line unless white_listed?(node.receiver.name)
|
29
29
|
end
|
30
30
|
end
|
31
31
|
Array(klass).each(&iterator)
|
32
32
|
end
|
33
|
+
|
34
|
+
def white_listed? method
|
35
|
+
[Class, Fixnum, Enumerable].any? do |enclosing_module|
|
36
|
+
enclosing_module.instance_methods.any? {|instance_method| instance_method == method }
|
37
|
+
end
|
38
|
+
end
|
33
39
|
end
|
34
40
|
end
|
35
41
|
end
|
data/lib/pelusa/runner.rb
CHANGED
@@ -14,18 +14,9 @@ module Pelusa
|
|
14
14
|
#
|
15
15
|
# Returns an Array of Reports of those file runs.
|
16
16
|
def run(files)
|
17
|
-
|
17
|
+
Array(files).map do |file|
|
18
18
|
run_file(file)
|
19
19
|
end
|
20
|
-
@reporter.print_banner
|
21
|
-
|
22
|
-
exit_code = 0
|
23
|
-
|
24
|
-
reporters.each do |reporter|
|
25
|
-
reporter.report
|
26
|
-
exit_code = 1 unless reporter.successful?
|
27
|
-
end
|
28
|
-
exit_code
|
29
20
|
end
|
30
21
|
|
31
22
|
# Public: Runs the analyzer on a single file.
|
data/lib/pelusa/version.rb
CHANGED
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Pelusa
|
4
|
+
describe Cli do
|
5
|
+
describe "#run" do
|
6
|
+
before do
|
7
|
+
@report = stub(empty?: false, report: true, class: Reporter)
|
8
|
+
Pelusa.stubs(:run).returns [@report]
|
9
|
+
end
|
10
|
+
describe 'when the reports are successful' do
|
11
|
+
it 'returns 0' do
|
12
|
+
@report.stubs(successful?: true)
|
13
|
+
Cli.new.run().must_equal 0
|
14
|
+
end
|
15
|
+
end
|
16
|
+
describe 'when the reports have failed' do
|
17
|
+
it 'returns 1' do
|
18
|
+
@report.stubs(successful?: false)
|
19
|
+
Cli.new.run().must_equal 1
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -6,17 +6,6 @@ module Pelusa
|
|
6
6
|
Pelusa::Configuration.new("#{FIXTURES_PATH}/sample_config_one.yml")
|
7
7
|
end
|
8
8
|
|
9
|
-
describe "#present?" do
|
10
|
-
it "returns false when configuration doesn't file exists" do
|
11
|
-
configuration = Pelusa::Configuration.new("#{FIXTURES_PATH}/not_here.yml")
|
12
|
-
configuration.present?.must_equal(false)
|
13
|
-
end
|
14
|
-
|
15
|
-
it "returns false when configuration file exists" do
|
16
|
-
configuration.present?.must_equal(true)
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
9
|
describe '#sources' do
|
21
10
|
it 'returns path to sources' do
|
22
11
|
configuration.sources.must_equal 'lib/**/*.rb'
|
@@ -25,7 +14,7 @@ module Pelusa
|
|
25
14
|
describe 'by default' do
|
26
15
|
it 'returns lib/**/*.rb' do
|
27
16
|
empty_configuration = Pelusa::Configuration.new("unexistent_yml")
|
28
|
-
empty_configuration.sources.must_equal
|
17
|
+
empty_configuration.sources.must_equal Pelusa::Configuration::DEFAULT_SOURCES
|
29
18
|
end
|
30
19
|
end
|
31
20
|
end
|
@@ -36,6 +36,48 @@ module Pelusa
|
|
36
36
|
analysis.failed?.must_equal true
|
37
37
|
end
|
38
38
|
end
|
39
|
+
|
40
|
+
describe 'when instantiating a class' do
|
41
|
+
it 'returns a SuccessAnalysis' do
|
42
|
+
klass = """
|
43
|
+
class Foo
|
44
|
+
def execute
|
45
|
+
Bar.new.execute
|
46
|
+
end
|
47
|
+
end""".to_ast
|
48
|
+
|
49
|
+
analysis = @lint.check(klass)
|
50
|
+
analysis.successful?.must_equal true
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe 'when chaining operations on an Enumerable' do
|
55
|
+
it 'returns a SuccessAnalysis' do
|
56
|
+
klass = """
|
57
|
+
class Foo
|
58
|
+
def execute
|
59
|
+
[1,2,3].map(&:object_id).map(&:object_id)
|
60
|
+
end
|
61
|
+
end""".to_ast
|
62
|
+
|
63
|
+
analysis = @lint.check(klass)
|
64
|
+
analysis.successful?.must_equal true
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
describe 'when chaining Fixnum operations' do
|
70
|
+
it 'returns a SuccessAnalysis' do
|
71
|
+
klass = """
|
72
|
+
class Foo
|
73
|
+
def execute
|
74
|
+
1 + 2 + 3 + 4
|
75
|
+
end
|
76
|
+
end""".to_ast
|
77
|
+
|
78
|
+
analysis = @lint.check(klass)
|
79
|
+
analysis.successful?.must_equal true
|
80
|
+
end
|
39
81
|
end
|
40
82
|
end
|
41
83
|
end
|
data/test/pelusa/runner_test.rb
CHANGED
@@ -9,18 +9,12 @@ module Pelusa
|
|
9
9
|
Analyzer.stubs(:new).returns analyzer
|
10
10
|
end
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
@report.stubs(successful?: true)
|
15
|
-
Pelusa.run(__FILE__).must_equal 0
|
16
|
-
end
|
12
|
+
it 'runs a single file' do
|
13
|
+
Pelusa.run(__FILE__).must_equal [@report]
|
17
14
|
end
|
18
15
|
|
19
|
-
|
20
|
-
|
21
|
-
@report.stubs(successful?: false)
|
22
|
-
Pelusa.run(__FILE__).must_equal 1
|
23
|
-
end
|
16
|
+
it 'runs multiple files' do
|
17
|
+
Pelusa.run([__FILE__, __FILE__]).must_equal [@report, @report]
|
24
18
|
end
|
25
19
|
end
|
26
20
|
end
|
metadata
CHANGED
@@ -1,35 +1,46 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: pelusa
|
3
|
-
version: !ruby/object:Gem::Version
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 2380615109590600174
|
4
5
|
prerelease:
|
5
|
-
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 2
|
9
|
+
- 0
|
10
|
+
version: 0.2.0
|
6
11
|
platform: ruby
|
7
|
-
authors:
|
12
|
+
authors:
|
8
13
|
- Josep M. Bach
|
9
14
|
autorequire:
|
10
15
|
bindir: bin
|
11
16
|
cert_chain: []
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
none: false
|
17
|
-
requirements:
|
18
|
-
- - ! '>='
|
19
|
-
- !ruby/object:Gem::Version
|
20
|
-
version: '0'
|
21
|
-
prerelease: false
|
22
|
-
requirement: *6620
|
17
|
+
|
18
|
+
date: 2012-03-23 00:00:00 Z
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
23
21
|
name: mocha
|
22
|
+
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"
|
24
32
|
type: :development
|
33
|
+
version_requirements: *id001
|
25
34
|
description: Static analysis Lint-type tool to improve your OO Ruby code
|
26
|
-
email:
|
35
|
+
email:
|
27
36
|
- josep.m.bach@gmail.com
|
28
|
-
executables:
|
37
|
+
executables:
|
29
38
|
- pelusa
|
30
39
|
extensions: []
|
40
|
+
|
31
41
|
extra_rdoc_files: []
|
32
|
-
|
42
|
+
|
43
|
+
files:
|
33
44
|
- .gitignore
|
34
45
|
- .pelusa.yml
|
35
46
|
- .rvmrc
|
@@ -67,6 +78,7 @@ files:
|
|
67
78
|
- test/pelusa/analysis_test.rb
|
68
79
|
- test/pelusa/analyzer_test.rb
|
69
80
|
- test/pelusa/class_analyzer_test.rb
|
81
|
+
- test/pelusa/cli_test.rb
|
70
82
|
- test/pelusa/configuration_test.rb
|
71
83
|
- test/pelusa/iterator_test.rb
|
72
84
|
- test/pelusa/lint/case_statements_test.rb
|
@@ -85,34 +97,44 @@ files:
|
|
85
97
|
- test/test_helper.rb
|
86
98
|
homepage: http://github.com/codegram/pelusa
|
87
99
|
licenses: []
|
100
|
+
|
88
101
|
post_install_message:
|
89
102
|
rdoc_options: []
|
90
|
-
|
103
|
+
|
104
|
+
require_paths:
|
91
105
|
- lib
|
92
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
106
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
93
107
|
none: false
|
94
|
-
requirements:
|
95
|
-
- -
|
96
|
-
- !ruby/object:Gem::Version
|
97
|
-
|
98
|
-
|
108
|
+
requirements:
|
109
|
+
- - ">="
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
hash: 2002549777813010636
|
112
|
+
segments:
|
113
|
+
- 0
|
114
|
+
version: "0"
|
115
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
99
116
|
none: false
|
100
|
-
requirements:
|
101
|
-
- -
|
102
|
-
- !ruby/object:Gem::Version
|
103
|
-
|
117
|
+
requirements:
|
118
|
+
- - ">="
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
hash: 2002549777813010636
|
121
|
+
segments:
|
122
|
+
- 0
|
123
|
+
version: "0"
|
104
124
|
requirements: []
|
125
|
+
|
105
126
|
rubyforge_project: pelusa
|
106
127
|
rubygems_version: 1.8.12
|
107
128
|
signing_key:
|
108
129
|
specification_version: 3
|
109
130
|
summary: Static analysis Lint-type tool to improve your OO Ruby code
|
110
|
-
test_files:
|
131
|
+
test_files:
|
111
132
|
- test/pelusa_test.rb
|
112
133
|
- test/test_helper.rb
|
113
134
|
- test/pelusa/analysis_test.rb
|
114
135
|
- test/pelusa/analyzer_test.rb
|
115
136
|
- test/pelusa/class_analyzer_test.rb
|
137
|
+
- test/pelusa/cli_test.rb
|
116
138
|
- test/pelusa/configuration_test.rb
|
117
139
|
- test/pelusa/iterator_test.rb
|
118
140
|
- test/pelusa/runner_test.rb
|