mirror of
https://github.com/KevinMidboe/linguist.git
synced 2025-10-29 17:50:22 +00:00
JS is minified if its average line length is greater than 100c
Fixes #27
This commit is contained in:
@@ -151,6 +151,17 @@ module Linguist
|
||||
lines.grep(/\S/).size
|
||||
end
|
||||
|
||||
# Internal: Compute average line length.
|
||||
#
|
||||
# Returns Integer.
|
||||
def average_line_length
|
||||
if lines.any?
|
||||
lines.inject(0) { |n, l| n += l.length } / lines.length
|
||||
else
|
||||
0
|
||||
end
|
||||
end
|
||||
|
||||
# Public: Is the blob a generated file?
|
||||
#
|
||||
# Generated source code is supressed in diffs and is ignored by
|
||||
@@ -166,16 +177,24 @@ module Linguist
|
||||
def generated?
|
||||
if ['.xib', '.nib', '.pbxproj'].include?(extname)
|
||||
true
|
||||
elsif generated_coffeescript?
|
||||
elsif generated_coffeescript? || minified_javascript?
|
||||
true
|
||||
elsif extname == '.js'
|
||||
# JS is minified if any lines are longer than 500c
|
||||
lines.any? { |l| l.length > 500 }
|
||||
else
|
||||
false
|
||||
end
|
||||
end
|
||||
|
||||
# Internal: Is the blob minified JS?
|
||||
#
|
||||
# Consider JS minified if the average line length is
|
||||
# greater then 100c.
|
||||
#
|
||||
# Returns true or false.
|
||||
def minified_javascript?
|
||||
return unless extname == '.js'
|
||||
average_line_length > 100
|
||||
end
|
||||
|
||||
# Internal: Is the blob JS generated by CoffeeScript?
|
||||
#
|
||||
# Requires Blob#data
|
||||
|
||||
Reference in New Issue
Block a user