Created
May 2, 2013 01:04
-
-
Save rorcraft/5499515 to your computer and use it in GitHub Desktop.
Custom CaneLintSpec
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--no-doc | |
--no-abc | |
--style-glob {app,lib}/**/*.rb | |
--require spec/cane_lint_spec.rb | |
--check CaneLintSpec | |
--lint-spec-glob {app,lib}/**/*.rb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CaneLintSpec < Struct.new(:opts) | |
def self.options | |
{ | |
lint_spec_glob: ['Glob to run lint_spec metrics over', | |
default: '{app,lib}/**/*.rb', | |
variable: 'GLOB', | |
clobber: :no_lint_spec], | |
no_lint_spec: ['Disable lint spec', | |
cast: ->(x) { !x } ] | |
} | |
end | |
def self.key; :lint_spec; end | |
def self.name; "Lint spec"; end | |
def violations | |
return [] if opts[:no_lint_spec] | |
worker.map(file_names) {|file_name| | |
find_violations(file_name) | |
}.flatten | |
end | |
private | |
def find_violations(file_name) | |
Cane::File.iterator(file_name).map.with_index do |line, line_number| | |
if line.match(/[^\#].*strftime/) | |
{ | |
file: file_name, | |
line: line_number + 1, | |
label: "Should not call strftime directly", | |
description: "Should not call strftime directly" | |
} | |
end | |
end.compact | |
end | |
def file_names | |
Dir[opts.fetch(:lint_spec_glob)] | |
end | |
def worker | |
Cane.task_runner(opts) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment