Created
December 5, 2012 14:55
-
-
Save aereal/4216115 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/env ruby | |
LOOK = `which look 2>/dev/null`.strip | |
abort "#{$0} requires |look| executable command" unless File.executable?(LOOK) | |
def calculate_clarity(word) | |
candidates = `#{LOOK} -f #{word}`.strip.lines | |
$?.success? ? candidates.count : 0 | |
end | |
require "ruby_parser" | |
target_file = ARGF | |
sexp_tree = Ruby19Parser.new.parse(target_file.read) | |
definition_nodes = [:class, :cdecl, :lasgn, :args] | |
define_names = definition_nodes.flat_map {|node| sexp_tree.enum_for(:each_of_type, node).map {|exp| exp[1] } } | |
define_clarities = define_names.map {|name| calculate_clarity(name) } | |
definitions = define_names.zip(define_clarities) | |
threshold = 20 | |
too_ambiguous_names = definitions.select {|name, clarity| clarity >= threshold } | |
if $0 == __FILE__ | |
too_ambiguous_names.each do |name, clarity| | |
puts "#{name} => #{clarity}" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment