Skip to content

Commit 76d6ecf

Browse files
committed
Scaffold: Import jscs from gulp & fix formatting
1 parent 86bcf42 commit 76d6ecf

File tree

11 files changed

+126
-74
lines changed

11 files changed

+126
-74
lines changed

.jscsrc

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
{
2+
"disallowKeywords": ["with"],
3+
"disallowKeywordsOnNewLine": ["else"],
4+
"disallowMixedSpacesAndTabs": true,
5+
"disallowMultipleVarDecl": "exceptUndefined",
6+
"disallowNewlineBeforeBlockStatements": true,
7+
"disallowQuotedKeysInObjects": true,
8+
"disallowSpaceAfterObjectKeys": true,
9+
"disallowSpaceAfterPrefixUnaryOperators": true,
10+
"disallowSpacesInFunction": {
11+
"beforeOpeningRoundBrace": true
12+
},
13+
"disallowSpacesInsideParentheses": true,
14+
"disallowTrailingWhitespace": true,
15+
"maximumLineLength": null,
16+
"requireCamelCaseOrUpperCaseIdentifiers": true,
17+
"requireCapitalizedComments": true,
18+
"requireCapitalizedConstructors": true,
19+
"requireCurlyBraces": true,
20+
"requireSpaceAfterKeywords": [
21+
"if",
22+
"else",
23+
"for",
24+
"while",
25+
"do",
26+
"switch",
27+
"case",
28+
"return",
29+
"try",
30+
"catch",
31+
"typeof"
32+
],
33+
"requireSpaceAfterLineComment": true,
34+
"requireSpaceAfterBinaryOperators": true,
35+
"requireSpaceBeforeBinaryOperators": true,
36+
"requireSpaceBeforeBlockStatements": true,
37+
"requireSpaceBeforeObjectValues": true,
38+
"requireSpacesInFunction": {
39+
"beforeOpeningCurlyBrace": true
40+
},
41+
"requireTrailingComma": {
42+
"ignoreSingleLine": true
43+
},
44+
"requireBlocksOnNewline": true,
45+
"validateIndentation": 2,
46+
"validateLineBreaks": "LF",
47+
"validateQuoteMarks": "'"
48+
}

index.js

Lines changed: 42 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -14,50 +14,50 @@ var completion = require('./lib/completion');
1414
var argv = require('minimist')(process.argv.slice(2));
1515
var taskTree = require('./lib/taskTree');
1616

17-
// set env var for ORIGINAL cwd
17+
// Set env var for ORIGINAL cwd
1818
// before anything touches it
1919
process.env.INIT_CWD = process.cwd();
2020

2121
var cli = new Liftoff({
2222
name: 'gulp',
2323
completions: completion,
2424
extensions: interpret.jsVariants,
25-
v8flags: v8flags
25+
v8flags: v8flags,
2626
});
2727

28-
// exit with 0 or 1
28+
// Exit with 0 or 1
2929
var failed = false;
3030
process.once('exit', function(code) {
3131
if (code === 0 && failed) {
3232
exit(1);
3333
}
3434
});
3535

36-
// parse those args m8
36+
// Parse those args m8
3737
var cliPackage = require('./package');
3838
var versionFlag = argv.v || argv.version;
3939
var tasksFlag = argv.T || argv.tasks;
4040
var tasks = argv._;
4141
var toRun = tasks.length ? tasks : ['default'];
4242

43-
// this is a hold-over until we have a better logging system
43+
// This is a hold-over until we have a better logging system
4444
// with log levels
4545
var simpleTasksFlag = argv['tasks-simple'];
4646
var shouldLog = !argv.silent && !simpleTasksFlag;
4747

4848
if (!shouldLog) {
49-
gutil.log = function(){};
49+
gutil.log = function() {};
5050
}
5151

52-
cli.on('require', function (name) {
52+
cli.on('require', function(name) {
5353
gutil.log('Requiring external module', chalk.magenta(name));
5454
});
5555

56-
cli.on('requireFail', function (name) {
56+
cli.on('requireFail', function(name) {
5757
gutil.log(chalk.red('Failed to load external module'), chalk.magenta(name));
5858
});
5959

60-
cli.on('respawn', function (flags, child) {
60+
cli.on('respawn', function(flags, child) {
6161
var nodeFlags = chalk.magenta(flags.join(', '));
6262
var pid = chalk.magenta(child.pid);
6363
gutil.log('Node flags detected:', nodeFlags);
@@ -69,13 +69,13 @@ function run() {
6969
cwd: argv.cwd,
7070
configPath: argv.gulpfile,
7171
require: argv.require,
72-
completion: argv.completion
72+
completion: argv.completion,
7373
}, handleArguments);
7474
}
7575

7676
module.exports = run;
7777

78-
// the actual logic
78+
// The actual logic
7979
function handleArguments(env) {
8080
if (versionFlag && tasks.length === 0) {
8181
gutil.log('CLI version', cliPackage.version);
@@ -99,14 +99,14 @@ function handleArguments(env) {
9999
exit(1);
100100
}
101101

102-
// check for semver difference between cli and local installation
102+
// Check for semver difference between cli and local installation
103103
if (semver.gt(cliPackage.version, env.modulePackage.version)) {
104104
gutil.log(chalk.red('Warning: gulp version mismatch:'));
105105
gutil.log(chalk.red('Global gulp is', cliPackage.version));
106106
gutil.log(chalk.red('Local gulp is', env.modulePackage.version));
107107
}
108108

109-
// chdir before requiring gulpfile to make sure
109+
// Chdir before requiring gulpfile to make sure
110110
// we let them chdir as needed
111111
if (process.cwd() !== env.cwd) {
112112
process.chdir(env.cwd);
@@ -116,14 +116,14 @@ function handleArguments(env) {
116116
);
117117
}
118118

119-
// this is what actually loads up the gulpfile
119+
// This is what actually loads up the gulpfile
120120
require(env.configPath);
121121
gutil.log('Using gulpfile', chalk.magenta(tildify(env.configPath)));
122122

123123
var gulpInst = require(env.modulePath);
124124
logEvents(gulpInst);
125125

126-
process.nextTick(function () {
126+
process.nextTick(function() {
127127
if (simpleTasksFlag) {
128128
return logTasksSimple(env, gulpInst);
129129
}
@@ -141,34 +141,33 @@ function logTasks(env, localGulp) {
141141
tree.label = 'Tasks for ' + chalk.magenta(tildify(env.configPath));
142142
archy(tree)
143143
.split('\n')
144-
.filter(function (v, i) {
145-
// log first line as is
146-
if ( i === 0 ) {
144+
.filter(function(v, i) {
145+
// Log first line as is
146+
if (i === 0) {
147147
gutil.log(v);
148-
return false;
148+
return false;
149149
}
150-
// search for longest line
151-
if ( v.length > padding ) {
150+
// Search for longest line
151+
if (v.length > padding) {
152152
padding = v.length;
153153
}
154154
return v.trim().length !== 0;
155-
156-
}).forEach(function (v) {
155+
}).forEach(function(v) {
157156
var line = v.split(' ');
158157
var task = line.slice(1).join(' ');
159158

160-
// log dependencies as is
161-
if ( rdependency.test(v) ) {
159+
// Log dependencies as is
160+
if (rdependency.test(v)) {
162161
gutil.log(v);
163-
// pretty task with optionnal description
164-
} else {
165-
gutil.log(
166-
line[0] + ' ' +
167-
chalk.cyan(task) +
168-
Array( padding + 3 - v.length ).join(' ') +
169-
( localGulp.tasks[task].fn.description || '' )
170-
);
162+
return;
171163
}
164+
165+
// Pretty task with optional description
166+
gutil.log(
167+
line[0] + ' ' + chalk.cyan(task) +
168+
Array(padding + 3 - v.length).join(' ') +
169+
(localGulp.tasks[task].fn.description || '')
170+
);
172171
});
173172
}
174173

@@ -178,7 +177,7 @@ function logTasksSimple(env, localGulp) {
178177
.trim());
179178
}
180179

181-
// format orchestrator errors
180+
// Format orchestrator errors
182181
function formatError(e) {
183182
if (!e.err) {
184183
return e.message;
@@ -189,38 +188,38 @@ function formatError(e) {
189188
return e.err.toString();
190189
}
191190

192-
// normal error
191+
// Normal error
193192
if (e.err.stack) {
194193
return e.err.stack;
195194
}
196195

197-
// unknown (string, number, etc.)
196+
// Unknown (string, number, etc.)
198197
return new Error(String(e.err)).stack;
199198
}
200199

201-
// wire up logging events
200+
// Wire up logging events
202201
function logEvents(gulpInst) {
203202

204203
// total hack due to poor error management in orchestrator
205-
gulpInst.on('err', function () {
204+
gulpInst.on('err', function() {
206205
failed = true;
207206
});
208207

209-
gulpInst.on('task_start', function (e) {
208+
gulpInst.on('task_start', function(e) {
210209
// TODO: batch these
211210
// so when 5 tasks start at once it only logs one time with all 5
212211
gutil.log('Starting', '\'' + chalk.cyan(e.task) + '\'...');
213212
});
214213

215-
gulpInst.on('task_stop', function (e) {
214+
gulpInst.on('task_stop', function(e) {
216215
var time = prettyTime(e.hrDuration);
217216
gutil.log(
218217
'Finished', '\'' + chalk.cyan(e.task) + '\'',
219218
'after', chalk.magenta(time)
220219
);
221220
});
222221

223-
gulpInst.on('task_err', function (e) {
222+
gulpInst.on('task_err', function(e) {
224223
var msg = formatError(e);
225224
var time = prettyTime(e.hrDuration);
226225
gutil.log(
@@ -231,7 +230,7 @@ function logEvents(gulpInst) {
231230
gutil.log(msg);
232231
});
233232

234-
gulpInst.on('task_not_found', function (err) {
233+
gulpInst.on('task_not_found', function(err) {
235234
gutil.log(
236235
chalk.red('Task \'' + err.task + '\' is not in your gulpfile')
237236
);
@@ -240,7 +239,7 @@ function logEvents(gulpInst) {
240239
});
241240
}
242241

243-
// fix stdout truncation on windows
242+
// Fix stdout truncation on windows
244243
function exit(code) {
245244
if (process.platform === 'win32' && process.stdout.bufferSize) {
246245
process.stdout.once('drain', function() {

lib/completion.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
var fs = require('fs');
44
var path = require('path');
55

6-
module.exports = function (name) {
6+
module.exports = function(name) {
77
if (typeof name !== 'string') {
88
throw new Error('Missing completion type');
99
}

lib/taskTree.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
'use strict';
22

3-
module.exports = function (tasks) {
3+
module.exports = function(tasks) {
44
return Object.keys(tasks)
5-
.reduce(function (prev, task) {
5+
.reduce(function(prev, task) {
66
prev.nodes.push({
77
label: task,
8-
nodes: tasks[task].dep
8+
nodes: tasks[task].dep,
99
});
1010
return prev;
1111
}, {
12-
nodes: []
12+
nodes: [],
1313
});
1414
};

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,15 @@
4242
"coveralls": "^2.7.0",
4343
"gulp": ">=3.8.10",
4444
"istanbul": "^0.3.0",
45+
"jscs": "^1.11.3",
4546
"jshint": "^2.5.0",
4647
"jshint-stylish": "^1.0.0",
4748
"lab": "^5.1.0",
4849
"marked-man": "^0.1.3"
4950
},
5051
"scripts": {
5152
"prepublish": "marked-man --name gulp docs/CLI.md > gulp.1",
52-
"lint": "jshint lib index.js --reporter node_modules/jshint-stylish/stylish.js --exclude node_modules",
53+
"lint": "jshint lib index.js --reporter node_modules/jshint-stylish/stylish.js --exclude node_modules && jscs index.js lib bin test",
5354
"test": "npm run-script lint && lab -cvm 5000",
5455
"coveralls": "istanbul cover _mocha --report lcovonly -- -R spec && cat ./coverage/lcov.info | coveralls && rm -rf ./coverage"
5556
},

test/es6.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ var code = require('code');
55

66
var child = require('child_process');
77

8-
lab.experiment('es6', function () {
8+
lab.experiment('es6', function() {
99

10-
lab.test('supports es6', function (done) {
10+
lab.test('supports es6', function(done) {
1111
child.exec('node ' + __dirname + '/../bin/gulp.js --cwd ./test --gulpfile test/gulpfile.es6', function(err, stdout) {
1212
code.expect(stdout).to.contain('Requiring external module 6to5/register');
1313
done(err);

test/flags-task-simple.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ var child = require('child_process');
88

99
var output = fs.readFileSync(__dirname + '/expected/flags-tasks-simple.txt', 'utf8').replace(/\r\n/g, '\n');
1010

11-
lab.experiment('flag: --tasks-simple', function () {
11+
lab.experiment('flag: --tasks-simple', function() {
1212

13-
lab.test('prints the task list in simple format', function (done) {
13+
lab.test('prints the task list in simple format', function(done) {
1414
child.exec('node ' + __dirname + '/../bin/gulp.js --tasks-simple --cwd ./test', function(err, stdout) {
1515
code.expect(stdout).to.equal(output);
1616
done(err);

test/flags-tasks.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ var code = require('code');
55

66
var child = require('child_process');
77

8-
lab.experiment('flag: --tasks', function () {
8+
lab.experiment('flag: --tasks', function() {
99

10-
lab.test('prints the task list', function (done) {
10+
lab.test('prints the task list', function(done) {
1111
child.exec('node ' + __dirname + '/../bin/gulp.js --tasks --cwd ./test', function(err, stdout) {
1212
code.expect(stdout).to.contain('Tasks for');
1313
stdout = stdout.replace(/\\/g, '/').split('Tasks for')[1].split('\n');

test/flags-version.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ var child = require('child_process');
88
var cliVersion = require('../package.json').version;
99
var gulpVersion = require('gulp/package.json').version;
1010

11-
lab.experiment('flag: --version', function () {
11+
lab.experiment('flag: --version', function() {
1212

13-
lab.test('prints the version of CLI and local gulp', function (done) {
13+
lab.test('prints the version of CLI and local gulp', function(done) {
1414
child.exec('node ' + __dirname + '/../bin/gulp.js --version --cwd ./test', function(err, stdout) {
1515
code.expect(stdout).to.contain('CLI version ' + cliVersion);
1616
code.expect(stdout).to.contain('Local version ' + gulpVersion);

test/gulpfile.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
var gulp = require('gulp');
44

5-
function noop(){}
6-
function described(){}
5+
function noop() {}
6+
function described() {}
77
described.description = 'description';
88

99
gulp.task('test1', noop);

0 commit comments

Comments
 (0)