Compare commits

...

15 Commits

Author SHA1 Message Date
Brandon Keepers
22fbcc244b Merge pull request #1820 from github/cut-release-v4.2.2
v4.2.2
2014-12-03 10:55:09 -08:00
Brandon Keepers
70b1ec97db Clean before running janky build 2014-12-03 10:07:59 -08:00
Brandon Keepers
a97e328484 v4.2.2 2014-12-03 09:58:08 -08:00
Brandon Keepers
e446b86b90 Merge pull request #1813 from github/invalid-shebang
Fix detection for invalid shebang
2014-12-03 09:48:48 -08:00
Arfon Smith
901e8da911 Merge pull request #1818 from github/remove-scss-from-sass
SCSS isnt SASS
2014-12-03 10:13:32 -06:00
Arfon Smith
e9036d675e SCSS isnt SASS 2014-12-03 10:12:58 -06:00
Brandon Keepers
a5673e7fb6 Fix detection for invalid shebang 2014-12-02 21:03:39 -06:00
Arfon Smith
d06529fd14 Merge pull request #1812 from github/cut-release-v4.2.1
Bumping linguist version
2014-12-02 20:30:30 -06:00
Arfon Smith
a02f19f5a3 Bumping linguist version 2014-12-02 20:06:36 -06:00
Arfon Smith
a9a62fff15 Merge pull request #1809 from pchaigno/fix-matches-heuristics
Fix error when matching languages against heuristics
2014-12-02 20:05:22 -06:00
Paul Chaignon
7625c92307 Remove .module extension for PHP 2014-12-02 20:37:09 -05:00
Paul Chaignon
7dd318ca76 Use namespace.js for the heuristic test with no match 2014-12-02 20:36:18 -05:00
Paul Chaignon
e5bc2845cd Fix for fixture tests: fixture files were not tested at all 2014-12-02 20:26:15 -05:00
Paul Chaignon
4ddd8d9d2b Unit test for fix #1809 on heuristics 2014-12-02 20:06:12 -05:00
Paul Chaignon
37ffdb9020 Fix error when matching languages against heuristics: if no language, no heuristic rule should be used 2014-12-02 16:41:39 -05:00
10 changed files with 110 additions and 21 deletions

View File

@@ -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

View File

@@ -1864,7 +1864,7 @@ Oxygene:
extensions:
- .oxygene
tm_scope: none
Oz:
type: programming
color: "#fcaf3e"
@@ -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

View File

@@ -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

View File

@@ -1,3 +1,3 @@
module Linguist
VERSION = "4.2.0"
VERSION = "4.2.2"
end

View 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

View File

@@ -1,12 +0,0 @@
$blue: #3bbfce;
$margin: 16px;
.content_navigation {
color: $blue;
}
.border {
padding: $margin / 2;
margin: $margin / 2;
border: 2px $blue solid;
}

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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"