Skip to content

Commit

Permalink
Excluded Inline::C from UncommunicativeName
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinrutherford committed Feb 26, 2009
1 parent d6d1864 commit a478524
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 47 deletions.
31 changes: 21 additions & 10 deletions lib/reek/smells/uncommunicative_name.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,20 @@ module Smells
#
class UncommunicativeName < SmellDetector

BAD_NAMES_KEY = 'bad_names'
# The name of the config field that lists the regexps of
# smelly names to be rejected.
REJECT_KEY = 'reject'

# The name of the config field that lists the specific names that are
# to be treated as exceptions; these names will not be reported as
# uncommunicative.
ACCEPT_KEY = 'accept'

def self.default_config
super.adopt(BAD_NAMES_KEY => [/^.[0-9]*$/])
super.adopt(
REJECT_KEY => [/^.[0-9]*$/],
ACCEPT_KEY => ['Inline::C']
)
end

def self.contexts # :nodoc:
Expand All @@ -32,20 +42,20 @@ def self.contexts # :nodoc:

def initialize(config = UncommunicativeName.default_config)
super
@bad_names = config[BAD_NAMES_KEY]
@reject = config[REJECT_KEY]
@accept = config[ACCEPT_KEY]
end

#
# Checks the given +method+ for uncommunicative method name,
# parameter names, local variable names and instance variable names.
# Checks the given +context+ for uncommunicative names.
# Any smells found are added to the +report+.
#
def examine_context(context, report)
consider_name(context, report)
consider_variables(context, report)
end
def consider_variables(context, report)

def consider_variables(context, report) # :nodoc:
context.variable_names.each do |name|
next unless is_bad_name?(name)
report << SmellWarning.new(smell_name, context,
Expand All @@ -55,15 +65,16 @@ def consider_variables(context, report)

def consider_name(context, report) # :nodoc:
name = context.name
return false if @accept.include?(context.to_s) # TODO: fq_name() ?
return false unless is_bad_name?(name)
report << SmellWarning.new(smell_name, context,
"has the name '#{name}'")
end

def is_bad_name?(name)
def is_bad_name?(name) # :nodoc:
var = name.effective_name
return false if var == '*'
@bad_names.detect {|patt| patt === var}
return false if var == '*' or @accept.include?(var)
@reject.detect {|patt| patt === var}
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/reek/code_checks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ def check(desc, src, expected, pending_str = nil)
it(desc) do
pending(pending_str) unless pending_str.nil?
rpt = Analyser.new(src).analyse
rpt.length.should == expected.length
(0...rpt.length).each do |smell|
expected[smell].each { |patt| rpt[smell].report.should match(patt) }
end
rpt.length.should == expected.length
end
end
end
66 changes: 33 additions & 33 deletions spec/samples/inline.rb.expected
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
[Control Couple] Inline::C#parse_signature is controlled by argument raw
[Control Couple] Module#inline is controlled by argument options
[Duplication] Inline::C#build calls $?.==(0) multiple times
[Duplication] Inline::C#build calls Inline.directory multiple times
[Duplication] Inline::C#build calls io.puts(#endif) multiple times
[Duplication] Inline::C#build calls io.puts(#ifdef __cplusplus) multiple times
[Duplication] Inline::C#build calls io.puts multiple times
[Duplication] Inline::C#crap_for_windoze calls Config::CONFIG[libdir] multiple times
[Duplication] Inline::C#generate calls result.sub!((?-mix:\A\n), ) multiple times
[Duplication] Inline::C#generate calls signature[args].map multiple times
[Duplication] Inline::C#generate calls signature[args] multiple times
[Duplication] Inline::C#initialize calls stack.empty? multiple times
[Duplication] Inline::self.rootdir calls env.nil? multiple times
[Duplication] Module#inline calls Inline.const_get(lang) multiple times
[Feature Envy] Inline::C#module_name refers to md5 more than self
[Feature Envy] Inline::C#strip_comments refers to src more than self
[Large Class] Inline::C has at least 46 methods
[Long Method] File#self.write_with_backup has approx 6 statements
[Long Method] Inline::C#build has approx 61 statements
[Long Method] Inline::C#generate has approx 33 statements
[Long Method] Inline::C#load_cache has approx 7 statements
[Long Method] Inline::C#module_name has approx 6 statements
[Long Method] Inline::C#parse_signature has approx 15 statements
[Long Method] Inline::self.rootdir has approx 9 statements
[Long Method] Module#inline has approx 12 statements
[Nested Iterators] Inline::C#build/block/block is nested
[Uncommunicative Name] Inline::C#build/block/block has the variable name 'n'
[Uncommunicative Name] Inline::C#build has the variable name 't'
[Uncommunicative Name] Inline::C#c has the name 'c'
[Uncommunicative Name] Inline::C#module_name/block has the variable name 'm'
[Uncommunicative Name] Inline::C#module_name/block has the variable name 'x'
[Uncommunicative Name] Inline::C#parse_signature/block has the variable name 'x'
[Utility Function] Inline::C#strip_comments doesn't depend on instance state
File#self.write_with_backup has approx 6 statements (Long Method)
Inline::C has at least 46 methods (Large Class)
Inline::C#build calls $?.==(0) multiple times (Duplication)
Inline::C#build calls Inline.directory multiple times (Duplication)
Inline::C#build calls io.puts multiple times (Duplication)
Inline::C#build calls io.puts(#endif) multiple times (Duplication)
Inline::C#build calls io.puts(#ifdef __cplusplus) multiple times (Duplication)
Inline::C#build has approx 61 statements (Long Method)
Inline::C#build has the variable name 't' (Uncommunicative Name)
Inline::C#build/block/block has the variable name 'n' (Uncommunicative Name)
Inline::C#build/block/block is nested (Nested Iterators)
Inline::C#c has the name 'c' (Uncommunicative Name)
Inline::C#crap_for_windoze calls Config::CONFIG[libdir] multiple times (Duplication)
Inline::C#generate calls result.sub!((?-mix:\A\n), ) multiple times (Duplication)
Inline::C#generate calls signature[args] multiple times (Duplication)
Inline::C#generate calls signature[args].map multiple times (Duplication)
Inline::C#generate has approx 33 statements (Long Method)
Inline::C#initialize calls stack.empty? multiple times (Duplication)
Inline::C#load_cache has approx 7 statements (Long Method)
Inline::C#module_name has approx 6 statements (Long Method)
Inline::C#module_name refers to md5 more than self (Feature Envy)
Inline::C#module_name/block has the variable name 'm' (Uncommunicative Name)
Inline::C#module_name/block has the variable name 'x' (Uncommunicative Name)
Inline::C#parse_signature has approx 15 statements (Long Method)
Inline::C#parse_signature is controlled by argument raw (Control Couple)
Inline::C#parse_signature/block has the variable name 'x' (Uncommunicative Name)
Inline::C#strip_comments doesn't depend on instance state (Utility Function)
Inline::C#strip_comments refers to src more than self (Feature Envy)
Inline::self.rootdir calls env.nil? multiple times (Duplication)
Inline::self.rootdir has approx 9 statements (Long Method)
Module#inline calls Inline.const_get(lang) multiple times (Duplication)
Module#inline has approx 12 statements (Long Method)
Module#inline is controlled by argument options (Control Couple)
3 changes: 0 additions & 3 deletions spec/samples/inline.rb.reek

This file was deleted.

0 comments on commit a478524

Please sign in to comment.