Skip to content

Commit

Permalink
Remove .script! hack
Browse files Browse the repository at this point in the history
  • Loading branch information
bkeepers committed Apr 17, 2015
1 parent 745ce14 commit 8a42f76
Show file tree
Hide file tree
Showing 36 changed files with 24 additions and 47 deletions.
2 changes: 1 addition & 1 deletion lib/linguist/language.rb
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ def inspect
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
Expand Down
7 changes: 2 additions & 5 deletions lib/linguist/samples.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,13 @@ def self.each(&block)
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
Expand Down
12 changes: 1 addition & 11 deletions lib/linguist/strategy/filename.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,7 @@ module Strategy
# 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
Expand Down
File renamed without changes.
File renamed without changes.
17 changes: 0 additions & 17 deletions samples/Groovy/build.script!

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
13 changes: 10 additions & 3 deletions test/test_samples.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ def test_verify
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__)
Expand All @@ -42,16 +50,15 @@ def test_verify
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

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
Expand Down
20 changes: 10 additions & 10 deletions test/test_tokenizer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,16 @@ def test_objective_c_tokens
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

Expand Down

0 comments on commit 8a42f76

Please sign in to comment.