Merge branch 'master' into bayesian

This commit is contained in:
Joshua Peek
2012-06-19 11:43:48 -05:00
3 changed files with 2996 additions and 11 deletions

View File

@@ -255,17 +255,16 @@ module Linguist
# Includes:
# - XCode project XML files
# - Minified JavaScript
# - Compiled CoffeeScript
# - PEG.js-generated parsers
#
# Please add additional test coverage to
# `test/test_blob.rb#test_generated` if you make any changes.
#
# Return true or false
def generated?
if xcode_project_file? || generated_net_docfile?
true
elsif generated_coffeescript? || minified_javascript?
true
elsif name == 'Gemfile.lock'
if name == 'Gemfile.lock' || minified_javascript? || compiled_coffeescript? ||
xcode_project_file? || generated_net_docfile? || generated_parser?
true
else
false
@@ -293,17 +292,36 @@ module Linguist
average_line_length > 100
end
# Internal: Is the blob JS generated by CoffeeScript?
# Internal: Is the blob of JS a parser generated by PEG.js?
#
# Requires Blob#data
#
# PEG.js-generated parsers are not meant to be consumed by humans.
#
# Return true or false
def generated_parser?
return false unless extname == '.js'
# PEG.js-generated parsers include a comment near the top of the file
# that marks them as such.
if lines[0..4].join('') =~ /^(?:[^\/]|\/[^\*])*\/\*(?:[^\*]|\*[^\/])*Generated by PEG.js/
return true
end
false
end
# Internal: Is the blob of JS generated by CoffeeScript?
#
# Requires Blob#data
#
# CoffeScript is meant to output JS that would be difficult to
# tell if it was generated or not. Look for a number of patterns
# outputed by the CS compiler.
# output by the CS compiler.
#
# Return true or false
def generated_coffeescript?
return unless extname == '.js'
def compiled_coffeescript?
return false unless extname == '.js'
# CoffeeScript generated by > 1.2 include a comment on the first line
if lines[0] =~ /^\/\/ Generated by /

2963
test/fixtures/javascript/parser.js vendored Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -167,9 +167,13 @@ class TestBlob < Test::Unit::TestCase
assert blob("javascript/jquery-1.6.1.min.js").generated?
assert blob("javascript/jquery-1.4.2.min.js").generated?
# CoffeScript JS
# CoffeeScript-generated JS
# TODO
# These examples are to basic to tell
# PEG.js-generated parsers
assert blob("javascript/parser.js").generated?
# These examples are too basic to tell
assert !blob("javascript/empty.js").generated?
assert !blob("javascript/hello.js").generated?