Skip to content

Commit 4399c97

Browse files
committed
[eslint] add npm run lint
1 parent 1671ad5 commit 4399c97

File tree

6 files changed

+220
-179
lines changed

6 files changed

+220
-179
lines changed

.eslintrc

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"root": true,
3+
4+
"extends": "@ljharb",
5+
6+
"rules": {
7+
"func-style": ["error", "declaration"],
8+
"max-lines-per-function": "off",
9+
"max-statements-per-line": ["error", { "max": 2 }],
10+
"no-plusplus": "warn",
11+
"sort-keys": "off",
12+
},
13+
14+
"overrides": [
15+
{
16+
"files": "bin/**",
17+
"env": {
18+
"node": true,
19+
},
20+
"rules": {
21+
"no-process-exit": "off",
22+
}
23+
},
24+
{
25+
"files": "example/**",
26+
"rules": {
27+
"no-magic-numbers": "off",
28+
"no-plusplus": "off",
29+
},
30+
},
31+
],
32+
}

bin/cmd.js

Lines changed: 33 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
#!/usr/bin/env node
2+
3+
'use strict';
4+
25
var faucet = require('../');
36
var minimist = require('minimist');
47
var defined = require('defined');
@@ -9,65 +12,61 @@ var spawn = require('child_process').spawn;
912
var fs = require('fs');
1013
var path = require('path');
1114

15+
function jsFile(x) { return (/\.js$/i).test(x); }
16+
1217
var argv = minimist(process.argv.slice(2));
1318
var tap = faucet({
14-
width: defined(argv.w, argv.width, process.stdout.isTTY
15-
? process.stdout.columns - 5
16-
: 0
17-
)
19+
width: defined(argv.w, argv.width, process.stdout.isTTY
20+
? process.stdout.columns - 5
21+
: 0)
1822
});
1923
process.on('exit', function (code) {
20-
if (code === 0 && tap.exitCode !== 0) {
21-
process.exit(tap.exitCode);
22-
}
24+
if (code === 0 && tap.exitCode !== 0) {
25+
process.exit(tap.exitCode);
26+
}
2327
});
2428
process.stdout.on('error', function () {});
2529

2630
if (!process.stdin.isTTY || argv._[0] === '-') {
27-
process.stdin.pipe(tap).pipe(process.stdout);
28-
return;
31+
process.stdin.pipe(tap).pipe(process.stdout);
32+
return;
2933
}
3034

3135
var files = argv._.reduce(function (acc, file) {
32-
if (fs.statSync(file).isDirectory()) {
33-
return acc.concat(fs.readdirSync(file).map(function (x) {
34-
return path.join(file, x);
35-
}).filter(jsFile));
36-
}
37-
else return acc.concat(file);
36+
if (fs.statSync(file).isDirectory()) {
37+
return acc.concat(fs.readdirSync(file).map(function (x) {
38+
return path.join(file, x);
39+
}).filter(jsFile));
40+
}
41+
return acc.concat(file);
3842
}, []);
3943

4044
if (files.length === 0 && fs.existsSync('test')) {
41-
files.push.apply(files, fs.readdirSync('test').map(function (x) {
42-
return path.join('test', x);
43-
}).filter(jsFile));
45+
files.push.apply(files, fs.readdirSync('test').map(function (x) {
46+
return path.join('test', x);
47+
}).filter(jsFile));
4448
}
4549
if (files.length === 0 && fs.existsSync('tests')) {
46-
files.push.apply(files, fs.readdirSync('tests').map(function (x) {
47-
return path.join('tests', x);
48-
}).filter(jsFile));
50+
files.push.apply(files, fs.readdirSync('tests').map(function (x) {
51+
return path.join('tests', x);
52+
}).filter(jsFile));
4953
}
5054

5155
if (files.length === 0) {
52-
console.error('usage: `faucet [FILES]` or `| faucet`\n');
53-
console.error(
54-
'No test files or stdin provided and no files in test/ or tests/'
55-
+ ' directories found.'
56-
);
57-
return process.exit(1);
56+
console.error('usage: `faucet [FILES]` or `| faucet`\n');
57+
console.error('No test files or stdin provided and no files in test/ or tests/ directories found.');
58+
process.exit(1);
5859
}
5960

6061
var tape = spawn(tapeCmd, files);
6162
tape.stderr.pipe(process.stderr);
6263
tape.stdout.pipe(tap).pipe(process.stdout);
6364

6465
var tapeCode;
65-
tape.on('exit', function (code) { tapeCode = code });
66+
tape.on('exit', function (code) { tapeCode = code; });
6667
process.on('exit', function (code) {
67-
if (code === 0 && tapeCode !== 0) {
68-
console.error('# non-zero exit from the `tape` command');
69-
process.exit(tapeCode);
70-
}
68+
if (code === 0 && tapeCode !== 0) {
69+
console.error('# non-zero exit from the `tape` command');
70+
process.exit(tapeCode);
71+
}
7172
});
72-
73-
function jsFile (x) { return /\.js$/i.test(x) }

example/tape.js

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
1+
'use strict';
2+
13
var test = require('tape');
24

35
test('beep boop', function (t) {
4-
t.plan(2);
5-
6-
t.equal(1 + 1, 2);
7-
setTimeout(function () {
8-
t.deepEqual(
9-
'ABC'.toLowerCase().split(''),
10-
['a','b','c']
11-
);
12-
});
6+
t.plan(2);
7+
8+
t.equal(1 + 1, 2);
9+
setTimeout(function () {
10+
t.deepEqual(
11+
'ABC'.toLowerCase().split(''),
12+
[
13+
'a', 'b', 'c'
14+
]
15+
);
16+
});
1317
});

example/test.js

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,33 @@
1+
'use strict';
2+
13
var test = require('tape');
2-
function getMessage () {
3-
var msgs = [ 'yes', 'equals', 'matches', 'yep', 'pretty much', 'woo' ];
4-
return msgs[Math.floor(Math.random() * msgs.length)];
4+
5+
function getMessage() {
6+
var msgs = [
7+
'yes', 'equals', 'matches', 'yep', 'pretty much', 'woo'
8+
];
9+
return msgs[Math.floor(Math.random() * msgs.length)];
510
}
611

712
test('beep affirmative', function (t) {
8-
t.plan(24);
9-
var i = 0, n = 0;
10-
var iv = setInterval(function () {
11-
t.equal(i++, n++, getMessage());
12-
if (i === 24) clearInterval(iv);
13-
}, 50);
13+
t.plan(24);
14+
var i = 0,
15+
n = 0;
16+
var iv = setInterval(function () {
17+
t.equal(i++, n++, getMessage());
18+
if (i === 24) { clearInterval(iv); }
19+
}, 50);
1420
});
1521

1622
test('boop exterminate', function (t) {
17-
t.plan(20);
18-
var i = 0, n = 0;
19-
var iv = setInterval(function () {
20-
if ((i + 2) % 8 === 0) {
21-
t.equal(i, n + 6, getMessage())
22-
}
23-
else t.equal(i, n, getMessage());
24-
i++; n++;
25-
if (i === 20) clearInterval(iv);
26-
}, 100);
23+
t.plan(20);
24+
var i = 0,
25+
n = 0;
26+
var iv = setInterval(function () {
27+
if ((i + 2) % 8 === 0) {
28+
t.equal(i, n + 6, getMessage());
29+
} else { t.equal(i, n, getMessage()); }
30+
i++; n++;
31+
if (i === 20) { clearInterval(iv); }
32+
}, 100);
2733
});

0 commit comments

Comments
 (0)