Skip to content

Commit a69f0a0

Browse files
committed
Merge pull request #31 from angularity/jshint
Jshint fixes + Fixed CI problems
2 parents 7bc323e + e8725f6 commit a69f0a0

39 files changed

+245
-1045
lines changed

.jshintrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"maxparams": 20,
2222
"maxdepth": 5,
2323
"maxlen": 120,
24+
"scripturl": true,
2425
"node": true,
2526
"jasmine": true
2627
}

.travis.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,10 @@ matrix:
1010
fast_finish: true
1111
before_install:
1212
- npm install -g [email protected]
13-
- npm i -g
14-
- npm i -g jasmine-node
13+
- npm install -g
1514
- node -v
1615
- npm -v
17-
- jasmine-node --version
1816
script:
1917
- pwd && ls
20-
- jasmine-node --verbose --test-dir /home/travis/build/angularity/node-angularity/test
18+
- node node_modules/jasmine-node/bin/jasmine-node --version
19+
- npm run test

bin/cli.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,11 @@ var path = require('path'),
99
gulp = require('gulp'),
1010
gutil = require('gulp-util'),
1111
wordwrap = require('wordwrap'),
12-
runSequence = require('run-sequence'),
1312
chalk = require('chalk'),
1413
prettyTime = require('pretty-hrtime'),
1514
yargs = require('yargs');
1615

17-
var taskYargs = require('../lib/util/task-yargs'),
18-
taskYargsRun = require('../lib/util/task-yargs-run');
16+
var taskYargsRun = require('../lib/util/task-yargs-run');
1917

2018
// TODO @bholloway menus
2119
// var mainMenu = require('../lib/cli/mainMenu');
@@ -51,8 +49,8 @@ var defaultYargsInstance = yargs
5149
].join('\n')))
5250
// .example('angularity', 'Interactive menu') //TODO reinstate when interactive menu is reinstated
5351
.example('angularity -v', 'Display the version of angularity')
54-
.example('angularity \<task name\> -h', 'Get help on a particular task')
55-
.example('angularity \<task name\>', 'Run the given task')
52+
.example('angularity <task name> -h', 'Get help on a particular task')
53+
.example('angularity <task name>', 'Run the given task')
5654
.option('version', {
5755
describe: 'Display the curent version',
5856
alias: ['v'],

lib/build/browserify.js

Lines changed: 71 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
'use strict';
22

33
var fs = require('fs'),
4-
path = require('path'),
5-
through = require('through2'),
4+
path = require('path');
5+
6+
var through = require('through2'),
67
merge = require('lodash.merge'),
78
trackFilenames = require('gulp-track-filenames'),
89
transformTools = require('browserify-transform-tools'),
@@ -22,7 +23,7 @@ var fs = require('fs'),
2223
function isLiteralAST(node) {
2324
var candidates = Array.prototype.slice.call(arguments, 1);
2425
return (node) && (node.type === 'Literal') && candidates.some(function (candidate) {
25-
return (node.value === candidate)
26+
return (node.value === candidate);
2627
});
2728
}
2829

@@ -49,7 +50,7 @@ function isMethodAST(node) {
4950
* @return A jasmine transform
5051
*/
5152
function jasmineTransform(symbol) {
52-
return transformTools.makeFalafelTransform('jasmineTransform', null, function (node, options, done) {
53+
return transformTools.makeFalafelTransform('jasmineTransform', null, function jasmineASTWalker(node, options, done) {
5354
var isValid = isLiteralAST(node, symbol) && isMethodAST(node.parent, 'describe', 'module');
5455
if (isValid) {
5556
node.update('\'' + options.file.replace(/\\/g, '\\\\') + ':0:0\'');
@@ -112,11 +113,11 @@ function compile(bannerWidth, transforms) {
112113
* @return {string} The transformed file path
113114
*/
114115
function rootRelative(filePath, i, array) {
115-
var rootRelative = slash(path.relative(process.cwd(), path.resolve(filePath))); // resolve relative references
116-
var isProject = (rootRelative.slice(0, 2) !== '..');
117-
var result = [
116+
var rootRelPath = slash(path.relative(process.cwd(), path.resolve(filePath))); // resolve relative references
117+
var isProject = (rootRelPath.slice(0, 2) !== '..');
118+
var result = [
118119
sourceMapBase || '',
119-
isProject ? rootRelative : path.basename(rootRelative)
120+
isProject ? rootRelPath : path.basename(rootRelPath)
120121
].join(path.sep);
121122
if ((typeof i === 'number') && (typeof array === 'object')) {
122123
array[i] = result;
@@ -130,7 +131,7 @@ function compile(bannerWidth, transforms) {
130131
var BOWER = path.relative(process.cwd(), bowerDir.sync());
131132
return transformTools.makeRequireTransform('requireTransform', null, function (args, opts, done) {
132133

133-
// transform the original path where relevent
134+
// transform the original path where relevant
134135
var original = args[0];
135136
var split = original.split(/[\\\/]/g); // keep delimiters
136137
var firstTerm = split.splice(0, 1)[0]; // remove the first term from the split
@@ -178,39 +179,57 @@ function compile(bannerWidth, transforms) {
178179
// error handler
179180
var timeout;
180181
function errorHandler(error) {
181-
var text = error.toString();
182-
var analysis;
183-
var message;
184-
185-
// SyntaxError: <file>:<reason>:<line>:<column>
186-
if (analysis = /^\s*SyntaxError\:\s*([^:]*)\s*\:\s*([^(]*)\s*\((\d+:\d+)\)\s*\n/.exec(text)) {
187-
message = [analysis[1], analysis[3], analysis[2]].join(':') + '\n';
188-
189-
// Error: SyntaxError: <reason> while parsing json file <file>
190-
} else if (analysis = /^\s*Error: SyntaxError\:\s*(.*)\s*while parsing json file\s*([^]*)/.exec(text)) {
191-
message = [analysis[2], '0', '0', ' ' + analysis[1]].join(':') + '\n';
192-
193-
// Line <line>: <reason>: <file>
194-
} else if (analysis = /Line\s*(\d+)\s*\:\s*([^:]*)\s*:\s*(.*)\s*/.exec(text)) {
195-
message = [analysis[3], analysis[1], 0, ' ' + analysis[2]].join(':') + '\n';
196-
197-
// Error: Cannot find module '<reason>' from '<directory>'
198-
// find the first text match for any text quoted in <reason>
199-
} else if (analysis = /^\s*Error\: Cannot find module '(.*)\'\s*from\s*\'(.*)\'\s*$/.exec(text)) {
200-
var filename = fs.readdirSync(analysis[2])
201-
.filter(RegExp.prototype.test.bind(/\.js$/i))
202-
.filter(function (jsFilename) {
203-
var fullPath = path.join(analysis[2], jsFilename);
204-
var fileText = fs.readFileSync(fullPath).toString();
205-
return (new RegExp('[\'"]' + analysis[1] + '[\'"]')).test(fileText);
206-
})
207-
.shift();
208-
message = path.join(analysis[2], filename) + ':0:0: Cannot find import ' + analysis[1] + '\n';
209-
210-
// Unknown
211-
} else {
212-
message = 'TODO parse this error\n' + text + '\n';
213-
}
182+
183+
// run a bunch of tests against the error in order to determine the appropriate error message
184+
// there will be at least one truthy value, even if that is the final placeholder
185+
var text = error.toString();
186+
var message = [
187+
188+
// SyntaxError: <file>:<reason>:<line>:<column>
189+
function testSyntaxError() {
190+
var analysis = /^\s*SyntaxError\:\s*([^:]*)\s*\:\s*([^(]*)\s*\((\d+:\d+)\)\s*\n/.exec(text);
191+
return analysis && ([analysis[1], analysis[3], analysis[2]].join(':') + '\n');
192+
},
193+
194+
// Error: SyntaxError: <reason> while parsing json file <file>
195+
function testSyntaxErrorJSON() {
196+
var analysis = /^\s*Error: SyntaxError\:\s*(.*)\s*while parsing json file\s*([^]*)/.exec(text);
197+
return analysis && ([analysis[2], '0', '0', ' ' + analysis[1]].join(':') + '\n');
198+
},
199+
200+
// Line <line>: <reason>: <file>
201+
function testGeneric() {
202+
var analysis = /Line\s*(\d+)\s*\:\s*([^:]*)\s*:\s*(.*)\s*/.exec(text);
203+
return analysis && ([analysis[3], analysis[1], 0, ' ' + analysis[2]].join(':') + '\n');
204+
},
205+
206+
// Error: Cannot find module '<reason>' from '<directory>'
207+
// find the first text match for any text quoted in <reason>
208+
function testBadImport() {
209+
var analysis = /^\s*Error\: Cannot find module '(.*)\'\s*from\s*\'(.*)\'\s*$/.exec(text);
210+
if (analysis) {
211+
var filename = fs.readdirSync(analysis[2])
212+
.filter(RegExp.prototype.test.bind(/\.js$/i))
213+
.filter(function (jsFilename) {
214+
var fullPath = path.join(analysis[2], jsFilename);
215+
var fileText = fs.readFileSync(fullPath).toString();
216+
return (new RegExp('[\'"]' + analysis[1] + '[\'"]')).test(fileText);
217+
})
218+
.shift();
219+
return path.join(analysis[2], filename) + ':0:0: Cannot find import ' + analysis[1] + '\n';
220+
}
221+
},
222+
223+
// Unknown
224+
function otherwise() {
225+
return 'TODO parse this error\n' + text + '\n';
226+
}
227+
]
228+
.map(function invokeTestMethod(testMethod) {
229+
return testMethod();
230+
})
231+
.filter(Boolean)
232+
.shift();
214233

215234
// add unique
216235
if (output.indexOf(message) < 0) {
@@ -238,7 +257,7 @@ function compile(bannerWidth, transforms) {
238257
// transforms
239258
transforms
240259
.concat(requireTransform(false))
241-
.forEach(function (item, i, list) {
260+
.forEach(function eachItem(item, i, list) {
242261
if (typeof item === 'function') {
243262
var opts = (typeof list[i+1] === 'object') ? merge({ global: true }, list[i+1]) : { global: true };
244263
bundler.transform(item, opts);
@@ -247,7 +266,7 @@ function compile(bannerWidth, transforms) {
247266

248267
// require statements
249268
[].concat(files)
250-
.forEach(function (item) {
269+
.forEach(function eachItem(item) {
251270
bundler.require(item, {entry: true});
252271
});
253272

@@ -258,7 +277,7 @@ function compile(bannerWidth, transforms) {
258277
uglify : {
259278
compress: { // anything that changes semicolons to commas will cause debugger problems
260279
sequences: false,
261-
join_vars: false
280+
join_vars: false // jshint ignore:line
262281
},
263282
mangle : {
264283
toplevel: true
@@ -269,7 +288,7 @@ function compile(bannerWidth, transforms) {
269288

270289
// when we use minification we will get: error, code, source-map
271290
// when we don't we will get: error, buffer(with embedded source map)
272-
bundler.bundle(function (error, codeOrBuffer, map) {
291+
bundler.bundle(function onComplete(error, codeOrBuffer, map) {
273292
if (!error) {
274293
var code = codeOrBuffer.toString();
275294
var sourceMap = map ? JSON.parse(map) : convert.fromComment(code).toObject();
@@ -296,10 +315,10 @@ function compile(bannerWidth, transforms) {
296315
* @param {string} [sourceMapBase] Base path for source map file
297316
* @returns {stream.Through}
298317
*/
299-
each: function (isMinify, sourceMapBase) {
300-
return through.obj(function (file, encoding, done) {
318+
each: function gulpBundleEach(isMinify, sourceMapBase) {
319+
return through.obj(function transformFn(file, encoding, done) {
301320
bundle(this, [file.path], file.relative, isMinify, sourceMapBase, done);
302-
}, function (done) {
321+
}, function flushFn(done) {
303322
flushErrors();
304323
done();
305324
});
@@ -312,12 +331,12 @@ function compile(bannerWidth, transforms) {
312331
* @param {string} [sourceMapBase] Base path for source map file
313332
* @returns {stream.Through}
314333
*/
315-
all: function (outPath, isMinify, sourceMapBase) {
334+
all: function gulpBundleAll(outPath, isMinify, sourceMapBase) {
316335
var pending = [];
317-
return through.obj(function (file, encoding, done) {
336+
return through.obj(function transformFn(file, encoding, done) {
318337
pending.push(file.path);
319338
done();
320-
}, function (done) {
339+
}, function flushFn(done) {
321340
if (pending.length) {
322341
bundle(this, pending, outPath, isMinify, sourceMapBase, function () {
323342
flushErrors();

lib/build/node-sass.js

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,32 @@ function encodeRelativeURL(startPath, uri) {
2828
*/
2929
function notPackage(absolutePath) {
3030
return ['package.json', 'bower.json'].every(function fileNotFound(file) {
31-
return !(fs.existsSync(path.resolve(absolutePath, file)));
31+
return !(fs.existsSync(path.resolve(absolutePath, file)));
32+
});
33+
}
34+
35+
/**
36+
* Enqueue subdirectories that are not packages and are not in the root path
37+
* @param {Array} queue The queue to add to
38+
* @param {string} basePath The path to consider
39+
*/
40+
function enqueue(queue, basePath) {
41+
fs.readdirSync(basePath)
42+
.filter(function notHidden(filename) {
43+
return (filename.charAt(0) !== '.');
44+
})
45+
.map(function toAbsolute(filename) {
46+
return path.join(basePath, filename);
47+
})
48+
.filter(function directoriesOnly(absolutePath) {
49+
return fs.statSync(absolutePath).isDirectory();
50+
})
51+
.filter(function notInRootPath(absolutePath) {
52+
return (pathToRoot.indexOf(absolutePath) < 0);
53+
})
54+
.filter(notPackage)
55+
.forEach(function enqueue(absolutePath) {
56+
queue.push(absolutePath);
3257
});
3358
}
3459

@@ -37,10 +62,11 @@ function encodeRelativeURL(startPath, uri) {
3762
if (absoluteStart) {
3863

3964
// find path to the root, stopping at cwd, package.json or bower.json
40-
var pathToRoot = [ ];
65+
var pathToRoot = [];
66+
var isWorking;
4167
do {
4268
pathToRoot.push(absoluteStart);
43-
var isWorking = (absoluteStart !== process.cwd()) && notPackage(absoluteStart);
69+
isWorking = (absoluteStart !== process.cwd()) && notPackage(absoluteStart);
4470
absoluteStart = path.resolve(absoluteStart, '..');
4571
} while (isWorking);
4672

@@ -64,23 +90,7 @@ function encodeRelativeURL(startPath, uri) {
6490
}
6591
// enqueue subdirectories that are not packages and are not in the root path
6692
else {
67-
fs.readdirSync(basePath)
68-
.filter(function notHidden(filename) {
69-
return (filename.charAt(0) !== '.');
70-
})
71-
.map(function toAbsolute(filename) {
72-
return path.join(basePath, filename);
73-
})
74-
.filter(function directoriesOnly(absolutePath) {
75-
return fs.statSync(absolutePath).isDirectory();
76-
})
77-
.filter(function notInRootPath(absolutePath) {
78-
return (pathToRoot.indexOf(absolutePath) < 0);
79-
})
80-
.filter(notPackage)
81-
.forEach(function enqueue(absolutePath) {
82-
queue.push(absolutePath);
83-
});
93+
enqueue(queue, basePath);
8494
}
8595
}
8696
}
@@ -109,7 +119,7 @@ module.exports = function (bannerWidth, libraryPaths) {
109119

110120
/**
111121
* Push file contents to the output stream.
112-
* @param {string} ext The extention for the file, including dot
122+
* @param {string} ext The extension for the file, including dot
113123
* @param {string|object?} contents The contents for the file or fields to assign to it
114124
* @return {vinyl.File} The file that has been pushed to the stream
115125
*/
@@ -136,7 +146,7 @@ module.exports = function (bannerWidth, libraryPaths) {
136146
function reworkPlugin(stylesheet) {
137147

138148
// visit each node (selector) in the stylesheet recursively using the official utility method
139-
visit(stylesheet, function (declarations, node) {
149+
visit(stylesheet, function (declarations) {
140150

141151
// each node may have multiple declarations
142152
declarations.forEach(function (declaration) {

0 commit comments

Comments
 (0)