mirror of
https://github.com/KevinMidboe/linguist.git
synced 2025-10-28 17:20:22 +00:00
Remove .script! hack
This commit is contained in:
@@ -541,7 +541,7 @@ module Linguist
|
||||
if extnames = extensions[name]
|
||||
extnames.each do |extname|
|
||||
if !options['extensions'].index { |x| x.downcase.end_with? extname.downcase }
|
||||
warn "#{name} has a sample with extension (#{extname.downcase}) that isn't explicitly defined in languages.yml" unless extname == '.script!'
|
||||
warn "#{name} has a sample with extension (#{extname.downcase}) that isn't explicitly defined in languages.yml"
|
||||
options['extensions'] << extname
|
||||
end
|
||||
end
|
||||
|
||||
@@ -50,16 +50,13 @@ module Linguist
|
||||
end
|
||||
else
|
||||
path = File.join(dirname, filename)
|
||||
|
||||
if File.extname(filename) == ""
|
||||
raise "#{path} is missing an extension, maybe it belongs in filenames/ subdir"
|
||||
end
|
||||
extname = File.extname(filename)
|
||||
|
||||
yield({
|
||||
:path => path,
|
||||
:language => category,
|
||||
:interpreter => Shebang.interpreter(File.read(path)),
|
||||
:extname => File.extname(filename)
|
||||
:extname => extname.empty? ? nil : extname
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
@@ -3,17 +3,7 @@ module Linguist
|
||||
# Detects language based on filename and/or extension
|
||||
class Filename
|
||||
def self.call(blob, _)
|
||||
name = blob.name.to_s
|
||||
|
||||
# A bit of an elegant hack. If the file is executable but extensionless,
|
||||
# append a "magic" extension so it can be classified with other
|
||||
# languages that have shebang scripts.
|
||||
extensions = FileBlob.new(name).extensions
|
||||
if extensions.empty? && blob.mode && (blob.mode.to_i(8) & 05) == 05
|
||||
name += ".script!"
|
||||
end
|
||||
|
||||
Language.find_by_filename(name)
|
||||
Language.find_by_filename(blob.name.to_s)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
task echoDirListViaAntBuilder() {
|
||||
description = 'Uses the built-in AntBuilder instance to echo and list files'
|
||||
//Docs: http://ant.apache.org/manual/Types/fileset.html
|
||||
|
||||
//Echo the Gradle project name via the ant echo plugin
|
||||
ant.echo(message: project.name)
|
||||
ant.echo(path)
|
||||
ant.echo("${projectDir}/samples")
|
||||
|
||||
//Gather list of files in a subdirectory
|
||||
ant.fileScanner{
|
||||
fileset(dir:"samples")
|
||||
}.each{
|
||||
//Print each file to screen with the CWD (projectDir) path removed.
|
||||
println it.toString() - "${projectDir}"
|
||||
}
|
||||
}
|
||||
@@ -34,6 +34,14 @@ class TestSamples < Minitest::Test
|
||||
assert !data["interpreters"].empty?
|
||||
end
|
||||
|
||||
def test_ext_or_shebang
|
||||
Samples.each do |sample|
|
||||
if sample[:extname].to_s.empty? && !sample[:filename]
|
||||
assert sample[:interpreter], "#{sample[:path]} should have a file extension or a shebang, maybe it belongs in filenames/ subdir"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Check that there aren't samples with extensions or interpreters that
|
||||
# aren't explicitly defined in languages.yml
|
||||
languages_yml = File.expand_path("../../lib/linguist/languages.yml", __FILE__)
|
||||
@@ -42,7 +50,6 @@ class TestSamples < Minitest::Test
|
||||
options['extensions'] ||= []
|
||||
if extnames = Samples.cache['extnames'][name]
|
||||
extnames.each do |extname|
|
||||
next if extname == '.script!'
|
||||
assert options['extensions'].index { |x| x.downcase.end_with? extname.downcase }, "#{name} has a sample with extension (#{extname.downcase}) that isn't explicitly defined in languages.yml"
|
||||
end
|
||||
end
|
||||
@@ -50,8 +57,8 @@ class TestSamples < Minitest::Test
|
||||
options['interpreters'] ||= []
|
||||
if interpreters = Samples.cache['interpreters'][name]
|
||||
interpreters.each do |interpreter|
|
||||
# next if extname == '.script!'
|
||||
assert options['interpreters'].include?(interpreter), "#{name} has a sample with an interpreter (#{interpreter}) that isn't explicitly defined in languages.yml"
|
||||
assert options['interpreters'].include?(interpreter),
|
||||
"#{name} has a sample with an interpreter (#{interpreter}) that isn't explicitly defined in languages.yml"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -84,16 +84,16 @@ class TestTokenizer < Minitest::Test
|
||||
end
|
||||
|
||||
def test_shebang
|
||||
assert_equal "SHEBANG#!sh", tokenize(:"Shell/sh.script!")[0]
|
||||
assert_equal "SHEBANG#!bash", tokenize(:"Shell/bash.script!")[0]
|
||||
assert_equal "SHEBANG#!zsh", tokenize(:"Shell/zsh.script!")[0]
|
||||
assert_equal "SHEBANG#!perl", tokenize(:"Perl/perl.script!")[0]
|
||||
assert_equal "SHEBANG#!python", tokenize(:"Python/python.script!")[0]
|
||||
assert_equal "SHEBANG#!ruby", tokenize(:"Ruby/ruby.script!")[0]
|
||||
assert_equal "SHEBANG#!ruby", tokenize(:"Ruby/ruby2.script!")[0]
|
||||
assert_equal "SHEBANG#!node", tokenize(:"JavaScript/js.script!")[0]
|
||||
assert_equal "SHEBANG#!php", tokenize(:"PHP/php.script!")[0]
|
||||
assert_equal "SHEBANG#!escript", tokenize(:"Erlang/factorial.script!")[0]
|
||||
assert_equal "SHEBANG#!sh", tokenize(:"Shell/sh")[0]
|
||||
assert_equal "SHEBANG#!bash", tokenize(:"Shell/bash")[0]
|
||||
assert_equal "SHEBANG#!zsh", tokenize(:"Shell/zsh")[0]
|
||||
assert_equal "SHEBANG#!perl", tokenize(:"Perl/perl")[0]
|
||||
assert_equal "SHEBANG#!python", tokenize(:"Python/python")[0]
|
||||
assert_equal "SHEBANG#!ruby", tokenize(:"Ruby/ruby")[0]
|
||||
assert_equal "SHEBANG#!ruby", tokenize(:"Ruby/ruby2")[0]
|
||||
assert_equal "SHEBANG#!node", tokenize(:"JavaScript/js")[0]
|
||||
assert_equal "SHEBANG#!php", tokenize(:"PHP/php")[0]
|
||||
assert_equal "SHEBANG#!escript", tokenize(:"Erlang/factorial")[0]
|
||||
assert_equal "echo", tokenize(:"Shell/invalid-shebang.sh")[0]
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user