preek 1.1.0 → 1.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.
- checksums.yaml +4 -4
- data/README.md +3 -2
- data/lib/preek.rb +4 -5
- data/lib/preek/cli.rb +24 -5
- data/lib/preek/examiner.rb +68 -0
- data/lib/preek/output.rb +36 -0
- data/lib/preek/report.rb +64 -0
- data/lib/preek/smell_file.rb +7 -1
- data/lib/preek/smell_klass.rb +1 -1
- data/lib/preek/version.rb +1 -1
- data/preek.gemspec +1 -1
- data/spec/cli_spec.rb +74 -91
- data/spec/spec_helper.rb +1 -0
- metadata +12 -11
- data/lib/preek/smell_collector.rb +0 -45
- data/lib/preek/smell_reporter.rb +0 -64
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6a2898d250cb8cea642a90c538ce337b21b582fb
|
4
|
+
data.tar.gz: 963cbb7dcebd619e3da7a47fd2fdce46d767a406
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0f33bf0471e6fde2f572c62bd546da8611ef8be0f54ce4e81bcfaac2da2335c9e55ae2f4b4cfea0300a503c89272ec1444ea8c95bb7cad4cedfb610e465bd8c6
|
7
|
+
data.tar.gz: 3a51ab71c58530be58fd33affcf172ac7b4f8abc781050d73f02da3fb103d04a71a8bf49c9bbae1d20af7faacfd4575d8769ee2e8b42c6f3753fb205c82f0ed4
|
data/README.md
CHANGED
@@ -31,8 +31,9 @@ Usage:
|
|
31
31
|
preek smell FILE(S)|DIR
|
32
32
|
|
33
33
|
Options:
|
34
|
-
-i, [--irresponsible] #
|
35
|
-
|
34
|
+
-i, [--irresponsible] # Include IrresponsibleModule smell in output.
|
35
|
+
-c, [--compact] # Compact output.
|
36
|
+
-v, [--verbose] # Report files with no smells
|
36
37
|
|
37
38
|
Commands:
|
38
39
|
preek help [COMMAND] # Describe available commands or one specific command
|
data/lib/preek.rb
CHANGED
@@ -1,11 +1,10 @@
|
|
1
1
|
module Preek
|
2
2
|
require 'preek/version'
|
3
|
-
require 'preek/
|
4
|
-
require 'preek/
|
3
|
+
require 'preek/examiner'
|
4
|
+
require 'preek/report'
|
5
|
+
require 'preek/output'
|
5
6
|
|
6
7
|
def self.Smell(filenames, excludes = [])
|
7
|
-
|
8
|
-
smelly_files = SmellCollector.new(files, excludes).smelly_files
|
9
|
-
SmellReporter.new(smelly_files, not_files).print_result
|
8
|
+
Examiner.new(filenames, excludes).perform
|
10
9
|
end
|
11
10
|
end
|
data/lib/preek/cli.rb
CHANGED
@@ -1,8 +1,5 @@
|
|
1
1
|
require 'thor'
|
2
|
-
|
3
2
|
require 'preek/version'
|
4
|
-
require 'preek/smell_collector'
|
5
|
-
require 'preek/smell_reporter'
|
6
3
|
|
7
4
|
module Preek
|
8
5
|
|
@@ -16,15 +13,37 @@ module Preek
|
|
16
13
|
end
|
17
14
|
|
18
15
|
desc 'smell FILE(S)|DIR', 'Pretty format Reek output'
|
16
|
+
|
19
17
|
method_option :irresponsible,
|
20
18
|
type: :boolean,
|
21
19
|
aliases: '-i',
|
22
|
-
desc: '
|
20
|
+
desc: 'Include IrresponsibleModule smell in output.'
|
21
|
+
|
22
|
+
method_option :compact,
|
23
|
+
type: :boolean,
|
24
|
+
aliases: '-c',
|
25
|
+
desc: 'Compact output.'
|
26
|
+
|
27
|
+
method_option :verbose,
|
28
|
+
type: :boolean,
|
29
|
+
aliases: '-v',
|
30
|
+
desc: 'Report files with no smells.'
|
31
|
+
|
32
|
+
|
23
33
|
def smell(*args)
|
24
|
-
|
34
|
+
Examiner.new(args, excludes, reporter: reporter, output: output).perform
|
25
35
|
end
|
26
36
|
|
27
37
|
private
|
38
|
+
|
39
|
+
def reporter
|
40
|
+
options[:verbose] ? VerboseReport : QuietReport
|
41
|
+
end
|
42
|
+
|
43
|
+
def output
|
44
|
+
options[:compact] ? CompactOutput : Output
|
45
|
+
end
|
46
|
+
|
28
47
|
def _aliases
|
29
48
|
{
|
30
49
|
irresponsible: 'IrresponsibleModule'
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'reek/examiner'
|
2
|
+
|
3
|
+
module Preek
|
4
|
+
class Examiner
|
5
|
+
def initialize(files, excludes = [], options = {})
|
6
|
+
@files = files
|
7
|
+
@excludes = excludes
|
8
|
+
@reporter = options[:reporter] || VerboseReport
|
9
|
+
output_class = options[:output] || Output
|
10
|
+
@output = output_class.new
|
11
|
+
@total_smells = 0
|
12
|
+
end
|
13
|
+
|
14
|
+
def perform
|
15
|
+
examine_and_report
|
16
|
+
report_totals if totals_to_report?
|
17
|
+
@output.print_line
|
18
|
+
report_non_existing if non_existing_files?
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
def examine_and_report
|
23
|
+
sources.each do |source|
|
24
|
+
examiner = Reek::Examiner.new(source)
|
25
|
+
filter_excludes_from(examiner)
|
26
|
+
@reporter.new(examiner, @output).report
|
27
|
+
@total_smells += examiner.smells_count
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def filter_excludes_from(examiner)
|
32
|
+
examiner.smells.delete_if do |smell|
|
33
|
+
@excludes.include? smell.smell_class
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def totals_to_report?
|
38
|
+
return false if @reporter.verbose? || @sources.count == 0
|
39
|
+
@total_smells == 0
|
40
|
+
end
|
41
|
+
|
42
|
+
def report_totals
|
43
|
+
@output.print_line
|
44
|
+
@output.green :success, %(No smells detected)
|
45
|
+
end
|
46
|
+
|
47
|
+
def report_non_existing
|
48
|
+
@output.red :error, %{No such file(s) - #{non_existing_files.join(', ')}.\n}
|
49
|
+
@output.print_line
|
50
|
+
end
|
51
|
+
|
52
|
+
def existing_files
|
53
|
+
@existing_files ||= @files.select {|file| File.exists? file}
|
54
|
+
end
|
55
|
+
|
56
|
+
def non_existing_files?
|
57
|
+
!non_existing_files.empty?
|
58
|
+
end
|
59
|
+
|
60
|
+
def non_existing_files
|
61
|
+
@files - existing_files
|
62
|
+
end
|
63
|
+
|
64
|
+
def sources
|
65
|
+
@sources ||= Reek::Source::SourceLocator.new(existing_files).all_sources
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
data/lib/preek/output.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'thor/shell/color'
|
2
|
+
module Preek
|
3
|
+
class Output < Thor::Shell::Color
|
4
|
+
def status(*args)
|
5
|
+
say_status *args
|
6
|
+
end
|
7
|
+
|
8
|
+
def print_line
|
9
|
+
say "\n\t#{'-'*60}\n\n"
|
10
|
+
end
|
11
|
+
|
12
|
+
def blue(*args)
|
13
|
+
status *args, :blue
|
14
|
+
end
|
15
|
+
|
16
|
+
def green(*args)
|
17
|
+
status *args, :green
|
18
|
+
end
|
19
|
+
|
20
|
+
def red(*args)
|
21
|
+
status *args, :red
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
class CompactOutput < Output
|
26
|
+
def status(title, text, color = nil)
|
27
|
+
title = title.to_s + ": " if title.is_a?(Symbol)
|
28
|
+
say title, color, false
|
29
|
+
say text
|
30
|
+
end
|
31
|
+
|
32
|
+
def print_line
|
33
|
+
say "\n-\n\n"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/lib/preek/report.rb
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'preek/ext/smell_warning'
|
2
|
+
require 'preek/smell_file'
|
3
|
+
require 'preek/smell_klass'
|
4
|
+
module Preek
|
5
|
+
class VerboseReport
|
6
|
+
def self.verbose?
|
7
|
+
true
|
8
|
+
end
|
9
|
+
|
10
|
+
def initialize(examiner, output)
|
11
|
+
@examiner, @output = examiner, output
|
12
|
+
end
|
13
|
+
|
14
|
+
def report
|
15
|
+
print_header
|
16
|
+
if @examiner.smelly?
|
17
|
+
report_smells
|
18
|
+
else
|
19
|
+
report_success
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def print_header
|
26
|
+
@output.print_line
|
27
|
+
@output.blue :file, "#{@examiner.description}\n"
|
28
|
+
end
|
29
|
+
|
30
|
+
def smell_file
|
31
|
+
SmellFile.new(@examiner)
|
32
|
+
end
|
33
|
+
|
34
|
+
def report_smells
|
35
|
+
smell_file.klasses do |klass|
|
36
|
+
@output.green :class, klass.name
|
37
|
+
@output.red :smells, ''
|
38
|
+
klass.smells.each &print_smell
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def print_smell
|
43
|
+
lambda {|smell| @output.status nil, smell }
|
44
|
+
end
|
45
|
+
|
46
|
+
def print_klass_smells(smells)
|
47
|
+
smells.each {|smell| @output.status nil, smell }
|
48
|
+
end
|
49
|
+
|
50
|
+
def report_success
|
51
|
+
@output.green :success, "No smells detected.\n"
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
class QuietReport < VerboseReport
|
56
|
+
def self.verbose?
|
57
|
+
false
|
58
|
+
end
|
59
|
+
|
60
|
+
def report
|
61
|
+
print_header && report_smells if @examiner.smelly?
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
data/lib/preek/smell_file.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
module Preek
|
2
2
|
# A smelly file
|
3
3
|
class SmellFile
|
4
|
-
attr_reader :klasses
|
5
4
|
|
6
5
|
def initialize(examiner)
|
7
6
|
@examiner = examiner
|
@@ -15,6 +14,13 @@ module Preek
|
|
15
14
|
|
16
15
|
alias :filename :file
|
17
16
|
|
17
|
+
def klasses
|
18
|
+
return @klasses unless block_given?
|
19
|
+
@klasses.each do |name, klass|
|
20
|
+
yield klass
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
18
24
|
private
|
19
25
|
def add_smells_to_klasses
|
20
26
|
@examiner.smells.each do |smell|
|
data/lib/preek/smell_klass.rb
CHANGED
data/lib/preek/version.rb
CHANGED
data/preek.gemspec
CHANGED
@@ -19,8 +19,8 @@ Gem::Specification.new do |gem|
|
|
19
19
|
gem.add_runtime_dependency "thor", ">=0.16"
|
20
20
|
gem.add_runtime_dependency "reek", ">=1.3"
|
21
21
|
gem.add_development_dependency "rspec", ">=2.13"
|
22
|
+
gem.add_development_dependency "rspec-given"
|
22
23
|
gem.add_development_dependency "guard", ">=1.6"
|
23
|
-
gem.add_development_dependency "guard-pushover"
|
24
24
|
gem.add_development_dependency "guard-rspec", ">=2.4"
|
25
25
|
gem.add_development_dependency 'coveralls'
|
26
26
|
end
|
data/spec/cli_spec.rb
CHANGED
@@ -10,133 +10,116 @@ describe Preek::CLI do
|
|
10
10
|
end
|
11
11
|
|
12
12
|
describe "#version" do
|
13
|
-
|
14
|
-
|
15
|
-
output.should =~ /(\d\.?){3}/
|
16
|
-
end
|
13
|
+
When(:output) { capture(:stdout) { subject.version} }
|
14
|
+
Then {output.should =~ /(\d\.?){3}/}
|
17
15
|
end
|
18
16
|
|
19
|
-
describe "#
|
20
|
-
|
21
|
-
|
17
|
+
describe "#smell" do
|
18
|
+
|
19
|
+
When(:output) { capture(:stdout) { subject.smell(*args) } }
|
22
20
|
|
23
21
|
context "with non-existing file in ARGS" do
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
it "outputs 'No such file'" do
|
29
|
-
output.should include("No such file")
|
30
|
-
end
|
31
|
-
it "outputs the name of the file" do
|
32
|
-
output.should include(args[0])
|
33
|
-
end
|
22
|
+
Given(:args) { ['i/am/not/a_file'] }
|
23
|
+
Then{output.should_not include("success")}
|
24
|
+
Then{output.should include("No such file")}
|
25
|
+
Then{output.should include(args[0])}
|
34
26
|
end
|
35
27
|
|
36
|
-
context
|
37
|
-
let(:args){ [test_file('non_smelly')] }
|
38
|
-
it "output contains 'success! No smells'" do
|
39
|
-
output.should include("No smells")
|
40
|
-
end
|
41
|
-
end
|
28
|
+
context 'default quiet report' do
|
42
29
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
output.
|
30
|
+
context "when given file has no smells" do
|
31
|
+
Given(:args){ [test_file('non_smelly')] }
|
32
|
+
Then{output.should include("No smells")}
|
33
|
+
Then{output.should_not include(args[0])}
|
47
34
|
end
|
48
|
-
end
|
49
|
-
|
50
|
-
context "when given file has Irresponsible smell with --irresponsible options" do
|
51
|
-
let(:args){ [test_file('irresponsible')] }
|
52
35
|
|
53
|
-
|
54
|
-
|
36
|
+
context "when given file has no smells" do
|
37
|
+
Given(:args){ [test_file('non_smelly'), 'i/am/not/a_file'] }
|
38
|
+
Then{output.should include("No smells")}
|
39
|
+
Then{output.should_not include(args[0])}
|
40
|
+
Then{output.should include("No such file")}
|
41
|
+
Then{output.should include(args[1])}
|
55
42
|
end
|
56
43
|
|
57
|
-
|
58
|
-
|
44
|
+
context "when given file has Irresponsible smell" do
|
45
|
+
Given(:args){ [test_file('irresponsible')] }
|
46
|
+
Then{output.should include("No smells")}
|
47
|
+
Then{output.should_not include(args[0])}
|
59
48
|
end
|
60
49
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
it "output contains one classnames" do
|
66
|
-
output.should include('SecondSmelly')
|
67
|
-
end
|
68
|
-
it "output contains one smell" do
|
69
|
-
output.should include('UncommunicativeMethodName')
|
50
|
+
context "when given a file with two smelly classes" do
|
51
|
+
Given(:args){ [test_file('two_smelly_classes')] }
|
52
|
+
Then{output.should include('SecondSmelly')}
|
53
|
+
Then{output.should include('UncommunicativeMethodName')}
|
70
54
|
end
|
71
|
-
end
|
72
55
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
56
|
+
context "when given two smelly files" do
|
57
|
+
Given(:args){ [test_file('too_many_statements'), test_file('two_smelly_classes')] }
|
58
|
+
Then{output.should include('UncommunicativeMethodName', 'TooManyStatements')}
|
59
|
+
Then{output.should include(args[0], args[1])}
|
60
|
+
Then{output.should include("#loong_method", "#x")}
|
77
61
|
end
|
78
62
|
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
output.should include(
|
63
|
+
context "when given one file without smells and another with smells" do
|
64
|
+
Given(:args){ [test_file('non_smelly'), test_file('too_many_statements')] }
|
65
|
+
|
66
|
+
Then{output.should include('TooManyStatements')}
|
67
|
+
Then{output.should include(args[1])}
|
68
|
+
Then{output.should include("#loong_method")}
|
69
|
+
Then{output.should_not include(args[0])}
|
84
70
|
end
|
85
|
-
end
|
86
71
|
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
output.should include('IrresponsibleModule', 'UncommunicativeMethodName')
|
72
|
+
context "when given file has NilCheck smell" do
|
73
|
+
Given(:args){ [test_file('nil_check')] }
|
74
|
+
Then{output.should include("NilCheck")}
|
75
|
+
Then{output.should include(args[0])}
|
92
76
|
end
|
93
77
|
end
|
94
78
|
|
95
|
-
context
|
96
|
-
|
97
|
-
before :each do
|
98
|
-
subject.options = {irresponsible: true}
|
99
|
-
end
|
79
|
+
context 'with --irresponsible option' do
|
80
|
+
Given{subject.options = {irresponsible: true} }
|
100
81
|
|
101
|
-
|
102
|
-
|
82
|
+
context "when given file has Irresponsible smell" do
|
83
|
+
Given(:args){ [test_file('irresponsible')] }
|
84
|
+
Then{output.should include("Irresponsible")}
|
103
85
|
end
|
104
86
|
|
105
|
-
|
106
|
-
|
87
|
+
context "when given a file with two smelly classes" do
|
88
|
+
Given(:args){ [test_file('two_smelly_classes')] }
|
89
|
+
Then{output.should include('FirstSmelly', 'SecondSmelly')}
|
90
|
+
Then{output.should include('IrresponsibleModule', 'UncommunicativeMethodName')}
|
107
91
|
end
|
108
92
|
|
109
|
-
|
110
|
-
|
93
|
+
context "when given two smelly files" do
|
94
|
+
Given(:args){ [test_file('too_many_statements'), test_file('two_smelly_classes')] }
|
95
|
+
Then{output.should include('IrresponsibleModule', 'UncommunicativeMethodName', 'TooManyStatements')}
|
96
|
+
Then{output.should include(args[0], args[1])}
|
97
|
+
Then{output.should include("#loong_method", "#x")}
|
111
98
|
end
|
112
|
-
end
|
113
99
|
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
subject.options = {irresponsible: true}
|
100
|
+
context "when given a file with two different smells" do
|
101
|
+
Given(:args){ [test_file('irresponsible_and_lazy')] }
|
102
|
+
Then{output.should include('IrresponsibleModule', 'UncommunicativeMethodName')}
|
118
103
|
end
|
104
|
+
end
|
119
105
|
|
120
|
-
|
121
|
-
|
122
|
-
end
|
106
|
+
context 'with --verbose option' do
|
107
|
+
Given{subject.options = {verbose: true}}
|
123
108
|
|
124
|
-
|
125
|
-
|
109
|
+
context "when given file has no smells" do
|
110
|
+
Given(:args){ [test_file('non_smelly')] }
|
111
|
+
Then{output.should include("No smells")}
|
112
|
+
Then{output.should include(args[0])}
|
126
113
|
end
|
127
114
|
|
128
|
-
|
129
|
-
|
115
|
+
context "when given two smelly files" do
|
116
|
+
Given(:args){ [test_file('too_many_statements'), test_file('two_smelly_classes')] }
|
117
|
+
Then{output.should include(args[0], args[1])}
|
130
118
|
end
|
131
|
-
end
|
132
119
|
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
output.should include("NilCheck")
|
137
|
-
end
|
138
|
-
it "outputs the name of the file" do
|
139
|
-
output.should include(args[0])
|
120
|
+
context "when given one file without smells and another with smells" do
|
121
|
+
Given(:args){ [test_file('non_smelly'), test_file('too_many_statements')] }
|
122
|
+
Then{output.should include(args[1], args[0])}
|
140
123
|
end
|
141
124
|
end
|
142
125
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -4,6 +4,7 @@ Coveralls.wear!
|
|
4
4
|
$:.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
|
5
5
|
require 'stringio'
|
6
6
|
require File.expand_path('../../lib/preek', __FILE__)
|
7
|
+
require 'rspec/given'
|
7
8
|
|
8
9
|
RSpec.configure do |config|
|
9
10
|
config.treat_symbols_as_metadata_keys_with_true_values = true
|
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: 1.1
|
4
|
+
version: 1.2.1
|
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-
|
11
|
+
date: 2013-09-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -53,33 +53,33 @@ dependencies:
|
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '2.13'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: rspec-given
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - '>='
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
61
|
+
version: '0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - '>='
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
68
|
+
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name: guard
|
70
|
+
name: guard
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - '>='
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '
|
75
|
+
version: '1.6'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - '>='
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: '
|
82
|
+
version: '1.6'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: guard-rspec
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -127,11 +127,12 @@ files:
|
|
127
127
|
- bin/preek
|
128
128
|
- lib/preek.rb
|
129
129
|
- lib/preek/cli.rb
|
130
|
+
- lib/preek/examiner.rb
|
130
131
|
- lib/preek/ext/smell_warning.rb
|
131
|
-
- lib/preek/
|
132
|
+
- lib/preek/output.rb
|
133
|
+
- lib/preek/report.rb
|
132
134
|
- lib/preek/smell_file.rb
|
133
135
|
- lib/preek/smell_klass.rb
|
134
|
-
- lib/preek/smell_reporter.rb
|
135
136
|
- lib/preek/version.rb
|
136
137
|
- preek.gemspec
|
137
138
|
- spec/capture_helper.rb
|
@@ -163,7 +164,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
163
164
|
version: '0'
|
164
165
|
requirements: []
|
165
166
|
rubyforge_project:
|
166
|
-
rubygems_version: 2.0.
|
167
|
+
rubygems_version: 2.0.3
|
167
168
|
signing_key:
|
168
169
|
specification_version: 4
|
169
170
|
summary: It might reek but its pretty
|
@@ -1,45 +0,0 @@
|
|
1
|
-
require 'reek'
|
2
|
-
|
3
|
-
require 'preek/ext/smell_warning'
|
4
|
-
|
5
|
-
require 'preek/smell_file'
|
6
|
-
require 'preek/smell_klass'
|
7
|
-
|
8
|
-
module Preek
|
9
|
-
# This is a 'Collector'
|
10
|
-
class SmellCollector
|
11
|
-
def initialize(files, excludes = [])
|
12
|
-
@files = files.delete_if { |file| !File.exists? file }
|
13
|
-
@excludes = excludes
|
14
|
-
end
|
15
|
-
|
16
|
-
def smelly_files
|
17
|
-
@smelly_files ||= files_from_sources
|
18
|
-
end
|
19
|
-
|
20
|
-
private
|
21
|
-
def files_from_sources
|
22
|
-
filtered_sources.map do |examiner|
|
23
|
-
SmellFile.new(examiner) if examiner.smelly?
|
24
|
-
end.compact
|
25
|
-
end
|
26
|
-
|
27
|
-
def filtered_sources
|
28
|
-
sources.map do |source|
|
29
|
-
examiner = Reek::Examiner.new(source)
|
30
|
-
filter_excludes_from(examiner)
|
31
|
-
examiner
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
def filter_excludes_from(examiner)
|
36
|
-
examiner.smells.delete_if do |smell|
|
37
|
-
@excludes.include? smell.smell_class
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
def sources
|
42
|
-
Reek::Source::SourceLocator.new(@files).all_sources
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
data/lib/preek/smell_reporter.rb
DELETED
@@ -1,64 +0,0 @@
|
|
1
|
-
require 'thor/shell/color'
|
2
|
-
module Preek
|
3
|
-
# Here we report the smells in a nice fashion
|
4
|
-
class SmellReporter < Thor::Shell::Color
|
5
|
-
def initialize(smelly_files, not_files)
|
6
|
-
@smelly_files = smelly_files
|
7
|
-
@not_files = not_files
|
8
|
-
@padding = 0
|
9
|
-
end
|
10
|
-
|
11
|
-
def print_smells
|
12
|
-
if success?
|
13
|
-
say_status 'success!', 'No smells detected.'
|
14
|
-
else
|
15
|
-
print_each_smell
|
16
|
-
end
|
17
|
-
print_not_files
|
18
|
-
end
|
19
|
-
alias :print_result :print_smells
|
20
|
-
|
21
|
-
private
|
22
|
-
def success?
|
23
|
-
@smelly_files.empty?
|
24
|
-
end
|
25
|
-
|
26
|
-
def print_not_files
|
27
|
-
return if @not_files.empty?
|
28
|
-
say_status :error, "No such file(s) - #{@not_files.join(', ')}.", :red
|
29
|
-
end
|
30
|
-
|
31
|
-
def print_each_smell
|
32
|
-
print_line
|
33
|
-
@smelly_files.each do |smelly|
|
34
|
-
say_status 'file', format_path(smelly.filename), :blue
|
35
|
-
print_klasses smelly.klasses
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
def print_klasses klasses
|
40
|
-
klasses.each do |index, klass|
|
41
|
-
say_status "\n\tclass", klass.name
|
42
|
-
say_status 'smells', '', :red
|
43
|
-
print_klass_smells klass.smells
|
44
|
-
end
|
45
|
-
print_line
|
46
|
-
end
|
47
|
-
|
48
|
-
def print_klass_smells smells
|
49
|
-
smells.each {|smell|
|
50
|
-
say_status nil, smell
|
51
|
-
}
|
52
|
-
end
|
53
|
-
|
54
|
-
def print_line
|
55
|
-
say "\n\t#{'-'*60}\n\n"
|
56
|
-
end
|
57
|
-
|
58
|
-
def padding; 0; end
|
59
|
-
|
60
|
-
def format_path file
|
61
|
-
File.expand_path(file)
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|