diff --git a/lib/linguist/generated.rb b/lib/linguist/generated.rb index a87bbc90..b53ae155 100644 --- a/lib/linguist/generated.rb +++ b/lib/linguist/generated.rb @@ -58,6 +58,7 @@ module Linguist godeps? || generated_by_zephir? || minified_files? || + source_map? || compiled_coffeescript? || generated_parser? || generated_net_docfile? || @@ -96,6 +97,20 @@ module Linguist 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