Created
September 30, 2015 02:31
-
-
Save arthurnn/a6413b76ca644d97996c to your computer and use it in GitHub Desktop.
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
#!/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