Skip to content

Commit ac39ece

Browse files
committed
Merge remote-tracking branch 'origin/jshint' into jshint
2 parents 6b5ff57 + 95c6c0b commit ac39ece

File tree

5 files changed

+107
-75
lines changed

5 files changed

+107
-75
lines changed

lib/build/browserify.js

Lines changed: 50 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,11 @@ function compile(bannerWidth, transforms) {
112112
* @return {string} The transformed file path
113113
*/
114114
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 = [
115+
var rootRelPath = slash(path.relative(process.cwd(), path.resolve(filePath))); // resolve relative references
116+
var isProject = (rootRelPath.slice(0, 2) !== '..');
117+
var result = [
118118
sourceMapBase || '',
119-
isProject ? rootRelative : path.basename(rootRelative)
119+
isProject ? rootRelPath : path.basename(rootRelPath)
120120
].join(path.sep);
121121
if ((typeof i === 'number') && (typeof array === 'object')) {
122122
array[i] = result;
@@ -179,43 +179,52 @@ function compile(bannerWidth, transforms) {
179179
var timeout;
180180
function errorHandler(error) {
181181
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-
}
214-
215-
// add unique
216-
if (output.indexOf(message) < 0) {
217-
output.push(message);
218-
}
182+
[
183+
// SyntaxError: <file>:<reason>:<line>:<column>
184+
function() {
185+
var analysis = /^\s*SyntaxError\:\s*([^:]*)\s*\:\s*([^(]*)\s*\((\d+:\d+)\)\s*\n/.exec(text);
186+
return analysis && ([analysis[1], analysis[3], analysis[2]].join(':') + '\n');
187+
},
188+
// Error: SyntaxError: <reason> while parsing json file <file>
189+
function() {
190+
var analysis = /^\s*Error: SyntaxError\:\s*(.*)\s*while parsing json file\s*([^]*)/.exec(text);
191+
return analysis && ([analysis[2], '0', '0', ' ' + analysis[1]].join(':') + '\n');
192+
},
193+
// Line <line>: <reason>: <file>
194+
function() {
195+
var analysis = /Line\s*(\d+)\s*\:\s*([^:]*)\s*:\s*(.*)\s*/.exec(text);
196+
return analysis && ([analysis[3], analysis[1], 0, ' ' + analysis[2]].join(':') + '\n');
197+
},
198+
// Error: Cannot find module '<reason>' from '<directory>'
199+
// find the first text match for any text quoted in <reason>
200+
function() {
201+
var analysis = /^\s*Error\: Cannot find module '(.*)\'\s*from\s*\'(.*)\'\s*$/.exec(text);
202+
if (analysis) {
203+
var filename = fs.readdirSync(analysis[2])
204+
.filter(RegExp.prototype.test.bind(/\.js$/i))
205+
.filter(function (jsFilename) {
206+
var fullPath = path.join(analysis[2], jsFilename);
207+
var fileText = fs.readFileSync(fullPath).toString();
208+
return (new RegExp('[\'"]' + analysis[1] + '[\'"]')).test(fileText);
209+
})
210+
.shift();
211+
return path.join(analysis[2], filename) + ':0:0: Cannot find import ' + analysis[1] + '\n';
212+
}
213+
},
214+
// Unknown
215+
function() {
216+
return 'TODO parse this error\n' + text + '\n';
217+
}
218+
]
219+
.map(function(method) {
220+
return method();
221+
})
222+
.filter(Boolean)
223+
.forEach(function addUnique(message) {
224+
if (output.indexOf(message) < 0) {
225+
output.push(message);
226+
}
227+
});
219228

220229
// complete overall only once there are no further errors
221230
clearTimeout(timeout);

lib/build/node-sass.js

Lines changed: 34 additions & 24 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,12 +62,13 @@ 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 = [ ];
41-
do {
65+
var pathToRoot = [];
66+
var isWorking = true;
67+
while (isWorking) {
4268
pathToRoot.push(absoluteStart);
43-
var isWorking = (absoluteStart !== process.cwd()) && notPackage(absoluteStart);
69+
isWorking = (absoluteStart !== process.cwd()) && notPackage(absoluteStart);
4470
absoluteStart = path.resolve(absoluteStart, '..');
45-
} while (isWorking);
71+
}
4672

4773
// start a queue with the path to the root
4874
var queue = pathToRoot.concat();
@@ -57,30 +83,14 @@ function encodeRelativeURL(startPath, uri) {
5783

5884
// file exists so convert to a dataURI and end
5985
if (fs.existsSync(fullPath)) {
60-
var type = mime.lookup(fullPath);
86+
var type = mime.lookup(fullPath);
6187
var contents = fs.readFileSync(fullPath);
62-
var base64 = new Buffer(contents).toString('base64');
88+
var base64 = new Buffer(contents).toString('base64');
6389
return 'url(data:' + type + ';base64,' + base64 + ')';
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
}

lib/config/defaults.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ var instances = { };
1212
* @returns {{file: Function, defaults: Function, get: Function}}
1313
*/
1414
function getInstance(key) {
15-
return instances[key] = instances[key] || new Defaults(key);
15+
var result = instances[key] = instances[key] || new Defaults(key);
16+
return result;
1617
}
1718

1819
/**
@@ -39,10 +40,11 @@ function Defaults(key) {
3940
* @return {Defaults} the current instance
4041
*/
4142
function file() {
42-
var file = this.file_ = path.resolve(path.join.apply(path, arguments));
43-
if (file && fs.existsSync(file)) {
43+
/* jshint validthis:true */
44+
var filePath = this.file_ = path.resolve(path.join.apply(path, arguments));
45+
if (filePath && fs.existsSync(filePath)) {
4446
var existing = this.values_;
45-
this.values_ = readFile(file, this.key_) || {};
47+
this.values_ = readFile(filePath, this.key_) || {};
4648
this.set(existing);
4749
}
4850
return this;
@@ -54,6 +56,7 @@ function file() {
5456
* @return {Defaults} the current instance
5557
*/
5658
function defaults(parameters) {
59+
/* jshint validthis:true */
5760
this.defaults_ = (typeof parameters === 'object') ? parameters : {};
5861
return this;
5962
}
@@ -64,6 +67,7 @@ function defaults(parameters) {
6467
* @return {*} the resolved value of that field
6568
*/
6669
function get(field) {
70+
/* jshint validthis:true */
6771
if (field) {
6872
return (field in this.values_) ? this.values_[field] : this.defaults_[field];
6973
} else {
@@ -76,6 +80,7 @@ function get(field) {
7680
* @returns {Array.<string>} List of changed fields, possible empty
7781
*/
7882
function changeList() {
83+
/* jshint validthis:true */
7984
return Object.keys(this.values_);
8085
}
8186

@@ -86,6 +91,7 @@ function changeList() {
8691
* @return {Defaults} the current instance
8792
*/
8893
function set(objectOrField, value) {
94+
/* jshint validthis:true */
8995

9096
// enumerable object mode
9197
if (typeof objectOrField === 'object') {
@@ -115,6 +121,7 @@ function set(objectOrField, value) {
115121
* Clear any overrides
116122
*/
117123
function revert() {
124+
/* jshint validthis:true */
118125
this.values_ = {};
119126
return this;
120127
}
@@ -124,6 +131,7 @@ function revert() {
124131
* @return {string} the full path to the file that was written
125132
*/
126133
function commit() {
134+
/* jshint validthis:true */
127135
var pending;
128136
if (this.key_) {
129137
pending = readFile(this.file_) || {};

lib/inject/adjacent-files.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,19 @@ module.exports = function (extension, opts, recurse) {
3434

3535
// use terms in the relative address, from none to all
3636
var split = fileRelative.split(/[\\\/]/g);
37-
for(var i = 0, glob = [ ]; i < split.length; i++) {
38-
extensions.forEach(function(extension) {
37+
for(var i = 0, glob = []; i < split.length; i++) {
38+
extensions.forEach(addSliceToGlob(glob, 0, i + 1));
39+
}
40+
function addSliceToGlob(glob, start, stop) {
41+
return function (extension) {
3942
var item = [ fileRecurse ]
40-
.concat(split.slice(0, i + 1))
43+
.concat(split.slice(start, stop))
4144
.concat('*.' + extension)
4245
.join('/');
4346
if (glob.indexOf(item) < 0) {
4447
glob.push(item);
4548
}
46-
});
49+
};
4750
}
4851
return gulp.src(glob, { read: false })
4952
.pipe(semiflat(file.base))

lib/inject/bower-files.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ module.exports = function () {
8484

8585
function greatestCommonBase(absolute) {
8686
if (base) {
87-
for (var i = 0; (base[i] === absolute[i]); i++);
87+
for (var i = 0; (base[i] === absolute[i]); i++) {} /* jshint -W035 */
8888
base = base.slice(0, i);
8989
} else if (options.base === true) {
9090
base = path.dirname(absolute);
@@ -126,7 +126,9 @@ module.exports = function () {
126126

127127
// combination of source streams with specific base path for each package
128128
stream = combined.create();
129-
(prepend) && stream.append(prepend);
129+
if (prepend) {
130+
stream.append(prepend);
131+
}
130132
value.forEach(function (bowerPackage) {
131133
var src = gulp.src(bowerPackage.concat(), bowerPackage.options)
132134
.pipe(through.obj(function(file, encoding, done) {

0 commit comments

Comments
 (0)