Skip to content

Instantly share code, notes, and snippets.

@arthurnn
Created September 30, 2015 02:31
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arthurnn/a6413b76ca644d97996c to your computer and use it in GitHub Desktop.
Save arthurnn/a6413b76ca644d97996c to your computer and use it in GitHub Desktop.
#!/usr/bin/ruby -w
require "sexp_processor"
require "ruby_parser"
class AssertScanner < MethodBasedSexpProcessor
def self.run paths
paths = expand_dirs_to_files(*paths)
paths.each do |path|
# warn path
begin
rp = RubyParser.new
self.new.process rp.process(File.read(path), path)
rescue RuntimeError, Racc::ParseError => e
warn "Skipping: parse error on #{path}: #{e.message}"
end
end
nil
end
ALLOWED_MSG_TYPES = [:hash]
def process_call sexp
_, recv, msg, *args = sexp
if recv == nil && msg == :assert && args.size == 2
if args.first.sexp_type == :str || ! ALLOWED_MSG_TYPES.include?(args.last.sexp_type)
puts " - %s:%s" % [sexp.file, sexp.line]
`emacsclient +#{sexp.line} #{sexp.file}`
end
end
sexp
end
end
AssertScanner.run ARGV if $0 == __FILE__
# Regex used to do the first pass
# find . "(" -name "*.rb" ")" -print0 | xargs -0 ruby -ne 'puts $_.gsub(/assert ([^,(]*(?:\(.*?\))*), (.+)/, "assert \\1, message: \\2")' -i
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment