mirror of
https://github.com/KevinMidboe/linguist.git
synced 2025-10-29 17:50:22 +00:00
Merge branch 'master' into bayesian
This commit is contained in:
@@ -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
2963
test/fixtures/javascript/parser.js
vendored
Normal file
File diff suppressed because it is too large
Load Diff
@@ -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?
|
||||
|
||||
|
||||
Reference in New Issue
Block a user