From b103232e0e6a7b80c55753a931954a0b13d9e142 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=81=AA=E3=81=A4=E3=81=8D?= Date: Sun, 8 Mar 2015 08:07:37 -0700 Subject: [PATCH] Detect generated source maps --- lib/linguist/generated.rb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) 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