preek 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/preek +11 -10
- data/lib/preek.rb +25 -5
- data/lib/preek/smell_collector.rb +3 -2
- data/lib/preek/smell_file.rb +4 -2
- data/lib/preek/smell_reporter.rb +1 -0
- data/lib/preek/version.rb +1 -1
- data/spec/preek_spec.rb +35 -5
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 23aaf624b23cc383b727443a4638f9d8974465ff
|
4
|
+
data.tar.gz: ba4e3c93bd89f810a2ff58b8d76373fc39153f19
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f8e069e0498d2879120117dca4c13a4679981bef8757a0fe6293705a0c43d69971b64c3c0d7b30717e628601f8f00962b8b586fd9101c346646056732a9fa2ad
|
7
|
+
data.tar.gz: 331ad8be448eb115fc52bc5ef25f719af4a4f71ac4bc670fcd1d75c7e5b022015e6d7339353fa312ee20c7caac37f075ebd14728ffc1755ed7b5dcf8cb8e0b88
|
data/bin/preek
CHANGED
@@ -1,13 +1,14 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
require "preek"
|
3
3
|
|
4
|
-
unless ARGV.empty?
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
else
|
12
|
-
|
13
|
-
end
|
4
|
+
# unless ARGV.empty?
|
5
|
+
# preek = Preek::Preek.new
|
6
|
+
# if preek.respond_to? ARGV[0]
|
7
|
+
# preek.send ARGV.shift.to_sym, ARGV
|
8
|
+
# else
|
9
|
+
# preek.parse ARGV
|
10
|
+
# end
|
11
|
+
# else
|
12
|
+
# Preek::Preek.start
|
13
|
+
# end
|
14
|
+
Preek::Preek.start
|
data/lib/preek.rb
CHANGED
@@ -14,17 +14,23 @@ module Preek
|
|
14
14
|
say VERSION
|
15
15
|
end
|
16
16
|
|
17
|
-
desc 'FILE', 'Pretty format Reek output'
|
18
|
-
|
17
|
+
desc 'smell FILE(S)|DIR', 'Pretty format Reek output'
|
18
|
+
method_option :irresponsible,
|
19
|
+
type: :boolean,
|
20
|
+
aliases: '-i',
|
21
|
+
desc: 'include IrresponsibleModule smell in output.'
|
22
|
+
def smell(*args)
|
23
|
+
args ||= @args
|
24
|
+
@includes = options.keys.map {|key| _aliases[key.to_sym] }
|
19
25
|
files, @not_files = args.partition { |file| File.exists? file }
|
20
|
-
report_smells_for
|
26
|
+
report_smells_for(files, excludes) unless files.empty?
|
21
27
|
report_not_files
|
22
28
|
end
|
23
29
|
|
24
30
|
private
|
25
|
-
def report_smells_for
|
31
|
+
def report_smells_for(files, includes)
|
26
32
|
sources = Reek::Source::SourceLocator.new(files).all_sources
|
27
|
-
smelly_files = SmellCollector.new(sources).smelly_files
|
33
|
+
smelly_files = SmellCollector.new(sources, excludes).smelly_files
|
28
34
|
@reporter = SmellReporter.new(smelly_files)
|
29
35
|
@reporter.print_smells
|
30
36
|
end
|
@@ -32,5 +38,19 @@ module Preek
|
|
32
38
|
def report_not_files
|
33
39
|
say_status :error, "No such file(s) - #{@not_files*", "}.", :red unless @not_files.empty?
|
34
40
|
end
|
41
|
+
|
42
|
+
def _aliases
|
43
|
+
{
|
44
|
+
irresponsible: 'IrresponsibleModule'
|
45
|
+
}
|
46
|
+
end
|
47
|
+
|
48
|
+
def excludes
|
49
|
+
(exclude_list - @includes)#.map(&:to_s).map(&:capitalize)
|
50
|
+
end
|
51
|
+
|
52
|
+
def exclude_list
|
53
|
+
%w(IrresponsibleModule)
|
54
|
+
end
|
35
55
|
end
|
36
56
|
end
|
@@ -3,8 +3,9 @@ module Preek
|
|
3
3
|
require 'preek/smell_file'
|
4
4
|
# This is a 'Collector'
|
5
5
|
class SmellCollector
|
6
|
-
def initialize
|
6
|
+
def initialize(sources, excludes)
|
7
7
|
@sources = sources
|
8
|
+
@excludes = excludes
|
8
9
|
@files = examine_sources
|
9
10
|
end
|
10
11
|
|
@@ -16,7 +17,7 @@ module Preek
|
|
16
17
|
def examine_sources
|
17
18
|
@sources.map do |source|
|
18
19
|
smells = Reek::Examiner.new(source).smells
|
19
|
-
SmellFile.new
|
20
|
+
SmellFile.new(smells, @excludes) unless smells.empty?
|
20
21
|
end
|
21
22
|
end
|
22
23
|
end
|
data/lib/preek/smell_file.rb
CHANGED
@@ -2,13 +2,14 @@ module Preek
|
|
2
2
|
require 'preek/klass_collector'
|
3
3
|
# A smelly file
|
4
4
|
class SmellFile
|
5
|
-
def initialize(smells)
|
5
|
+
def initialize(smells, excludes)
|
6
6
|
@smells = smells
|
7
|
+
@excludes = excludes
|
7
8
|
@klass_collector = KlassCollector.new
|
9
|
+
add_smells_to_klass
|
8
10
|
end
|
9
11
|
|
10
12
|
def klasses
|
11
|
-
add_smells_to_klass
|
12
13
|
@klass_collector.get_klasses
|
13
14
|
end
|
14
15
|
|
@@ -19,6 +20,7 @@ module Preek
|
|
19
20
|
private
|
20
21
|
def add_smells_to_klass
|
21
22
|
@smells.each do |smell|
|
23
|
+
next if @excludes.include? smell.smell_class
|
22
24
|
@klass_collector.find(smell.klass).add_smell smell
|
23
25
|
end
|
24
26
|
end
|
data/lib/preek/smell_reporter.rb
CHANGED
data/lib/preek/version.rb
CHANGED
data/spec/preek_spec.rb
CHANGED
@@ -14,7 +14,8 @@ describe Preek::Preek do
|
|
14
14
|
end
|
15
15
|
|
16
16
|
describe "#parse" do
|
17
|
-
let(:output) { capture(:stdout) { subject.parse(args) } }
|
17
|
+
let(:output) { capture(:stdout) { subject.parse(*args) } }
|
18
|
+
let(:args) { ['i/am/not/a_file'] }
|
18
19
|
|
19
20
|
context "with non-existing file in ARGS" do
|
20
21
|
let(:args) { ['i/am/not/a_file'] }
|
@@ -35,16 +36,40 @@ describe Preek::Preek do
|
|
35
36
|
|
36
37
|
context "when given file has Irresponsible smell" do
|
37
38
|
let(:args){ [test_file('irresponsible')] }
|
39
|
+
it "output contains 'success! No smells'" do
|
40
|
+
output.should include("No smells")
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
context "when given file has Irresponsible smell with --irresponsible options" do
|
45
|
+
let(:args){ [test_file('irresponsible')] }
|
46
|
+
|
47
|
+
before :each do
|
48
|
+
subject.options = {irresponsible: true}
|
49
|
+
end
|
50
|
+
|
38
51
|
it "output contains 'Irresponsible'" do
|
39
52
|
output.should include("Irresponsible")
|
40
53
|
end
|
41
|
-
|
42
|
-
output.should include(args[0])
|
43
|
-
end
|
54
|
+
|
44
55
|
end
|
45
56
|
|
46
57
|
context "when given a file with two smelly classes" do
|
47
58
|
let(:args){ [test_file('two_smelly_classes')] }
|
59
|
+
it "output contains one classnames" do
|
60
|
+
output.should include('SecondSmelly')
|
61
|
+
end
|
62
|
+
it "output contains one smell" do
|
63
|
+
output.should include('UncommunicativeMethodName')
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
context "when given a file with two smelly classes with --irresponsible options" do
|
68
|
+
let(:args){ [test_file('two_smelly_classes')] }
|
69
|
+
before :each do
|
70
|
+
subject.options = {irresponsible: true}
|
71
|
+
end
|
72
|
+
|
48
73
|
it "output contains both classnames" do
|
49
74
|
output.should include('FirstSmelly', 'SecondSmelly')
|
50
75
|
end
|
@@ -53,15 +78,20 @@ describe Preek::Preek do
|
|
53
78
|
end
|
54
79
|
end
|
55
80
|
|
56
|
-
context "when given a file with two different smells" do
|
81
|
+
context "when given a file with two different smells with --irresponsible options" do
|
57
82
|
let(:args){ [test_file('irresponsible_and_lazy')] }
|
58
83
|
it "output contains both smells" do
|
84
|
+
subject.options = {irresponsible: true}
|
59
85
|
output.should include('IrresponsibleModule', 'UncommunicativeMethodName')
|
60
86
|
end
|
61
87
|
end
|
62
88
|
|
63
89
|
context "when given two smelly files" do
|
64
90
|
let(:args){ [test_file('too_many_statements'), test_file('two_smelly_classes')] }
|
91
|
+
before :each do
|
92
|
+
subject.options = {irresponsible: true}
|
93
|
+
end
|
94
|
+
|
65
95
|
it "output contains all smells" do
|
66
96
|
output.should include('IrresponsibleModule', 'UncommunicativeMethodName', 'TooManyStatements')
|
67
97
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: preek
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jon Neverland
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-07-
|
11
|
+
date: 2013-07-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|