mirror of
				https://github.com/KevinMidboe/linguist.git
				synced 2025-10-29 17:50:22 +00:00 
			
		
		
		
	Compare commits
	
		
			15 Commits
		
	
	
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
|  | 22fbcc244b | ||
|  | 70b1ec97db | ||
|  | a97e328484 | ||
|  | e446b86b90 | ||
|  | 901e8da911 | ||
|  | e9036d675e | ||
|  | a5673e7fb6 | ||
|  | d06529fd14 | ||
|  | a02f19f5a3 | ||
|  | a9a62fff15 | ||
|  | 7625c92307 | ||
|  | 7dd318ca76 | ||
|  | e5bc2845cd | ||
|  | 4ddd8d9d2b | ||
|  | 37ffdb9020 | 
| @@ -53,7 +53,7 @@ module Linguist | ||||
|  | ||||
|     # Internal: Check if this heuristic matches the candidate languages. | ||||
|     def matches?(candidates) | ||||
|       candidates.all? { |l| @languages.include?(l.name) } | ||||
|       candidates.any? && candidates.all? { |l| @languages.include?(l.name) } | ||||
|     end | ||||
|  | ||||
|     # Internal: Perform the heuristic | ||||
|   | ||||
| @@ -1889,7 +1889,6 @@ PHP: | ||||
|   - .aw | ||||
|   - .ctp | ||||
|   - .fcgi | ||||
|   - .module | ||||
|   - .php3 | ||||
|   - .php4 | ||||
|   - .php5 | ||||
| @@ -2384,7 +2383,6 @@ Sass: | ||||
|   group: CSS | ||||
|   extensions: | ||||
|   - .sass | ||||
|   - .scss | ||||
|  | ||||
| Scala: | ||||
|   type: programming | ||||
|   | ||||
| @@ -19,7 +19,7 @@ module Linguist | ||||
|     # Returns a String or nil | ||||
|     def self.interpreter(data) | ||||
|       lines = data.lines | ||||
|       return unless match = /^#! ?(.*)$/.match(lines.first) | ||||
|       return unless match = /^#! ?(.+)$/.match(lines.first) | ||||
|  | ||||
|       tokens = match[1].split(' ') | ||||
|       script = tokens.first.split('/').last | ||||
|   | ||||
| @@ -1,3 +1,3 @@ | ||||
| module Linguist | ||||
|   VERSION = "4.2.0" | ||||
|   VERSION = "4.2.2" | ||||
| end | ||||
|   | ||||
							
								
								
									
										93
									
								
								samples/JavaScript/namespace.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										93
									
								
								samples/JavaScript/namespace.js
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,93 @@ | ||||
| (function(root, factory) { | ||||
|   if (typeof define === 'function' && define.amd) { | ||||
|     define(['lodash'], factory); | ||||
|   } else if (typeof exports !== 'undefined') { | ||||
|     module.exports = factory(require('lodash')); | ||||
|   } else { | ||||
|     root.Namespace = factory(root._); | ||||
|   } | ||||
| })(this, function(_) { | ||||
|   'use strict'; | ||||
|  | ||||
|   /** | ||||
|    * @module namespace | ||||
|    * @class namespace | ||||
|    */ | ||||
|   function Namespace() {} | ||||
|    | ||||
|   /** | ||||
|    * Regex for splitting keypaths into arrays. | ||||
|    * | ||||
|    * @private | ||||
|    * @const {RegExp} | ||||
|    * @type | ||||
|    */ | ||||
|   var KEYPATH_SPLITTER = /\./g; | ||||
|    | ||||
|   /** | ||||
|    * An internal cache to avoid calculating a keypath more than once. | ||||
|    * | ||||
|    * @private | ||||
|    * @type {Object} | ||||
|    */ | ||||
|   var _keypaths = {}; | ||||
|    | ||||
|   _.extend(Namespace.prototype, { | ||||
|    | ||||
|     /** | ||||
|      * Adds a definition to the namespace object. | ||||
|      * | ||||
|      * @public | ||||
|      * @instance | ||||
|      * @method add | ||||
|      * @param {String} keypath - The keypath for the definition to be added at. | ||||
|      * @param {Function|Object} definition - The definition to be added. | ||||
|      * @return {Function|Object} - The definition. | ||||
|      */ | ||||
|     add: function(keypath, definition) { | ||||
|       return this._walk(keypath, function(memo, name, index, keypath) { | ||||
|         if (index + 1 === keypath.length) { | ||||
|           memo[name] = _.extend(definition, memo[name]); | ||||
|         } | ||||
|         return memo[name] || (memo[name] = {}); | ||||
|       }); | ||||
|     }, | ||||
|    | ||||
|     /** | ||||
|      * Retrieves a definition from the namespace safely. | ||||
|      * | ||||
|      * @public | ||||
|      * @instance | ||||
|      * @method get | ||||
|      * @param {String} keypath - The keypath to lookup a definition for. | ||||
|      * @returns {Function|Object|undefined} - The definition if it exists, otherwise `undefined`. | ||||
|      */ | ||||
|     get: function(keypath) { | ||||
|       return this._walk(keypath); | ||||
|     }, | ||||
|    | ||||
|     /** | ||||
|      * An internal function for walking a keypath. | ||||
|      * | ||||
|      * @private | ||||
|      * @instance | ||||
|      * @method _walk | ||||
|      * @param {String} keypath - The keypath to walk through. | ||||
|      * @param {Function} [callback] - An optional callback to be called at each item in the path. | ||||
|      * @returns {function|Object|undefined} - The reduced keypath. | ||||
|      */ | ||||
|     _walk: function(keypath, callback) { | ||||
|       return _.reduce( | ||||
|         _keypaths[keypath] || (_keypaths[keypath] = keypath.split(KEYPATH_SPLITTER)), | ||||
|         callback || function(memo, name) { | ||||
|           return memo && memo[name]; | ||||
|         }, | ||||
|         this | ||||
|       ); | ||||
|     } | ||||
|   }); | ||||
|    | ||||
|   return Namespace; | ||||
| }); | ||||
|  | ||||
| //# sourceMappingURL=namespace.js.map | ||||
| @@ -1,12 +0,0 @@ | ||||
| $blue: #3bbfce; | ||||
| $margin: 16px; | ||||
|  | ||||
| .content_navigation { | ||||
|   color: $blue; | ||||
| } | ||||
|  | ||||
| .border { | ||||
|   padding: $margin / 2; | ||||
|   margin: $margin / 2; | ||||
|   border: 2px $blue solid; | ||||
| } | ||||
| @@ -13,6 +13,9 @@ set +x | ||||
|  | ||||
| mkdir -p ./vendor/gems | ||||
|  | ||||
| # Clean out any unversioned files | ||||
| git clean -fd | ||||
|  | ||||
| bundle install --local --path ./vendor/gems | ||||
| bundle exec rake samples | ||||
| bundle exec rake | ||||
|   | ||||
| @@ -469,16 +469,16 @@ class TestBlob < Test::Unit::TestCase | ||||
|     # Test language detection for files which shouldn't be used as samples | ||||
|     root = File.expand_path('../fixtures', __FILE__) | ||||
|     Dir.entries(root).each do |language| | ||||
|       next unless File.file?(language) | ||||
|       next if language == '.' || language == '..' | ||||
|  | ||||
|       # Each directory contains test files of a language | ||||
|       dirname = File.join(root, language) | ||||
|       Dir.entries(dirname).each do |filename| | ||||
|         next unless File.file?(filename) | ||||
|          | ||||
|         # By default blob search the file in the samples; | ||||
|         # thus, we need to give it the absolute path | ||||
|         filepath = File.join(dirname, filename) | ||||
|         next unless File.file?(filepath) | ||||
|  | ||||
|         blob = blob(filepath) | ||||
|         assert blob.language, "No language for #{filepath}" | ||||
|         assert_equal language, blob.language.name, blob.name | ||||
|   | ||||
| @@ -20,6 +20,12 @@ class TestHeuristcs < Test::Unit::TestCase | ||||
|     Dir.glob("#{samples_path}/#{language_name}/#{file}") | ||||
|   end | ||||
|  | ||||
|   def test_no_match | ||||
|     language = [] | ||||
|     results = Heuristics.call(file_blob("JavaScript/namespace.js"), language) | ||||
|     assert_equal [], results | ||||
|   end | ||||
|  | ||||
|   # Candidate languages = ["C++", "Objective-C"] | ||||
|   def test_obj_c_by_heuristics | ||||
|     # Only calling out '.h' filenames as these are the ones causing issues | ||||
|   | ||||
| @@ -16,6 +16,7 @@ class TestShebang < Test::Unit::TestCase | ||||
|     assert_interpreter nil, "\n\n\n\n\n" | ||||
|     assert_interpreter nil, " #!/usr/sbin/ruby" | ||||
|     assert_interpreter nil, "\n#!/usr/sbin/ruby" | ||||
|     assert_interpreter nil, "#!" | ||||
|  | ||||
|     assert_interpreter "ruby", "#!/usr/sbin/ruby\n# bar" | ||||
|     assert_interpreter "ruby", "#!/usr/bin/ruby\n# foo" | ||||
|   | ||||
		Reference in New Issue
	
	Block a user