reek 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,9 @@
1
+ == 0.2.0 2008-09-10
2
+
3
+ * Minor enhancements:
4
+ * Added --help, --version options
5
+ * Added --sort option to sort the report by smell or by code location
6
+
1
7
  == 0.1.1 2008-09-09
2
8
 
3
9
  * Some tweaks:
data/bin/reek CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
  #
3
3
  # Created on 2008-2-17.
4
- # Copyright (c) 2008. All rights reserved.
4
+ # Copyright (c) 2008 Kevin Rutherford, Rutherford Software Ltd. All rights reserved.
5
5
 
6
6
  begin
7
7
  require 'rubygems'
@@ -10,6 +10,8 @@ rescue LoadError
10
10
  end
11
11
 
12
12
  require 'reek'
13
+ require 'reek/options'
14
+ require 'reek/version'
13
15
 
14
16
  def classes_currently_loaded
15
17
  result = []
@@ -17,6 +19,8 @@ def classes_currently_loaded
17
19
  result
18
20
  end
19
21
 
22
+ Reek::Options.parse(ARGV)
23
+
20
24
  old_classes = classes_currently_loaded
21
25
  files = ARGV
22
26
  files = Dir['**/*.rb'] if files.empty?
@@ -0,0 +1,61 @@
1
+ $:.unshift File.dirname(__FILE__)
2
+
3
+ require 'reek/report'
4
+ require 'optparse'
5
+
6
+ include Reek
7
+
8
+ module Reek
9
+
10
+ class Options
11
+ def self.default_options
12
+ {:sort_order => Report::SORT_ORDERS[:context]}
13
+ end
14
+
15
+ @@opts = default_options
16
+
17
+ def self.[](key)
18
+ @@opts[key]
19
+ end
20
+
21
+ def self.parse_args(args)
22
+ result = default_options
23
+ parser = OptionParser.new do |opts|
24
+ opts.banner = "Usage: #{File.basename($0)} [options] [files]"
25
+
26
+ opts.separator ""
27
+ opts.separator "Specific options:"
28
+
29
+ opts.on('-s', "--sort ORDER", Report::SORT_ORDERS.keys,
30
+ "Select sort order for report (#{Report::SORT_ORDERS.keys.join(', ')})") do |arg|
31
+ result[:sort_order] = Report::SORT_ORDERS[arg] unless arg.nil?
32
+ end
33
+
34
+ opts.separator ""
35
+ opts.separator "Common options:"
36
+ opts.on_tail("-h", "--help", "Show this message") do
37
+ puts opts
38
+ exit(0)
39
+ end
40
+
41
+ opts.on_tail("-v", "--version", "Show version") do
42
+ puts "#{File.basename($0)} #{Reek::VERSION::STRING}"
43
+ exit(0)
44
+ end
45
+ end
46
+
47
+ parser.parse!(args)
48
+ result
49
+ end
50
+
51
+ def self.parse(args)
52
+ begin
53
+ @@opts = parse_args(args)
54
+ rescue OptionParser::ParseError => e
55
+ puts "Error: #{e}"
56
+ puts "Use '-h' for help."
57
+ exit(1)
58
+ end
59
+ end
60
+ end
61
+ end
@@ -4,7 +4,25 @@ require 'set'
4
4
 
5
5
  module Reek
6
6
 
7
+ class SortByContext
8
+ def compare(smell1, smell2)
9
+ smell1.detailed_report <=> smell2.detailed_report
10
+ end
11
+ end
12
+
13
+ class SortBySmell
14
+ def compare(smell1, smell2)
15
+ smell1.report <=> smell2.report
16
+ end
17
+ end
18
+
7
19
  class Report
20
+
21
+ SORT_ORDERS = {
22
+ :context => SortByContext.new,
23
+ :smell => SortBySmell.new
24
+ }
25
+
8
26
  def initialize # :nodoc:
9
27
  @smells = SortedSet.new
10
28
  end
@@ -17,10 +35,6 @@ module Reek
17
35
  @smells.empty?
18
36
  end
19
37
 
20
- def include?(obj) # :nodoc:
21
- @smells.include?(obj)
22
- end
23
-
24
38
  def length # :nodoc:
25
39
  @smells.length
26
40
  end
@@ -35,4 +49,5 @@ module Reek
35
49
  @smells.map {|smell| smell.report}.join("\n")
36
50
  end
37
51
  end
52
+
38
53
  end
@@ -1,6 +1,7 @@
1
1
  $:.unshift File.dirname(__FILE__)
2
2
 
3
3
  require 'reek/printer'
4
+ require 'reek/options'
4
5
 
5
6
  module Reek
6
7
 
@@ -25,12 +26,10 @@ module Reek
25
26
  end
26
27
 
27
28
  def <=>(other) # :nodoc:
28
- self.report <=> other.report
29
+ Options[:sort_order].compare(self, other)
29
30
  end
30
31
 
31
- def eql?(other) # :nodoc:
32
- self.report.eql?(other.report)
33
- end
32
+ alias eql? <=>
34
33
 
35
34
  def name
36
35
  self.class.convert_camel_case(self.class.name.split(/::/)[1])
@@ -39,6 +38,10 @@ module Reek
39
38
  def report
40
39
  "[#{name}] #{detailed_report}"
41
40
  end
41
+
42
+ def to_s
43
+ report
44
+ end
42
45
  end
43
46
 
44
47
  class LongParameterList < Smell
@@ -1,8 +1,8 @@
1
1
  module Reek #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
- MINOR = 1
5
- TINY = 1
4
+ MINOR = 2
5
+ TINY = 0
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
@@ -25,8 +25,8 @@ describe MethodChecker, "(Feature Envy)" do
25
25
  it 'should report simple parameter call' do
26
26
  @cchk.check_source('def simple(arga) arga[3] end')
27
27
  @rpt.length.should == 2
28
- @rpt[1].should == UtilityFunction.new(@cchk)
29
- @rpt[0].should == FeatureEnvy.new(@cchk, ':arga')
28
+ @rpt[0].should == UtilityFunction.new(@cchk)
29
+ @rpt[1].should == FeatureEnvy.new(@cchk, ':arga')
30
30
  end
31
31
 
32
32
  it 'should report highest affinity' do
@@ -0,0 +1,39 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper.rb'
2
+
3
+ require 'reek/options'
4
+
5
+ include Reek
6
+
7
+ describe Options, ' when given no arguments' do
8
+ it "should retain the default sort order" do
9
+ default_order = Options[:sort_order]
10
+ Options.parse []
11
+ Options[:sort_order].should == default_order
12
+ end
13
+ end
14
+
15
+ describe Options, ' when --sort_order is specified' do
16
+ before :each do
17
+ @default_order = Options[:sort_order]
18
+ end
19
+
20
+ it 'should require an argument' do
21
+ lambda { Options.parse_args(['-s']) }.should raise_error(OptionParser::MissingArgument)
22
+ Options[:sort_order].should == @default_order
23
+ end
24
+
25
+ it "should allow sort by smell" do
26
+ Options.parse %w{-s smell}
27
+ Options[:sort_order].should == Report::SORT_ORDERS[:smell]
28
+ end
29
+
30
+ it "should allow sort by context" do
31
+ Options.parse %w{-s context}
32
+ Options[:sort_order].should == Report::SORT_ORDERS[:context]
33
+ end
34
+
35
+ it "should reject illegal sort order" do
36
+ lambda { Options.parse_args(%w{-s tarts}) }.should raise_error(OptionParser::InvalidArgument)
37
+ Options[:sort_order].should == @default_order
38
+ end
39
+ end
@@ -47,3 +47,36 @@ describe Report, " as a SortedSet" do
47
47
  rpt.length.should == 1
48
48
  end
49
49
  end
50
+
51
+ describe SortByContext do
52
+ before :each do
53
+ @sorter = SortByContext.new
54
+ end
55
+
56
+ it 'should return 0 for identical smells' do
57
+ smell = LongMethod.new('Class#method')
58
+ @sorter.compare(smell, smell).should == 0
59
+ end
60
+
61
+ it 'should return non-0 for different smells' do
62
+ @sorter.compare(LongMethod.new('x'), FeatureEnvy.new('y', 1)).should == -1
63
+ end
64
+ end
65
+
66
+ describe SortBySmell do
67
+ before :each do
68
+ @sorter = SortBySmell.new
69
+ end
70
+
71
+ it 'should return 0 for identical smells' do
72
+ @sorter.compare(LongMethod.new('x'), LongMethod.new('x')).should == 0
73
+ end
74
+
75
+ it 'should differentiate identical smells with different contexts' do
76
+ @sorter.compare(LongMethod.new('x'), LongMethod.new('y')).should == -1
77
+ end
78
+
79
+ it 'should differentiate different smells with identical contexts' do
80
+ @sorter.compare(LongMethod.new('x'), FeatureEnvy.new('x', 2)).should == 1
81
+ end
82
+ end
@@ -33,7 +33,7 @@
33
33
  <h1>Code smell detector</h1>
34
34
  <div id="version" class="clickable" onclick='document.location = "http://rubyforge.org/projects/reek"; return false'>
35
35
  <p>Get Version</p>
36
- <a href="http://rubyforge.org/projects/reek" class="numbers">0.1.1</a>
36
+ <a href="http://rubyforge.org/projects/reek" class="numbers">0.2.0</a>
37
37
  </div>
38
38
  <h1>&#x2192; &#8216;reek&#8217;</h1>
39
39
 
@@ -18,7 +18,7 @@ h2. The basics
18
18
  $ reek
19
19
  </pre>
20
20
 
21
- (More details coming soon...)
21
+ (See reek --help for more.)
22
22
 
23
23
  h2. Code Smells
24
24
 
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: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin Rutherford
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-09-09 00:00:00 +01:00
12
+ date: 2008-09-12 00:00:00 +01:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -52,6 +52,7 @@ files:
52
52
  - lib/reek/checker.rb
53
53
  - lib/reek/class_checker.rb
54
54
  - lib/reek/method_checker.rb
55
+ - lib/reek/options.rb
55
56
  - lib/reek/printer.rb
56
57
  - lib/reek/report.rb
57
58
  - lib/reek/smells.rb
@@ -63,6 +64,7 @@ files:
63
64
  - spec/reek/long_method_spec.rb
64
65
  - spec/reek/method_checker_spec.rb
65
66
  - spec/reek/nested_iterators_spec.rb
67
+ - spec/reek/options_spec.rb
66
68
  - spec/reek/report_spec.rb
67
69
  - spec/reek/smell_spec.rb
68
70
  - spec/reek/uncommunicative_name_spec.rb