lib/linguist/generated.rb in github-linguist-4.5.2 vs lib/linguist/generated.rb in github-linguist-4.5.3
- old
+ new
@@ -56,10 +56,11 @@
composer_lock? ||
node_modules? ||
godeps? ||
generated_by_zephir? ||
minified_files? ||
+ source_map? ||
compiled_coffeescript? ||
generated_parser? ||
generated_net_docfile? ||
generated_postscript? ||
compiled_cython_file? ||
@@ -92,9 +93,23 @@
if lines.any?
(lines.inject(0) { |n, l| n += l.length } / lines.length) > 110
else
false
end
+ end
+
+ # Internal: Is the blob a generated source map?
+ #
+ # Source Maps usually have .css.map or .js.map extensions. In case they
+ # are not following the name convention, detect them based on the content.
+ #
+ # Returns true or false.
+ def source_map?
+ return false unless extname.downcase == '.map'
+
+ name =~ /(\.css|\.js)\.map$/i || # Name convention
+ lines[0] =~ /^{"version":\d+,/ || # Revision 2 and later begin with the version number
+ lines[0] =~ /^\/\*\* Begin line maps\. \*\*\/{/ # Revision 1 begins with a magic comment
end
# Internal: Is the blob of JS generated by CoffeeScript?
#
# CoffeeScript is meant to output JS that would be difficult to