Skip to content

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also .

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also .
...
  • 9 commits
  • 4 files changed
  • 1 commit comment
  • 1 contributor
Showing with 32 additions and 14 deletions.
  1. +1 −1 lib/linguist/blob_helper.rb
  2. +14 −6 lib/linguist/language.rb
  3. +12 −5 lib/linguist/languages.yml
  4. +5 −2 test/test_language.rb
View
2 lib/linguist/blob_helper.rb
@@ -688,7 +688,7 @@ def colorize_without_wrapper(options = {})
Language.overridden_extensions.each do |extension|
name = "guess_#{extension.sub(/^\./, '')}_language".to_sym
unless instance_methods.map(&:to_sym).include?(name)
- warn "Language##{name} was not defined"
+ raise NotImplementedError, "Language##{name} was not defined"
end
end
end
View
20 lib/linguist/language.rb
@@ -43,26 +43,26 @@ def self.create(attributes = {})
@languages << language
- # All Language names should be unique. Warn if there is a duplicate.
+ # All Language names should be unique. Raise if there is a duplicate.
if @name_index.key?(language.name)
- warn "Duplicate language name: #{language.name}"
+ raise ArgumentError, "Duplicate language name: #{language.name}"
end
# Language name index
@index[language.name] = @name_index[language.name] = language
language.aliases.each do |name|
- # All Language aliases should be unique. Warn if there is a duplicate.
+ # All Language aliases should be unique. Raise if there is a duplicate.
if @alias_index.key?(name)
- warn "Duplicate alias: #{name}"
+ raise ArgumentError, "Duplicate alias: #{name}"
end
@index[name] = @alias_index[name] = language
end
language.extensions.each do |extension|
if extension !~ /^\./
- warn "Extension is missing a '.': #{extension.inspect}"
+ raise ArgumentError, "Extension is missing a '.': #{extension.inspect}"
end
unless ambiguous?(extension)
@@ -76,7 +76,11 @@ def self.create(attributes = {})
language.overrides.each do |extension|
if extension !~ /^\./
- warn "Extension is missing a '.': #{extension.inspect}"
+ raise ArgumentError, "Extension is missing a '.': #{extension.inspect}"
+ end
+
+ if l = @overrides[extension]
+ raise ArgumentError, "#{extension} is already overridden by #{l.name}"
end
@overrides[extension] = language
@@ -441,6 +445,10 @@ def eql?(other)
def hash
name.hash
end
+
+ def inspect
+ "#<#{self.class} name=#{name}>"
+ end
end
popular = YAML.load_file(File.expand_path("../popular.yml", __FILE__))
View
17 lib/linguist/languages.yml
@@ -12,7 +12,8 @@
# ace_mode - A String name of Ace Mode (if available)
# extension - An Array of associated extensions
# primary_extension - A String for the main extension associated with
-# the langauge. (defaults to extensions.first)
+# the langauge. (defaults to extensions.first).
+# Must be unique.
# overrides - An Array of extensions that takes precedence over conflicts
# searchable - Boolean flag to enable searching (defaults to true)
# search_term - Deprecated: Some languages maybe indexed under a
@@ -62,6 +63,9 @@ Ada:
Apex:
type: programming
lexer: Text only
+ primary_extension: .cls
+ overrides:
+ - .cls
extensions:
- .cls
@@ -267,6 +271,7 @@ Common Lisp:
Coq:
type: programming
+ primary_extension: .coq
extensions:
- .v
@@ -900,10 +905,9 @@ Perl:
type: programming
ace_mode: perl
color: "#0298c3"
+ primary_extension: .pl
overrides:
- .pl
- - .t
- primary_extension: .pl
extensions:
- .PL
- .perl
@@ -928,6 +932,7 @@ PowerShell:
Prolog:
type: programming
color: "#74283c"
+ primary_extension: .prolog
extensions:
- .pl
- .pro
@@ -1008,6 +1013,7 @@ Rebol:
type: programming
lexer: REBOL
color: "#358a5b"
+ primary_extension: .rebol
extensions:
- .r
- .r2
@@ -1189,8 +1195,6 @@ TeX:
type: markup
ace_mode: latex
primary_extension: .tex
- overrides:
- - .cls
extensions:
- .aux
- .cls
@@ -1224,6 +1228,9 @@ Turing:
type: programming
color: "#45f715"
lexer: Text only
+ primary_extension: .t
+ overrides:
+ - .t
extensions:
- .t
- .tu
View
7 test/test_language.rb
@@ -10,7 +10,7 @@ class TestLanguage < Test::Unit::TestCase
def test_ambiguous_extensions
assert Language.ambiguous?('.cls')
- assert_equal Language['TeX'], Language.find_by_extension('cls')
+ assert_equal Language['Apex'], Language.find_by_extension('cls')
assert Language.ambiguous?('.h')
assert_equal Language['C'], Language.find_by_extension('h')
@@ -25,7 +25,7 @@ def test_ambiguous_extensions
assert_equal Language['R'], Language.find_by_extension('r')
assert Language.ambiguous?('.t')
- assert_equal Language['Perl'], Language.find_by_extension('t')
+ assert_equal Language['Turing'], Language.find_by_extension('t')
assert Language.ambiguous?('.v')
assert_equal Language['Verilog'], Language.find_by_extension('v')
@@ -266,6 +266,8 @@ def test_find_by_extension
def test_find_all_by_extension
Language.all.each do |language|
+ assert_equal language, Language.find_by_extension(language.primary_extension)
+
language.extensions.each do |extension|
unless Language.ambiguous?(extension)
assert_equal language, Language.find_by_extension(extension)
@@ -355,6 +357,7 @@ def test_primary_extension
assert_equal '.rb', Language['Ruby'].primary_extension
assert_equal '.js', Language['JavaScript'].primary_extension
assert_equal '.coffee', Language['CoffeeScript'].primary_extension
+ assert_equal '.t', Language['Turing'].primary_extension
# This is a nasty requirement, but theres some code in GitHub that
# expects this. Really want to drop this.

Showing you all comments on commits in this comparison.

@abevoelker

Good idea... I should have done a bit more to sandbox the horrendous OpenEdge language from being falsely detected.

What would be neat is if there was an introspection method similar to the ambiguous extension handling that could be used to explicitly say "this file is not a <Language> file," except be usable in instances where there is no file extension ambiguity. Because when I added OE, a lot of cruft got pulled in and marked as OE because they had files ending in .p, but were definitely not valid OE code. Perhaps that's being a bit too OCD though... I suppose it would give repo owners incentive to add a lexer for the correct .p language.

Anyway, cool story bro and carry on

Something went wrong with that request. Please try again.