Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Bundler, 'def class' check #10

Closed
wants to merge 2 commits into from

2 participants

@duncan-bayne

I've moved the Gem deps to Bundler to make life easy in environments with conflicting rspec versions.

I've also added a check for 'def class', which is a bad idea (& recently cost me several hours of head-scratching).

@duncan-bayne

So this pull request has been here for two years ... any plans to accept it? I'm at a new job and I'm hoping to avoid creating yet another fork of Roodi :)

@martinjandrews
@duncan-bayne

Hey cool, I didn't realise. Now I can bribe you ... how about a coffee if you accept this pull request ;)

@martinjandrews

The Gemfile stuff had already been done, but I've now manually added your new check as well. Not yet released, but will be included when I upgrade some dependencies.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Sep 29, 2011
  1. Now uses Bundler for dependencies.

    Duncan Bayne authored
This page is out of date. Refresh to see the latest.
View
7 Gemfile
@@ -0,0 +1,7 @@
+source "http://rubygems.org/"
+
+gem 'rake'
+gem 'hoe'
+gem 'rspec'
+gem 'ruby_parser'
+gem 'rdoc'
View
21 Gemfile.lock
@@ -0,0 +1,21 @@
+GEM
+ remote: http://rubygems.org/
+ specs:
+ hoe (2.12.3)
+ rake (~> 0.8)
+ rake (0.9.2)
+ rdoc (3.9.3)
+ rspec (1.3.2)
+ ruby_parser (2.2.0)
+ sexp_processor (~> 3.0)
+ sexp_processor (3.0.6)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ hoe
+ rake
+ rdoc
+ rspec
+ ruby_parser
View
1  lib/roodi/checks.rb
@@ -16,3 +16,4 @@
require 'roodi/checks/module_name_check'
require 'roodi/checks/npath_complexity_method_check'
require 'roodi/checks/parameter_number_check'
+require 'roodi/checks/core_method_override_check'
View
25 lib/roodi/checks/core_method_override_check.rb
@@ -0,0 +1,25 @@
+require 'roodi/checks/check'
+
+module Roodi
+ module Checks
+ # Checks a class to make sure it doesn't override core methods on Object.
+ #
+ # An example is when the 'class' method of a class is overriden. This causes code
+ # that tests the class of an object to fail.
+ class CoreMethodOverrideCheck < Check
+
+ def interesting_nodes
+ [:defn]
+ end
+
+ def evaluate_start(node)
+ [ :class ].each do |core_name|
+ if node[1] == core_name
+ add_error("Class overrides method '#{core_name}'.")
+ end
+ end
+ end
+
+ end
+ end
+end
View
2  lib/roodi/checks/module_name_check.rb
@@ -4,7 +4,7 @@ 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.
+ # Keeping to a consistent naming convention makes your code easier to read.
class ModuleNameCheck < NameCheck
DEFAULT_PATTERN = /^[A-Z][a-zA-Z0-9]*$/
View
2  roodi.yml
@@ -13,4 +13,4 @@ MethodNameCheck: { pattern: !ruby/regexp /^[_a-z<>=\[|+-\/\*`]+[
ModuleLineCountCheck: { line_count: 300 }
ModuleNameCheck: { pattern: !ruby/regexp /^[A-Z][a-zA-Z0-9]*$/ }
ParameterNumberCheck: { parameter_count: 5 }
-
+CoreMethodOverrideCheck: { }
View
31 spec/roodi/checks/core_method_override_check_spec.rb
@@ -0,0 +1,31 @@
+require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
+
+describe Roodi::Checks::CoreMethodOverrideCheck do
+ before(:each) do
+ @roodi = Roodi::Core::Runner.new(Roodi::Checks::CoreMethodOverrideCheck.new)
+ end
+
+ it "should accept a class with a method" do
+ content = <<-END
+ class WellBehavedClass
+ def well_behaved_method
+ end
+ end
+ END
+ @roodi.check_content(content)
+ @roodi.errors.should be_empty
+ end
+
+ it "should reject a class which overrides the class method" do
+ content = <<-END
+ class BadClass
+ def class
+ end
+ end
+ END
+ @roodi.check_content(content)
+ errors = @roodi.errors
+ errors.should_not be_empty
+ errors[0].to_s.should eql("dummy-file.rb:2 - Class overrides method 'class'.")
+ end
+end
View
1  spec/roodi/roodi.yml
@@ -1 +1,2 @@
MethodNameCheck: { pattern: !ruby/regexp /^[A-Z]+$/ }
+CoreMethodOverrideCheck: { }
Something went wrong with that request. Please try again.