reek 2.0.1 → 2.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +4 -0
- data/lib/reek/cli/options.rb +1 -0
- data/lib/reek/core/smell_repository.rb +2 -1
- data/lib/reek/core/tree_walker.rb +1 -2
- data/lib/reek/examiner.rb +30 -16
- data/lib/reek/version.rb +1 -1
- data/spec/factories/factories.rb +2 -0
- data/spec/reek/smells/duplicate_method_call_spec.rb +0 -1
- data/spec/reek/smells/feature_envy_spec.rb +1 -2
- data/spec/reek/smells/smell_detector_shared.rb +1 -0
- data/spec/reek/smells/too_many_statements_spec.rb +4 -8
- data/spec/reek/smells/utility_function_spec.rb +1 -2
- data/tasks/develop.rake +1 -1
- data/tasks/reek.rake +0 -1
- metadata +3 -4
- data/lib/reek/core/sniffer.rb +0 -35
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1877ecb6f7f04aa89c30beda81afb570a22b0edf
|
4
|
+
data.tar.gz: 9bb692ec4755c9402ce8bfa596e7333be0755573
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 16cd877bea8569bb5e55e30f825d076d62fa7a0a5f026fbf50f86150672f93517a881d71cd048670a3d2f029cacd88c27ceab2f21fe6aa65de2a0ce7995cb27f
|
7
|
+
data.tar.gz: cfd0ba532e2870abc0794fa173274b811a6a19de8ecf5adfd3f741c55cfec7aa70dc1263f4d183f584fc4c4f682ec9eed5b4d323bc996f5c1e2c5e654e7a5e14
|
data/CHANGELOG
CHANGED
data/lib/reek/cli/options.rb
CHANGED
@@ -13,12 +13,13 @@ module Reek
|
|
13
13
|
Reek::Smells::SmellDetector.descendants
|
14
14
|
end
|
15
15
|
|
16
|
-
def initialize(source_description, smell_types = self.class.smell_types)
|
16
|
+
def initialize(source_description = nil, smell_types = self.class.smell_types)
|
17
17
|
@typed_detectors = nil
|
18
18
|
@detectors = {}
|
19
19
|
smell_types.each do |klass|
|
20
20
|
@detectors[klass] = klass.new(source_description)
|
21
21
|
end
|
22
|
+
Configuration::AppConfiguration.configure_smell_repository self
|
22
23
|
end
|
23
24
|
|
24
25
|
def configure(klass, config)
|
@@ -11,9 +11,8 @@ module Reek
|
|
11
11
|
#
|
12
12
|
# SMELL: This class is responsible for counting statements and for feeding
|
13
13
|
# each context to the smell repository.
|
14
|
-
# SMELL: This class has a name that doesn't match its responsibility.
|
15
14
|
class TreeWalker
|
16
|
-
def initialize(smell_repository)
|
15
|
+
def initialize(smell_repository = Core::SmellRepository.new)
|
17
16
|
@smell_repository = smell_repository
|
18
17
|
@element = StopContext.new
|
19
18
|
end
|
data/lib/reek/examiner.rb
CHANGED
@@ -1,10 +1,11 @@
|
|
1
|
-
require 'reek/core/sniffer'
|
2
|
-
require 'reek/core/warning_collector'
|
3
1
|
require 'reek/source/source_repository'
|
2
|
+
require 'reek/core/warning_collector'
|
3
|
+
require 'reek/core/smell_repository'
|
4
|
+
require 'reek/core/tree_walker'
|
4
5
|
|
5
6
|
module Reek
|
6
7
|
#
|
7
|
-
#
|
8
|
+
# Applies all available smell detectors to a source.
|
8
9
|
#
|
9
10
|
class Examiner
|
10
11
|
#
|
@@ -23,20 +24,12 @@ module Reek
|
|
23
24
|
# each of which is opened and parsed for source code.
|
24
25
|
#
|
25
26
|
def initialize(source, smell_types_to_filter_by = [])
|
26
|
-
sources
|
27
|
-
@description
|
28
|
-
@collector
|
29
|
-
|
30
|
-
smell_types = Core::SmellRepository.smell_types
|
31
|
-
|
32
|
-
if smell_types_to_filter_by.any?
|
33
|
-
smell_types.select! { |klass| smell_types_to_filter_by.include? klass.smell_type }
|
34
|
-
end
|
27
|
+
@sources = Source::SourceRepository.parse(source)
|
28
|
+
@description = @sources.description
|
29
|
+
@collector = Core::WarningCollector.new
|
30
|
+
@smell_types = eligible_smell_types(smell_types_to_filter_by)
|
35
31
|
|
36
|
-
|
37
|
-
repository = Core::SmellRepository.new(src.desc, smell_types)
|
38
|
-
Core::Sniffer.new(src, repository).report_on(@collector)
|
39
|
-
end
|
32
|
+
run
|
40
33
|
end
|
41
34
|
|
42
35
|
#
|
@@ -61,5 +54,26 @@ module Reek
|
|
61
54
|
def smelly?
|
62
55
|
!smells.empty?
|
63
56
|
end
|
57
|
+
|
58
|
+
private
|
59
|
+
|
60
|
+
def run
|
61
|
+
@sources.each do |source|
|
62
|
+
smell_repository = Core::SmellRepository.new(source.desc, @smell_types)
|
63
|
+
syntax_tree = source.syntax_tree
|
64
|
+
Core::TreeWalker.new(smell_repository).process(syntax_tree) if syntax_tree
|
65
|
+
smell_repository.report_on(@collector)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def eligible_smell_types(smell_types_to_filter_by = [])
|
70
|
+
if smell_types_to_filter_by.any?
|
71
|
+
Core::SmellRepository.smell_types.select do |klass|
|
72
|
+
smell_types_to_filter_by.include? klass.smell_type
|
73
|
+
end
|
74
|
+
else
|
75
|
+
Core::SmellRepository.smell_types
|
76
|
+
end
|
77
|
+
end
|
64
78
|
end
|
65
79
|
end
|
data/lib/reek/version.rb
CHANGED
data/spec/factories/factories.rb
CHANGED
@@ -230,8 +230,7 @@ describe Reek::Smells::FeatureEnvy do
|
|
230
230
|
end
|
231
231
|
EOS
|
232
232
|
source = src.to_reek_source
|
233
|
-
|
234
|
-
@mctx = Reek::Core::TreeWalker.new(sniffer).process_def(source.syntax_tree)
|
233
|
+
@mctx = Reek::Core::TreeWalker.new.process_def(source.syntax_tree)
|
235
234
|
@smells = @detector.examine_context(@mctx)
|
236
235
|
end
|
237
236
|
|
@@ -9,6 +9,7 @@ shared_examples_for 'SmellDetector' do
|
|
9
9
|
@ctx = double('context')
|
10
10
|
allow(@ctx).to receive(:config_for).and_return({})
|
11
11
|
end
|
12
|
+
|
12
13
|
it 'when false' do
|
13
14
|
expect(@ctx).to receive(:matches?).at_least(:once).and_return(false)
|
14
15
|
expect(@detector.exception?(@ctx)).to eq(false)
|
@@ -2,16 +2,12 @@ require 'spec_helper'
|
|
2
2
|
require 'reek/smells/too_many_statements'
|
3
3
|
require 'reek/smells/smell_detector_shared'
|
4
4
|
|
5
|
-
def process_method(
|
6
|
-
source
|
7
|
-
sniffer = Reek::Core::Sniffer.new(source)
|
8
|
-
Reek::Core::TreeWalker.new(sniffer).process_def(source.syntax_tree)
|
5
|
+
def process_method(source)
|
6
|
+
Reek::Core::TreeWalker.new.process_def(source.to_reek_source.syntax_tree)
|
9
7
|
end
|
10
8
|
|
11
|
-
def process_singleton_method(
|
12
|
-
source
|
13
|
-
sniffer = Reek::Core::Sniffer.new(source)
|
14
|
-
Reek::Core::TreeWalker.new(sniffer).process_defs(source.syntax_tree)
|
9
|
+
def process_singleton_method(source)
|
10
|
+
Reek::Core::TreeWalker.new.process_defs(source.to_reek_source.syntax_tree)
|
15
11
|
end
|
16
12
|
|
17
13
|
describe Reek::Smells::TooManyStatements do
|
@@ -119,8 +119,7 @@ describe Reek::Smells::UtilityFunction do
|
|
119
119
|
end
|
120
120
|
EOS
|
121
121
|
source = src.to_reek_source
|
122
|
-
|
123
|
-
mctx = Reek::Core::TreeWalker.new(sniffer).process_def(source.syntax_tree)
|
122
|
+
mctx = Reek::Core::TreeWalker.new.process_def(source.syntax_tree)
|
124
123
|
@warning = @detector.examine_context(mctx)[0] # SMELL: too cumbersome!
|
125
124
|
end
|
126
125
|
|
data/tasks/develop.rake
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
require 'rake/clean'
|
2
|
+
require 'reek/core/smell_repository'
|
2
3
|
|
3
4
|
CONFIG_FILE = 'config/defaults.reek'
|
4
5
|
|
5
6
|
file CONFIG_FILE do
|
6
7
|
config = {}
|
7
|
-
require 'reek/core/sniffer'
|
8
8
|
Reek::Core::SmellRepository.smell_types.each do |klass|
|
9
9
|
config[klass.name.split(/::/)[-1]] = klass.default_config
|
10
10
|
end
|
data/tasks/reek.rake
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: reek
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kevin Rutherford
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2015-03-
|
13
|
+
date: 2015-03-15 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: parser
|
@@ -234,7 +234,6 @@ files:
|
|
234
234
|
- lib/reek/core/singleton_method_context.rb
|
235
235
|
- lib/reek/core/smell_configuration.rb
|
236
236
|
- lib/reek/core/smell_repository.rb
|
237
|
-
- lib/reek/core/sniffer.rb
|
238
237
|
- lib/reek/core/stop_context.rb
|
239
238
|
- lib/reek/core/tree_walker.rb
|
240
239
|
- lib/reek/core/warning_collector.rb
|
@@ -436,7 +435,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
436
435
|
version: '0'
|
437
436
|
requirements: []
|
438
437
|
rubyforge_project: reek
|
439
|
-
rubygems_version: 2.
|
438
|
+
rubygems_version: 2.2.2
|
440
439
|
signing_key:
|
441
440
|
specification_version: 4
|
442
441
|
summary: Code smell detector for Ruby
|
data/lib/reek/core/sniffer.rb
DELETED
@@ -1,35 +0,0 @@
|
|
1
|
-
require 'reek/core/tree_walker'
|
2
|
-
require 'reek/core/smell_repository'
|
3
|
-
require 'reek/configuration/app_configuration'
|
4
|
-
|
5
|
-
module Reek
|
6
|
-
module Core
|
7
|
-
#
|
8
|
-
# Configures all available smell detectors and applies them to a source.
|
9
|
-
#
|
10
|
-
class Sniffer
|
11
|
-
def initialize(source, # Either Source::SourceFile or Source::SourceCode
|
12
|
-
smell_repository = Core::SmellRepository.new(source.desc))
|
13
|
-
@smell_repository = smell_repository
|
14
|
-
@source = source
|
15
|
-
|
16
|
-
Configuration::AppConfiguration.configure_smell_repository(@smell_repository)
|
17
|
-
end
|
18
|
-
|
19
|
-
def report_on(listener)
|
20
|
-
TreeWalker.new(@smell_repository).process(syntax_tree) if syntax_tree
|
21
|
-
@smell_repository.report_on(listener)
|
22
|
-
end
|
23
|
-
|
24
|
-
def examine(scope, node_type)
|
25
|
-
@smell_repository.examine scope, node_type
|
26
|
-
end
|
27
|
-
|
28
|
-
private
|
29
|
-
|
30
|
-
def syntax_tree
|
31
|
-
@syntax_tree ||= @source.syntax_tree
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|