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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f4119a0e66c059ea4a0d565bfab3ecfaeef3c722
4
- data.tar.gz: 60149f1e3dda3e9f1b9f1e03f2287817ab9715ce
3
+ metadata.gz: 1877ecb6f7f04aa89c30beda81afb570a22b0edf
4
+ data.tar.gz: 9bb692ec4755c9402ce8bfa596e7333be0755573
5
5
  SHA512:
6
- metadata.gz: de5e40087670fc35f74a341f9e50c477aa1deaeb914abe7466afe4ce53efaf9fb38633b814424cc50cc20aa08e1563f1e65169d159bc29b6e720f012d11b628b
7
- data.tar.gz: ed3e2bddfbc5e369f1079da7e1a7684dc6ab28d1ad6d64625541587ec47c0173b7596de15ac4b26737401a6cb0d9ec82a8c0696cd88603e57772530254ead51f
6
+ metadata.gz: 16cd877bea8569bb5e55e30f825d076d62fa7a0a5f026fbf50f86150672f93517a881d71cd048670a3d2f029cacd88c27ceab2f21fe6aa65de2a0ce7995cb27f
7
+ data.tar.gz: cfd0ba532e2870abc0794fa173274b811a6a19de8ecf5adfd3f741c55cfec7aa70dc1263f4d183f584fc4c4f682ec9eed5b4d323bc996f5c1e2c5e654e7a5e14
data/CHANGELOG CHANGED
@@ -1,3 +1,7 @@
1
+ == 2.0.2
2
+
3
+ * (troessner) Fix version command
4
+
1
5
  == 2.0.1
2
6
 
3
7
  * (leonelgalan) Add support for json reports
@@ -2,6 +2,7 @@ require 'optparse'
2
2
  require 'ostruct'
3
3
  require 'rainbow'
4
4
  require 'reek/cli/option_interpreter'
5
+ require 'reek/version'
5
6
 
6
7
  module Reek
7
8
  module Cli
@@ -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
- # Finds the active code smells in Ruby source code.
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 = Source::SourceRepository.parse(source)
27
- @description = sources.description
28
- @collector = Core::WarningCollector.new
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
- sources.each do |src|
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
@@ -3,6 +3,6 @@ module Reek
3
3
  # This module holds the Reek version informations
4
4
  #
5
5
  module Version
6
- STRING = '2.0.1'
6
+ STRING = '2.0.2'
7
7
  end
8
8
  end
@@ -1,3 +1,5 @@
1
+ require 'reek/smells'
2
+
1
3
  FactoryGirl.define do
2
4
  factory :smell_detector, class: Reek::Smells::SmellDetector do
3
5
  skip_create
@@ -2,7 +2,6 @@ require 'spec_helper'
2
2
  require 'reek/smells/duplicate_method_call'
3
3
  require 'reek/core/code_context'
4
4
  require 'reek/core/tree_walker'
5
- require 'reek/core/sniffer'
6
5
  require 'reek/smells/smell_detector_shared'
7
6
 
8
7
  describe Reek::Smells::DuplicateMethodCall do
@@ -230,8 +230,7 @@ describe Reek::Smells::FeatureEnvy do
230
230
  end
231
231
  EOS
232
232
  source = src.to_reek_source
233
- sniffer = Reek::Core::Sniffer.new(source)
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(src)
6
- source = src.to_reek_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(src)
12
- source = src.to_reek_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
- sniffer = Reek::Core::Sniffer.new(source)
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
@@ -3,5 +3,4 @@ require 'reek/rake/task'
3
3
  Reek::Rake::Task.new do |t|
4
4
  t.fail_on_error = true
5
5
  t.verbose = false
6
- t.reek_opts = '--quiet'
7
6
  end
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.1
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-03 00:00:00.000000000 Z
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.4.4
438
+ rubygems_version: 2.2.2
440
439
  signing_key:
441
440
  specification_version: 4
442
441
  summary: Code smell detector for Ruby
@@ -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