Skip to content

Instantly share code, notes, and snippets.

@rorcraft
Created May 2, 2013 01:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rorcraft/5499515 to your computer and use it in GitHub Desktop.
Save rorcraft/5499515 to your computer and use it in GitHub Desktop.
Custom CaneLintSpec
--no-doc
--no-abc
--style-glob {app,lib}/**/*.rb
--require spec/cane_lint_spec.rb
--check CaneLintSpec
--lint-spec-glob {app,lib}/**/*.rb
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