Skip to content

Commit

Permalink
Added rdoc to checks.
Browse files Browse the repository at this point in the history
  • Loading branch information
martinjandrews committed Sep 14, 2008
1 parent 6c37c6f commit 2267714
Show file tree
Hide file tree
Showing 13 changed files with 63 additions and 11 deletions.
5 changes: 5 additions & 0 deletions lib/roodi/checks/case_missing_else_check.rb
Expand Up @@ -2,6 +2,11 @@

module Roodi
module Checks
# Checks a case statement to make sure it has an 'else' clause.
#
# It's usually a good idea to have an else clause in every case statement. Even if the
# developer is sure that all currently possible cases are covered, this should be
# expressed in the else clause. This way the code is protected aginst later changes,
class CaseMissingElseCheck < Check
def interesting_nodes
[:case]
Expand Down
4 changes: 4 additions & 0 deletions lib/roodi/checks/class_line_count_check.rb
Expand Up @@ -2,6 +2,10 @@

module Roodi
module Checks
# Checks a class to make sure the number of lines it has is under the specified limit.
#
# A class getting too large is a code smell that indicates it might be taking on too many
# responsibilities. It should probably be refactored into multiple smaller classes.
class ClassLineCountCheck < Check
DEFAULT_LINE_COUNT = 300

Expand Down
3 changes: 3 additions & 0 deletions lib/roodi/checks/class_name_check.rb
Expand Up @@ -2,6 +2,9 @@

module Roodi
module Checks
# Checks a class name to make sure it matches the specified pattern.
#
# Keeping to a consistent nameing convention makes your code easier to read.
class ClassNameCheck < Check
DEFAULT_PATTERN = /^[A-Z][a-zA-Z0-9]*$/

Expand Down
9 changes: 9 additions & 0 deletions lib/roodi/checks/cyclomatic_complexity_block_check.rb
Expand Up @@ -2,6 +2,15 @@

module Roodi
module Checks
# Checks cyclomatic complexity of a block against a specified limit.
#
# The cyclomatic complexity is measured by the number of "if", "unless", "elsif", "?:",
# "while", "until", "for", "rescue", "case", "when", "&amp;&amp;", "and", "||" and "or"
# statements (plus one) in the body of the member. It is a measure of the minimum
# number of possible paths through the source and therefore the number of required tests.
#
# Generally, for a block, 1-2 is considered good, 3-4 ok, 5-8 consider re-factoring, and 8+
# re-factor now!
class CyclomaticComplexityBlockCheck < CyclomaticComplexityCheck
DEFAULT_COMPLEXITY = 4

Expand Down
7 changes: 0 additions & 7 deletions lib/roodi/checks/cyclomatic_complexity_check.rb
Expand Up @@ -2,13 +2,6 @@

module Roodi
module Checks
# Checks cyclomatic complexity against a specified limit. The complexity is
# measured by the number of "if", "unless", "elsif", "?:", "while", "until",
# "for", "rescue", "case", "when", "&amp;&amp;", "and", "||" and "or" statements (plus
# one) in the body of the member. It is a measure of the minimum number of
# possible paths through the source and therefore the number of required tests.
# Generally 1-4 is considered good, 5-7 ok, 8-10 consider re-factoring, and
# 11+ re-factor now!
class CyclomaticComplexityCheck < Check
def initialize(complexity)
super()
Expand Down
9 changes: 9 additions & 0 deletions lib/roodi/checks/cyclomatic_complexity_method_check.rb
Expand Up @@ -2,6 +2,15 @@

module Roodi
module Checks
# Checks cyclomatic complexity of a method against a specified limit.
#
# The cyclomatic complexity is measured by the number of "if", "unless", "elsif", "?:",
# "while", "until", "for", "rescue", "case", "when", "&amp;&amp;", "and", "||" and "or"
# statements (plus one) in the body of the member. It is a measure of the minimum
# number of possible paths through the source and therefore the number of required tests.
#
# Generally, for a method, 1-4 is considered good, 5-8 ok, 9-10 consider re-factoring, and
# 11+ re-factor now!
class CyclomaticComplexityMethodCheck < CyclomaticComplexityCheck
DEFAULT_COMPLEXITY = 8

Expand Down
4 changes: 4 additions & 0 deletions lib/roodi/checks/empty_rescue_body_check.rb
Expand Up @@ -2,6 +2,10 @@

module Roodi
module Checks
# Checks the body of a rescue block to make sure it's not empty..
#
# When the body of a rescue block is empty, exceptions can get caught and swallowed without
# any feedback to the user.
class EmptyRescueBodyCheck < Check
def interesting_nodes
[:resbody]
Expand Down
5 changes: 5 additions & 0 deletions lib/roodi/checks/for_loop_check.rb
Expand Up @@ -2,6 +2,11 @@

module Roodi
module Checks
# Checks to make sure for loops are not being used..
#
# Using a for loop is not idiomatic use of Ruby, and is usually a sign that someone with
# more experience in a different programming language is trying out Ruby. Use
# Enumerable.each with a block instead.
class ForLoopCheck < Check
def interesting_nodes
[:for]
Expand Down
5 changes: 5 additions & 0 deletions lib/roodi/checks/method_line_count_check.rb
Expand Up @@ -2,6 +2,11 @@

module Roodi
module Checks
# Checks a method to make sure the number of lines it has is under the specified limit.
#
# A method getting too large is a code smell that indicates it might be doing more than one
# thing and becoming hard to test. It should probably be refactored into multiple methods
# that each do a single thing well.
class MethodLineCountCheck < Check
DEFAULT_LINE_COUNT = 20

Expand Down
7 changes: 5 additions & 2 deletions lib/roodi/checks/method_name_check.rb
Expand Up @@ -2,6 +2,9 @@

module Roodi
module Checks
# Checks a method name to make sure it matches the specified pattern.
#
# Keeping to a consistent nameing convention makes your code easier to read.
class MethodNameCheck < Check
DEFAULT_PATTERN = /^[_a-z<>=\[\]|+-\/\*`]+[_a-z0-9_<>=~@\[\]]*[=!\?]?$/

Expand All @@ -15,8 +18,8 @@ def interesting_nodes
end

def evaluate(node)
pattern = /^[_a-z<>=\[\]|+-\/\*`]+[_a-z0-9_<>=~@\[\]]*[=!\?]?$/
add_error "Method name \"#{node[1]}\" should match pattern #{@pattern.inspect}" unless node[1].to_s =~ @pattern
method_name = node[1]
add_error "Method name \"#{method_name}\" should match pattern #{@pattern.inspect}" unless method_name.to_s =~ @pattern
end
end
end
Expand Down
4 changes: 4 additions & 0 deletions lib/roodi/checks/module_line_count_check.rb
Expand Up @@ -2,6 +2,10 @@

module Roodi
module Checks
# Checks a module to make sure the number of lines it has is under the specified limit.
#
# A module getting too large is a code smell that indicates it might be taking on too many
# responsibilities. It should probably be refactored into multiple smaller modules.
class ModuleLineCountCheck < Check
DEFAULT_LINE_COUNT = 300

Expand Down
7 changes: 5 additions & 2 deletions lib/roodi/checks/module_name_check.rb
Expand Up @@ -2,6 +2,9 @@

module Roodi
module Checks
# Checks a module name to make sure it matches the specified pattern.
#
# Keeping to a consistent nameing convention makes your code easier to read.
class ModuleNameCheck < Check
DEFAULT_PATTERN = /^[A-Z][a-zA-Z0-9]*$/

Expand All @@ -15,8 +18,8 @@ def interesting_nodes
end

def evaluate(node)
class_name = node[1].class == Symbol ? node[1] : node[1].last
add_error "Module name \"#{class_name}\" should match pattern #{@pattern.inspect}" unless class_name.to_s =~ @pattern
module_name = node[1].class == Symbol ? node[1] : node[1].last
add_error "Module name \"#{module_name}\" should match pattern #{@pattern.inspect}" unless module_name.to_s =~ @pattern
end
end
end
Expand Down
5 changes: 5 additions & 0 deletions lib/roodi/checks/parameter_number_check.rb
Expand Up @@ -2,6 +2,11 @@

module Roodi
module Checks
# Checks a method to make sure the number of parameters it has is under the specified limit.
#
# A method taking too many parameters is a code smell that indicates it might be doing too
# much, or that the parameters should be grouped into one or more objects of their own. It
# probably needs some refactoring.
class ParameterNumberCheck < Check
DEFAULT_PARAMETER_COUNT = 5

Expand Down

0 comments on commit 2267714

Please sign in to comment.