Sha256: e8fcf2f45b2b203e731f09bdca4dd6a348337c06c5f385fbe8c9a32f9b024e56

Contents?: true

Size: 1.28 KB

Versions: 4

Compression:

Stored size: 1.28 KB

Contents

#!/usr/bin/ruby
#    This file is part of Metasm, the Ruby assembly manipulation suite
#    Copyright (C) 2006-2009 Yoann GUILLOT
#
#    Licence is LGPL, see LICENCE in the top-level directory


# this is a ruby code cleaner tool
# it passes its argument to ruby -v -c, which displays warnings (eg unused variable)
# it shows the incriminated line along the warning, to help identify false positives
# probably linux-only, and need ruby-1.9.1 or newer

def lint(tg)
	if File.symlink?(tg)
		# nothing
	elsif File.directory?(tg)
		Dir.entries(tg).each { |ent|
			next if ent == '.' or ent == '..'
			ent = File.join(tg, ent)
			lint(ent) if File.directory?(ent) or ent =~ /\.rb$/
		}
	else
		lint_file(tg)
	end
end

def lint_file(tg)
	flines = nil
	compile_warn(tg).each_line { |line|
		file, lineno, warn = line.split(/\s*:\s*/, 3)
		if file == tg
			if not flines
				puts "#{tg}:"
				flines = File.readlines(file) #File.open(file, 'rb') { |fd| fd.readlines }
			end
			puts " l.#{lineno}: #{warn.strip}: #{flines[lineno.to_i-1].strip.inspect}"
		end
	}
	puts if flines
end

def compile_warn(tg)
	r, w = IO.pipe('binary')
	if !fork
		r.close
		$stderr.reopen w
		$stdout.reopen '/dev/null'
		exec 'ruby', '-v', '-c', tg
		exit!
	else
		w.close
	end
	r
end

ARGV << '.' if ARGV.empty?
ARGV.each { |arg| lint arg }

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
metasm-1.0.5 misc/lint.rb
metasm-1.0.4 misc/lint.rb
metasm-1.0.3 misc/lint.rb
metasm-1.0.2 misc/lint.rb