lib/linguist/generated.rb in github-linguist-2.9.7 vs lib/linguist/generated.rb in github-linguist-2.10.0
- old
+ new
@@ -56,11 +56,13 @@
compiled_coffeescript? ||
xcode_project_file? ||
generated_parser? ||
generated_net_docfile? ||
generated_net_designer_file? ||
- generated_protocol_buffer?
+ generated_protocol_buffer? ||
+ generated_jni_header? ||
+ node_modules?
end
# Internal: Is the blob an XCode project file?
#
# Generated if the file extension is an XCode project
@@ -71,18 +73,20 @@
['.xib', '.nib', '.storyboard', '.pbxproj', '.xcworkspacedata', '.xcuserstate'].include?(extname)
end
# Internal: Is the blob minified files?
#
- # Consider a file minified if it contains more than 5% spaces.
+ # Consider a file minified if the average line length is
+ # greater then 110c.
+ #
# Currently, only JS and CSS files are detected by this method.
#
# Returns true or false.
def minified_files?
return unless ['.js', '.css'].include? extname
- if data && data.length > 200
- (data.each_char.count{ |c| c <= ' ' } / data.length.to_f) < 0.05
+ if lines.any?
+ (lines.inject(0) { |n, l| n += l.length } / lines.length) > 110
else
false
end
end
@@ -178,8 +182,27 @@
def generated_protocol_buffer?
return false unless ['.py', '.java', '.h', '.cc', '.cpp'].include?(extname)
return false unless lines.count > 1
return lines[0].include?("Generated by the protocol buffer compiler. DO NOT EDIT!")
+ end
+
+ # Internal: Is the blob a C/C++ header generated by the Java JNI tool javah?
+ #
+ # Returns true of false.
+ def generated_jni_header?
+ return false unless extname == '.h'
+ return false unless lines.count > 2
+
+ return lines[0].include?("/* DO NOT EDIT THIS FILE - it is machine generated */") &&
+ lines[1].include?("#include <jni.h>")
+ end
+
+ # node_modules/ can contain large amounts of files, in general not meant
+ # for humans in pull requests.
+ #
+ # Returns true or false.
+ def node_modules?
+ !!name.match(/node_modules\//)
end
end
end