diff --git a/.eslintrc b/.eslintrc new file mode 100644 index 0000000..f674032 --- /dev/null +++ b/.eslintrc @@ -0,0 +1,3 @@ +{ + "extends": "./node_modules/aurelia-tools/.eslintrc" +} diff --git a/build/tasks/lint.js b/build/tasks/lint.js index d10253f..b690fa4 100644 --- a/build/tasks/lint.js +++ b/build/tasks/lint.js @@ -1,10 +1,10 @@ var gulp = require('gulp'); var paths = require('../paths'); -var jshint = require('gulp-jshint'); -var stylish = require('jshint-stylish'); +var eslint = require('gulp-eslint'); gulp.task('lint', function() { return gulp.src(paths.source) - .pipe(jshint()) - .pipe(jshint.reporter(stylish)); + .pipe(eslint()) + .pipe(eslint.format()) + .pipe(eslint.failOnError()); }); diff --git a/package.json b/package.json index 4a72c4c..f08d33e 100644 --- a/package.json +++ b/package.json @@ -27,16 +27,16 @@ "devDependencies": { "aurelia-tools": "^0.1.6", "babel-dts-generator": "^0.2.5", + "babel-eslint": "^4.1.0", "conventional-changelog": "0.0.11", "del": "^1.1.0", "gulp": "^3.8.10", "gulp-babel": "^5.1.0", "gulp-bump": "^0.3.1", - "gulp-jshint": "^1.9.0", + "gulp-eslint": "^1.0.0", "gulp-rename": "^1.2.2", "gulp-yuidoc": "^0.1.2", "jasmine-core": "^2.1.3", - "jshint-stylish": "^1.0.0", "karma": "^0.12.28", "karma-babel-preprocessor": "^5.2.1", "karma-chrome-launcher": "^0.1.7", diff --git a/src/index.js b/src/index.js index d5f18fe..42d613c 100644 --- a/src/index.js +++ b/src/index.js @@ -1,40 +1,37 @@ -function trimDots(ary: string[]) { - var i, part; - for (i = 0; i < ary.length; ++i) { - part = ary[i]; - if (part === '.') { - ary.splice(i, 1); - i -= 1; - } else if (part === '..') { - // If at the start, or previous value is still .., - // keep them so that when converted to a path it may - // still work when converted to a path, even though - // as an ID it is less than ideal. In larger point - // releases, may be better to just kick out an error. - if (i === 0 || (i == 1 && ary[2] === '..') || ary[i - 1] === '..') { - continue; - } else if (i > 0) { - ary.splice(i - 1, 2); - i -= 2; - } +function trimDots(ary: string[]): void { + for (let i = 0; i < ary.length; ++i) { + let part = ary[i]; + if (part === '.') { + ary.splice(i, 1); + i -= 1; + } else if (part === '..') { + // If at the start, or previous value is still .., + // keep them so that when converted to a path it may + // still work when converted to a path, even though + // as an ID it is less than ideal. In larger point + // releases, may be better to just kick out an error. + if (i === 0 || (i === 1 && ary[2] === '..') || ary[i - 1] === '..') { + continue; + } else if (i > 0) { + ary.splice(i - 1, 2); + i -= 2; } + } } } -export function relativeToFile(name : string, file : string) : string { - var lastIndex, - normalizedBaseParts, - fileParts = (file && file.split('/')), - nameParts = name.trim().split('/'); +export function relativeToFile(name: string, file: string): string { + let fileParts = file && file.split('/'); + let nameParts = name.trim().split('/'); if (nameParts[0].charAt(0) === '.' && fileParts) { - //Convert file to array, and lop off the last part, - //so that . matches that 'directory' and not name of the file's - //module. For instance, file of 'one/two/three', maps to - //'one/two/three.js', but we want the directory, 'one/two' for - //this normalization. - normalizedBaseParts = fileParts.slice(0, fileParts.length - 1); - nameParts = normalizedBaseParts.concat(nameParts); + //Convert file to array, and lop off the last part, + //so that . matches that 'directory' and not name of the file's + //module. For instance, file of 'one/two/three', maps to + //'one/two/three.js', but we want the directory, 'one/two' for + //this normalization. + let normalizedBaseParts = fileParts.slice(0, fileParts.length - 1); + nameParts.unshift(...normalizedBaseParts); } trimDots(nameParts); @@ -42,39 +39,44 @@ export function relativeToFile(name : string, file : string) : string { return nameParts.join('/'); } -export function join(path1 : string, path2 : string) : string { - var url1, url2, url3, i, ii, urlPrefix, trailingSlash; - - if(!path1){ +export function join(path1: string, path2: string): string { + if (!path1) { return path2; } - if(!path2){ + if (!path2) { return path1; } - urlPrefix = path1.indexOf('//') === 0 ? '//' : - path1.indexOf('/') === 0 ? '/' : ''; - trailingSlash = path2.slice(-1) == '/' ? '/' : ''; + let urlPrefix; + if (path1.indexOf('//') === 0) { + urlPrefix = '//'; + } else if (path1.indexOf('/') === 0) { + urlPrefix = '/'; + } else { + urlPrefix = ''; + } - url1 = path1.split('/'); - url2 = path2.split('/'); - url3 = []; + let trailingSlash = path2.slice(-1) === '/' ? '/' : ''; - for (i = 0, ii = url1.length; i < ii; ++i) { - if (url1[i] == '..') { + let url1 = path1.split('/'); + let url2 = path2.split('/'); + let url3 = []; + + for (let i = 0, ii = url1.length; i < ii; ++i) { + if (url1[i] === '..') { url3.pop(); - } else if (url1[i] == '.' || url1[i] == '') { + } else if (url1[i] === '.' || url1[i] === '') { continue; } else { url3.push(url1[i]); } } - for (i = 0, ii = url2.length; i < ii; ++i) { - if (url2[i] == '..') { + for (let i = 0, ii = url2.length; i < ii; ++i) { + if (url2[i] === '..') { url3.pop(); - } else if (url2[i] == '.' || url2[i] == '') { + } else if (url2[i] === '.' || url2[i] === '') { continue; } else { url3.push(url2[i]); @@ -84,34 +86,22 @@ export function join(path1 : string, path2 : string) : string { return urlPrefix + url3.join('/').replace(/\:\//g, '://') + trailingSlash; } -var r20 = /%20/g, - rbracket = /\[\]$/, - class2type = {}; +export function buildQueryString(a: Object, traditional?: boolean): string { + let s = []; -'Boolean Number String Function Array Date RegExp Object Error'.split(' ').forEach((name, i) => { - class2type['[object ' + name + ']'] = name.toLowerCase(); -}); + function add(key: string, value: any) { + // If value is a function, invoke it and return its value + let v = value; + if (typeof value === 'function') { + v = value(); + } else if (value === null || value === undefined) { + v = ''; + } -function type( obj ){ - if (obj == null){ - return obj + ""; + s.push(encodeURIComponent(key) + '=' + encodeURIComponent(v)); } - // Support: Android<4.0 (functionish RegExp) - return typeof obj === 'object' || typeof obj === 'function' - ? class2type[ toString.call(obj) ] || 'object' - : typeof obj; -} - -export function buildQueryString(a : Object, traditional? : boolean) : string { - var s = [], - add = function(key:string, value:any) { - // If value is a function, invoke it and return its value - value = typeof value === 'function' ? value() : (value == null ? '' : value); - s[s.length] = encodeURIComponent(key) + '=' + encodeURIComponent(value); - }; - - for(let prefix in a){ + for (let prefix in a) { _buildQueryString(prefix, a[prefix], traditional, add); } @@ -119,30 +109,47 @@ export function buildQueryString(a : Object, traditional? : boolean) : string { return s.join('&').replace(r20, '+'); } -function _buildQueryString(prefix:string, obj:any, traditional:boolean, add: (p:string, v:any) => void){ - if (Array.isArray(obj)){ +function _buildQueryString(prefix: string, obj: any, traditional: boolean, add: (p: string, v: any) => void): void { + if (Array.isArray(obj)) { // Serialize array item. obj.forEach((v, i) => { - if(traditional || rbracket.test(prefix)){ + if (traditional || rbracket.test(prefix)) { // Treat each array item as a scalar. add(prefix, v); - } else{ + } else { // Item is non-scalar (array or object), encode its numeric index. - _buildQueryString( - prefix + '[' + (typeof v === 'object' ? i : '') + ']', - v, - traditional, - add - ); + let innerPrefix = prefix + '[' + (typeof v === 'object' ? i : '') + ']'; + _buildQueryString(innerPrefix, v, traditional, add); } }); - } else if (!traditional && type(obj) === 'object'){ + } else if (!traditional && type(obj) === 'object') { // Serialize object item. for (let name in obj) { _buildQueryString(prefix + '[' + name + ']', obj[name], traditional, add); } - } else{ + } else { // Serialize scalar item. add(prefix, obj); } } + +const r20 = /%20/g; +const rbracket = /\[\]$/; +const class2type = {}; + +'Boolean Number String Function Array Date RegExp Object Error' + .split(' ') + .forEach((name) => { + class2type['[object ' + name + ']'] = name.toLowerCase(); + }); + +function type(obj: any) { + if (obj === null || obj === undefined) { + return obj + ''; + } + + // Support: Android<4.0 (functionish RegExp) + return typeof obj === 'object' || typeof obj === 'function' + ? class2type[toString.call(obj)] || 'object' + : typeof obj; +}