Skip to content

Commit 9e1f93c

Browse files
author
Contra
committed
new linting setup
1 parent 9aa5c45 commit 9e1f93c

File tree

7 files changed

+125
-52
lines changed

7 files changed

+125
-52
lines changed

.editorconfig

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# editorconfig.org
2+
root = true
3+
4+
[*]
5+
indent_style = space
6+
indent_size = 2
7+
end_of_line = lf
8+
charset = utf-8
9+
trim_trailing_whitespace = true
10+
insert_final_newline = true

.jshintrc

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,19 @@
11
{
2+
"camelcase": true,
3+
"curly": true,
4+
"eqeqeq": true,
5+
"freeze": true,
6+
"indent": 2,
7+
"newcap": false,
8+
"quotmark": "single",
9+
"maxdepth": 3,
10+
"maxstatements": 50,
11+
"maxlen": 80,
12+
"eqnull": true,
13+
"funcscope": true,
214
"strict": true,
315
"undef": true,
416
"unused": true,
517
"node": true,
618
"mocha": true
7-
}
19+
}

bin/gulp.js

+53-25
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,14 @@ var simpleTasksFlag = argv['tasks-simple'];
3232
var shouldLog = !argv.silent && !simpleTasksFlag;
3333

3434
// wire up a few err listeners to liftoff
35-
cli.on('require', function(name) {
36-
if (!shouldLog) return;
35+
cli.on('require', function (name) {
36+
if (!shouldLog) {
37+
return;
38+
}
3739
gutil.log('Requiring external module', chalk.magenta(name));
3840
});
3941

40-
cli.on('requireFail', function(name) {
42+
cli.on('requireFail', function (name) {
4143
gutil.log(chalk.red('Failed to load external module'), chalk.magenta(name));
4244
});
4345

@@ -59,7 +61,10 @@ function handleArguments(env) {
5961
}
6062

6163
if (!env.modulePath) {
62-
gutil.log(chalk.red('No local gulp install found in'), chalk.magenta(tildify(env.cwd)));
64+
gutil.log(
65+
chalk.red('Local gulp not found in'),
66+
chalk.magenta(tildify(env.cwd))
67+
);
6368
gutil.log(chalk.red('Try running: npm install gulp'));
6469
process.exit(1);
6570
}
@@ -72,16 +77,19 @@ function handleArguments(env) {
7277
// check for semver difference between cli and local installation
7378
if (semver.gt(cliPackage.version, env.modulePackage.version) && shouldLog) {
7479
gutil.log(chalk.red('Warning: gulp version mismatch:'));
75-
gutil.log(chalk.red('Running gulp is', cliPackage.version));
76-
gutil.log(chalk.red('Local gulp (installed in gulpfile dir) is', env.modulePackage.version));
80+
gutil.log(chalk.red('Global gulp is', cliPackage.version));
81+
gutil.log(chalk.red('Local gulp is', env.modulePackage.version));
7782
}
7883

7984
// chdir before requiring gulpfile to make sure
8085
// we let them chdir as needed
8186
if (process.cwd() !== env.cwd) {
8287
process.chdir(env.cwd);
8388
if (shouldLog) {
84-
gutil.log('Working directory changed to', chalk.magenta(tildify(env.cwd)));
89+
gutil.log(
90+
'Working directory changed to',
91+
chalk.magenta(tildify(env.cwd))
92+
);
8593
}
8694
}
8795

@@ -95,7 +103,7 @@ function handleArguments(env) {
95103
var gulpInst = require(env.modulePath);
96104
logEvents(gulpInst);
97105

98-
process.nextTick(function() {
106+
process.nextTick(function () {
99107
if (simpleTasksFlag) {
100108
return logTasksSimple(env, gulpInst);
101109
}
@@ -109,49 +117,69 @@ function handleArguments(env) {
109117
function logTasks(env, localGulp) {
110118
var tree = taskTree(localGulp.tasks);
111119
tree.label = 'Tasks for ' + chalk.magenta(tildify(env.configPath));
112-
archy(tree).split('\n').forEach(function(v) {
113-
if (v.trim().length === 0) return;
114-
gutil.log(v);
115-
});
120+
archy(tree)
121+
.split('\n')
122+
.forEach(function (v) {
123+
if (v.trim().length === 0) {
124+
return;
125+
}
126+
gutil.log(v);
127+
});
116128
}
117129

118130
function logTasksSimple(env, localGulp) {
119-
console.log(Object.keys(localGulp.tasks).join('\n').trim());
131+
console.log(Object.keys(localGulp.tasks)
132+
.join('\n')
133+
.trim());
120134
}
121135

122136
// format orchestrator errors
123137
function formatError(e) {
124-
if (!e.err) return e.message;
125-
if (e.err.message) return e.err.message;
138+
if (!e.err) {
139+
return e.message;
140+
}
141+
if (e.err.message) {
142+
return e.err.message;
143+
}
126144
return JSON.stringify(e.err);
127145
}
128146

129147
// wire up logging events
130148
function logEvents(gulpInst) {
131149

132150
// total hack due to fucked up error management in orchestrator
133-
gulpInst.on('err', function(){});
151+
gulpInst.on('err', function () {});
134152

135-
gulpInst.on('task_start', function(e) {
153+
gulpInst.on('task_start', function (e) {
136154
// TODO: batch these
137155
// so when 5 tasks start at once it only logs one time with all 5
138-
gutil.log('Starting', "'" + chalk.cyan(e.task) + "'...");
156+
gutil.log('Starting', '\'' + chalk.cyan(e.task) + '\'...');
139157
});
140158

141-
gulpInst.on('task_stop', function(e) {
159+
gulpInst.on('task_stop', function (e) {
142160
var time = prettyTime(e.hrDuration);
143-
gutil.log('Finished', "'" + chalk.cyan(e.task) + "'", 'after', chalk.magenta(time));
161+
gutil.log(
162+
'Finished', '\'' + chalk.cyan(e.task) + '\'',
163+
'after', chalk.magenta(time)
164+
);
144165
});
145166

146-
gulpInst.on('task_err', function(e) {
167+
gulpInst.on('task_err', function (e) {
147168
var msg = formatError(e);
148169
var time = prettyTime(e.hrDuration);
149-
gutil.log("'" + chalk.cyan(e.task) + "'", 'errored after', chalk.magenta(time), chalk.red(msg));
170+
gutil.log(
171+
'\'' + chalk.cyan(e.task) + '\'',
172+
'errored after',
173+
chalk.magenta(time),
174+
chalk.red(msg)
175+
);
150176
});
151177

152-
gulpInst.on('task_not_found', function(err) {
153-
gutil.log(chalk.red("Task '" + err.task + "' was not defined in your gulpfile but you tried to run it."));
154-
gutil.log('Please check the documentation for proper gulpfile formatting.');
178+
gulpInst.on('task_not_found', function (err) {
179+
gutil.log(
180+
chalk.red('Task \'' + err.task + '\' is not in your gulpfile')
181+
);
182+
gutil.log('Please check the documentation for proper gulpfile formatting');
155183
process.exit(1);
156184
});
157185
}

index.js

+17-5
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ function Gulp() {
1212
util.inherits(Gulp, Orchestrator);
1313

1414
Gulp.prototype.task = Gulp.prototype.add;
15-
Gulp.prototype.run = function() {
15+
Gulp.prototype.run = function () {
1616
// run() is deprecated as of 3.5 and will be removed in 4.0
1717
// use task dependencies instead
1818

@@ -24,15 +24,15 @@ Gulp.prototype.run = function() {
2424

2525
Gulp.prototype.src = vfs.src;
2626
Gulp.prototype.dest = vfs.dest;
27-
Gulp.prototype.watch = function(glob, opt, fn) {
27+
Gulp.prototype.watch = function (glob, opt, fn) {
2828
if (typeof opt === 'function' || Array.isArray(opt)) {
2929
fn = opt;
3030
opt = null;
3131
}
3232

3333
// array of tasks given
3434
if (Array.isArray(fn)) {
35-
return vfs.watch(glob, opt, function() {
35+
return vfs.watch(glob, opt, function () {
3636
this.start.apply(this, fn);
3737
}.bind(this));
3838
}
@@ -44,8 +44,20 @@ Gulp.prototype.watch = function(glob, opt, fn) {
4444
Gulp.prototype.Gulp = Gulp;
4545

4646
// deprecations
47-
deprecated.field('gulp.env has been deprecated. Use your own CLI parser instead. We recommend using yargs or minimist.', console.warn, Gulp.prototype, 'env', gutil.env);
48-
Gulp.prototype.run = deprecated.method('gulp.run() has been deprecated. Use task dependencies or gulp.watch task triggering instead.', console.warn, Gulp.prototype.run);
47+
deprecated.field('gulp.env has been deprecated. ' +
48+
'Use your own CLI parser instead. ' +
49+
'We recommend using yargs or minimist.',
50+
console.warn,
51+
Gulp.prototype,
52+
'env',
53+
gutil.env
54+
);
55+
56+
Gulp.prototype.run = deprecated.method('gulp.run() has been deprecated. ' +
57+
'Use task dependencies or gulp.watch task triggering instead.',
58+
console.warn,
59+
Gulp.prototype.run
60+
);
4961

5062
var inst = new Gulp();
5163
module.exports = inst;

lib/completion.js

+12-6
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,20 @@
33
var fs = require('fs');
44
var path = require('path');
55

6-
module.exports = function(name) {
7-
if (typeof name !== 'string') throw new Error('Missing completion type');
6+
module.exports = function (name) {
7+
if (typeof name !== 'string') {
8+
throw new Error('Missing completion type');
9+
}
810
var file = path.join(__dirname, '../completion', name);
911
try {
10-
console.log(fs.readFileSync(file, 'utf8'));
11-
process.exit(0);
12+
console.log(fs.readFileSync(file, 'utf8'));
13+
process.exit(0);
1214
} catch (err) {
13-
console.log('echo "Specified gulp shell auto-completion rules for \''+name+'\' not found"');
14-
process.exit(5);
15+
console.log(
16+
'echo "gulp autocompletion rules for',
17+
'\'' + name + '\'',
18+
'not found"'
19+
);
20+
process.exit(5);
1521
}
1622
};

lib/taskTree.js

+10-7
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
'use strict';
22

3-
module.exports = function(tasks) {
4-
return Object.keys(tasks).reduce(function(prev, task) {
5-
prev.nodes.push({
6-
label: task,
7-
nodes: tasks[task].dep
3+
module.exports = function (tasks) {
4+
return Object.keys(tasks)
5+
.reduce(function (prev, task) {
6+
prev.nodes.push({
7+
label: task,
8+
nodes: tasks[task].dep
9+
});
10+
return prev;
11+
}, {
12+
nodes: []
813
});
9-
return prev;
10-
}, {nodes: []});
1114
};

package.json

+10-8
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,21 @@
3838
"vinyl-fs": "^0.2.0"
3939
},
4040
"devDependencies": {
41-
"mocha": "^1.17.0",
42-
"mocha-lcov-reporter": "^0.0.1",
4341
"coveralls": "^2.7.0",
42+
"graceful-fs": "^3.0.0",
4443
"istanbul": "^0.2.3",
45-
"should": "^4.0.0",
46-
"rimraf": "^2.2.5",
47-
"q": "^1.0.0",
4844
"jshint": "^2.5.0",
49-
"graceful-fs": "^3.0.0",
50-
"mkdirp": "^0.5.0"
45+
"jshint-stylish": "^0.2.0",
46+
"mkdirp": "^0.5.0",
47+
"mocha": "^1.17.0",
48+
"mocha-lcov-reporter": "^0.0.1",
49+
"q": "^1.0.0",
50+
"rimraf": "^2.2.5",
51+
"should": "^4.0.0"
5152
},
5253
"scripts": {
53-
"test": "jshint --exclude node_modules . && mocha --reporter spec",
54+
"lint": "jshint lib bin index.js --reporter node_modules/jshint-stylish/stylish.js --exclude node_modules",
55+
"test": "npm run-script lint && mocha --reporter spec",
5456
"coveralls": "istanbul cover _mocha --report lcovonly -- -R spec && cat ./coverage/lcov.info | coveralls && rm -rf ./coverage"
5557
},
5658
"engineStrict": true,

0 commit comments

Comments
 (0)