kevinrutherford-reek 1.1.3.8 → 1.1.3.9

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -9,6 +9,7 @@
9
9
  ** Reports for multiple sources are run together; no more blank lines
10
10
  * The smells masked by *.reek config files can now be seen:
11
11
  ** The header for each source file now counts masked smells
12
+ ** The --show-all (-a) option shows masked warnings in the report
12
13
 
13
14
  === Minor Changes
14
15
  * Several changes to the LongMethod counting algorithm:
@@ -40,3 +40,30 @@ Feature: Masking smells using config files
40
40
  Dirty#a/block/block is nested (Nested Iterators)
41
41
 
42
42
  """
43
+
44
+ Scenario: switch off one smell but show all in the report
45
+ When I run reek --show-all spec/samples/masked/dirty.rb
46
+ Then it fails with exit status 2
47
+ And it reports:
48
+ """
49
+ spec/samples/masked/dirty.rb -- 3 warnings (+3 masked):
50
+ (masked) Dirty has the variable name '@s' (Uncommunicative Name)
51
+ Dirty#a calls @s.title multiple times (Duplication)
52
+ Dirty#a calls puts(@s.title) multiple times (Duplication)
53
+ (masked) Dirty#a has the name 'a' (Uncommunicative Name)
54
+ (masked) Dirty#a/block has the variable name 'x' (Uncommunicative Name)
55
+ Dirty#a/block/block is nested (Nested Iterators)
56
+
57
+ """
58
+
59
+ Scenario: switch off one smell and show hide them in the report
60
+ When I run reek --no-show-all spec/samples/masked/dirty.rb
61
+ Then it fails with exit status 2
62
+ And it reports:
63
+ """
64
+ spec/samples/masked/dirty.rb -- 3 warnings (+3 masked):
65
+ Dirty#a calls @s.title multiple times (Duplication)
66
+ Dirty#a calls puts(@s.title) multiple times (Duplication)
67
+ Dirty#a/block/block is nested (Nested Iterators)
68
+
69
+ """
@@ -18,3 +18,24 @@ Feature: Reek can be controlled using command-line options
18
18
  When I run reek --version
19
19
  Then it succeeds
20
20
  And it reports the current version
21
+
22
+ Scenario: display the help information
23
+ When I run reek --help
24
+ Then it succeeds
25
+ And it reports:
26
+ """
27
+ Usage: reek [options] files...
28
+
29
+ If no files are given, Reek reads source code from standard input.
30
+ See http://wiki.github.com/kevinrutherford/reek for detailed help.
31
+
32
+
33
+ Options:
34
+ -a, --[no-]show-all Show all smells, including those masked by config settings
35
+ -h, --help Show this message
36
+ -f, --format FORMAT Specify the format of smell warnings
37
+ -c, --context-first Sort by context; sets the format string to "%m%c %w (%s)"
38
+ -s, --smell-first Sort by smell; sets the format string to "%m[%s] %c %w"
39
+ -v, --version Show version
40
+
41
+ """
data/lib/reek/options.rb CHANGED
@@ -5,12 +5,13 @@ module Reek
5
5
 
6
6
  class Options
7
7
 
8
- CTX_SORT = '%c %w (%s)'
9
- SMELL_SORT = '[%s] %c %w'
8
+ CTX_SORT = '%m%c %w (%s)'
9
+ SMELL_SORT = '%m[%s] %c %w'
10
10
 
11
11
  def self.default_options
12
12
  {
13
- :format => CTX_SORT
13
+ :format => CTX_SORT,
14
+ :show_all => false
14
15
  }
15
16
  end
16
17
 
@@ -26,7 +27,7 @@ module Reek
26
27
  parser.parse!(args)
27
28
  result
28
29
  end
29
-
30
+
30
31
  def self.set_options(opts, config)
31
32
  opts.banner = <<EOB
32
33
  Usage: #{opts.program_name} [options] files...
@@ -36,9 +37,7 @@ See http://wiki.github.com/kevinrutherford/reek for detailed help.
36
37
  EOB
37
38
 
38
39
  opts.separator "\nOptions:"
39
- set_help_option(opts)
40
- set_sort_option(config, opts)
41
- set_version_option(opts)
40
+ set_all_options(opts, config)
42
41
  end
43
42
 
44
43
  def self.parse(args)
@@ -51,6 +50,13 @@ EOB
51
50
  end
52
51
 
53
52
  private
53
+
54
+ def self.set_all_options(opts, config)
55
+ set_show_all_option(opts, config)
56
+ set_help_option(opts)
57
+ set_sort_option(config, opts)
58
+ set_version_option(opts)
59
+ end
54
60
 
55
61
  def self.set_version_option(opts)
56
62
  opts.on("-v", "--version", "Show version") do
@@ -59,6 +65,12 @@ EOB
59
65
  end
60
66
  end
61
67
 
68
+ def self.set_show_all_option(opts, config)
69
+ opts.on("-a", "--[no-]show-all", "Show all smells, including those masked by config settings") do |opt|
70
+ config[:show_all] = opt
71
+ end
72
+ end
73
+
62
74
  def self.set_help_option(opts)
63
75
  opts.on("-h", "--help", "Show this message") do
64
76
  puts opts
data/lib/reek/report.rb CHANGED
@@ -7,8 +7,8 @@ module Reek
7
7
  include Enumerable
8
8
 
9
9
  def initialize(sniffer = nil) # :nodoc:
10
- @masked_smells = SortedSet.new
11
- @report = SortedSet.new
10
+ @masked_warnings = SortedSet.new
11
+ @warnings = SortedSet.new
12
12
  sniffer.report_on(self) if sniffer
13
13
  end
14
14
 
@@ -16,7 +16,7 @@ module Reek
16
16
  # Yields, in turn, each SmellWarning in this report.
17
17
  #
18
18
  def each
19
- @report.each { |smell| yield smell }
19
+ @warnings.each { |smell| yield smell }
20
20
  end
21
21
 
22
22
  #
@@ -24,56 +24,58 @@ module Reek
24
24
  # only if one of them has a report string matching all of the +patterns+.
25
25
  #
26
26
  def has_smell?(smell_class, patterns)
27
- @report.any? { |smell| smell.matches?(smell_class, patterns) }
27
+ @warnings.any? { |smell| smell.matches?(smell_class, patterns) }
28
28
  end
29
29
 
30
30
  def <<(smell) # :nodoc:
31
- @report << smell
31
+ @warnings << smell
32
32
  true
33
33
  end
34
34
 
35
35
  def record_masked_smell(smell)
36
- @masked_smells << smell
36
+ @masked_warnings << smell
37
37
  end
38
38
 
39
39
  def num_masked_smells
40
- @masked_smells.length
40
+ @masked_warnings.length
41
41
  end
42
42
 
43
43
  def empty?
44
- @report.empty?
44
+ @warnings.empty?
45
45
  end
46
46
 
47
47
  def length
48
- @report.length
48
+ @warnings.length
49
49
  end
50
50
 
51
51
  alias size length
52
52
 
53
- def [](index) # :nodoc:
54
- @report.to_a[index]
55
- end
56
-
57
53
  # Creates a formatted report of all the +Smells::SmellWarning+ objects recorded in
58
54
  # this report, with a heading.
59
55
  def full_report(desc)
60
- result = header(desc, @report.length)
61
- result += ":\n#{to_s}" if length > 0
56
+ result = header(desc, @warnings.length)
57
+ result += ":\n#{to_s}" if should_report
62
58
  result += "\n"
63
59
  result
64
60
  end
65
61
 
62
+ def should_report
63
+ @warnings.length > 0 or (Options[:show_all] and @masked_warnings.length > 0)
64
+ end
65
+
66
66
  def header(desc, num_smells)
67
67
  result = "#{desc} -- #{num_smells} warning"
68
68
  result += 's' unless num_smells == 1
69
- result += " (+#{@masked_smells.length} masked)" unless @masked_smells.empty?
69
+ result += " (+#{@masked_warnings.length} masked)" unless @masked_warnings.empty?
70
70
  result
71
71
  end
72
72
 
73
73
  # Creates a formatted report of all the +Smells::SmellWarning+ objects recorded in
74
74
  # this report.
75
75
  def to_s
76
- @report.map {|smell| " #{smell.report}"}.join("\n")
76
+ all = SortedSet.new(@warnings)
77
+ all.merge(@masked_warnings) if Options[:show_all]
78
+ all.map {|smell| " #{smell.report}"}.join("\n")
77
79
  end
78
80
  end
79
81
 
@@ -9,17 +9,18 @@ module Reek
9
9
  include Comparable
10
10
 
11
11
  def initialize(smell, context, warning)
12
- @smell = smell
12
+ @detector = smell
13
13
  @context = context
14
14
  @warning = warning
15
+ @is_masked = smell.masked?
15
16
  end
16
17
 
17
18
  def hash # :nodoc:
18
- report.hash
19
+ basic_report.hash
19
20
  end
20
21
 
21
22
  def <=>(other)
22
- report <=> other.report
23
+ basic_report <=> other.basic_report
23
24
  end
24
25
 
25
26
  alias eql? <=> # :nodoc:
@@ -29,21 +30,26 @@ module Reek
29
30
  # +smell_class+ and its report string matches all of the +patterns+.
30
31
  #
31
32
  def matches?(smell_class, patterns)
32
- return false unless smell_class.to_s == @smell.class.class_name
33
+ return false unless smell_class.to_s == @detector.class.class_name
33
34
  rpt = report
34
35
  return patterns.all? {|exp| exp === rpt}
35
36
  end
36
37
 
38
+ def basic_report
39
+ Options[:format].gsub(/\%s/, @detector.smell_name).gsub(/\%c/, @context.to_s).gsub(/\%w/, @warning)
40
+ end
41
+
37
42
  #
38
43
  # Returns a copy of the current report format (see +Options+)
39
44
  # in which the following magic tokens have been substituted:
40
45
  #
41
- # * %s <-- the name of the smell that was detected
42
46
  # * %c <-- a description of the +CodeContext+ containing the smell
47
+ # * %m <-- "(is_masked) " if this is a is_masked smell
48
+ # * %s <-- the name of the smell that was detected
43
49
  # * %w <-- the specific problem that was detected
44
50
  #
45
51
  def report
46
- Options[:format].gsub(/\%s/, @smell.smell_name).gsub(/\%c/, @context.to_s).gsub(/\%w/, @warning)
52
+ basic_report.gsub(/\%m/, @is_masked ? '(masked) ' : '')
47
53
  end
48
54
  end
49
55
  end
@@ -58,6 +58,10 @@ module Reek
58
58
  @masked = true
59
59
  end
60
60
 
61
+ def masked?
62
+ @masked
63
+ end
64
+
61
65
  def enabled?
62
66
  @config[ENABLED_KEY]
63
67
  end
data/lib/reek.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  $:.unshift File.dirname(__FILE__)
2
2
 
3
3
  module Reek # :doc:
4
- VERSION = '1.1.3.8'
4
+ VERSION = '1.1.3.9'
5
5
  end
data/reek.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{reek}
5
- s.version = "1.1.3.8"
5
+ s.version = "1.1.3.9"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Kevin Rutherford"]
@@ -4,7 +4,7 @@ require 'reek/smells/smells'
4
4
 
5
5
  include Reek
6
6
 
7
- describe SmellWarning, ' in comparisons' do
7
+ describe SmellWarning, 'equality' do
8
8
  before :each do
9
9
  @first = SmellWarning.new(Smells::FeatureEnvy.new, "self", "self")
10
10
  @second = SmellWarning.new(Smells::FeatureEnvy.new, "self", "self")
@@ -62,7 +62,6 @@ describe 'sample gem source code' do
62
62
  ruby.should reek_of(:LongMethod, /OptionParser#parse_in_order/)
63
63
  ruby.should reek_of(:LongParameterList, /OptionParser#List#complete/)
64
64
  ruby.should reek_of(:LongParameterList, /OptionParser#List#update/)
65
- ruby.should reek_of(:LongParameterList, /OptionParser#Switch#initialize/)
66
65
  ruby.should reek_of(:LongParameterList, /OptionParser#Switch#summarize/)
67
66
  ruby.should reek_of(:LongParameterList, /OptionParser#complete/)
68
67
  ruby.should reek_of(:LongParameterList, /OptionParser#summarize/)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kevinrutherford-reek
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.3.8
4
+ version: 1.1.3.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin Rutherford