mirror of
				https://github.com/KevinMidboe/linguist.git
				synced 2025-10-29 17:50:22 +00:00 
			
		
		
		
	Test that all languages have grammars
This will make CI fail if someone adds a new language but neglects to add a new grammar for it. This should make it easier for people to review PRs, as CI will help them to make sure a new grammar gets added. However, we currently support some languages that have no grammars, and we may support more in the future. So you can explicitly mark the language as having no grammar by setting `tm_scope: NONE` in languages.yml.
This commit is contained in:
		| @@ -1,5 +1,6 @@ | ||||
| require 'linguist/language' | ||||
| require 'test/unit' | ||||
| require 'yaml' | ||||
|  | ||||
| class TestLanguage < Test::Unit::TestCase | ||||
|   include Linguist | ||||
| @@ -359,4 +360,15 @@ class TestLanguage < Test::Unit::TestCase | ||||
|   def test_by_type | ||||
|     assert !Language.by_type(:prose).nil? | ||||
|   end | ||||
|  | ||||
|   def test_all_languages_have_grammars | ||||
|     scopes = YAML.load(File.read(File.expand_path("../../grammars.yml", __FILE__))).values.flatten | ||||
|     missing = Language.all.reject { |language| language.tm_scope == "NONE" || scopes.include?(language.tm_scope) } | ||||
|     message = "The following languages' scopes are not listed in grammars.yml. Please add grammars for all new languages.\n" | ||||
|     message << "If no grammar exists for a language, mark the language with `tm_scope: NONE` in lib/linguist/languages.yml.\n" | ||||
|  | ||||
|     width = missing.map { |language| language.name.length }.max | ||||
|     message << missing.map { |language| sprintf("%-#{width}s %s", language.name, language.tm_scope) }.sort.join("\n") | ||||
|     assert missing.empty?, message | ||||
|   end | ||||
| end | ||||
|   | ||||
		Reference in New Issue
	
	Block a user