Skip to content

Commit 6ee1437

Browse files
committed
[eslint] add eslint
1 parent dc1cc12 commit 6ee1437

14 files changed

+103
-25
lines changed

.eslintrc

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
{
2+
"root": true,
3+
4+
"extends": "@ljharb",
5+
6+
"rules": {
7+
"array-bracket-newline": 0,
8+
"array-bracket-spacing": 1,
9+
"array-callback-return": 1,
10+
"brace-style": 1,
11+
"comma-spacing": 1,
12+
"complexity": 0,
13+
"consistent-return": 1,
14+
"curly": 1,
15+
"eqeqeq": 1,
16+
"func-style": 1,
17+
"indent": [1, 4],
18+
"max-depth": 0,
19+
"max-lines-per-function": 1,
20+
"max-statements": 0,
21+
"multiline-comment-style": 0,
22+
"no-else-return": 1,
23+
"no-lonely-if": 1,
24+
"no-negated-condition": 1,
25+
"no-param-reassign": 1,
26+
"no-shadow": 1,
27+
"no-template-curly-in-string": 0,
28+
"no-trailing-spaces": 1,
29+
"no-use-before-define": 1,
30+
"no-useless-escape": 1,
31+
"nonblock-statement-body-position": 1,
32+
"object-curly-spacing": 1,
33+
"prefer-regex-literals": 1,
34+
"quotes": 1,
35+
"space-before-blocks": 1,
36+
"space-before-function-paren": 1,
37+
"space-infix-ops": 1,
38+
"spaced-comment": 1,
39+
"wrap-regex": 1,
40+
},
41+
42+
"overrides": [
43+
{
44+
"files": "example/**",
45+
"rules": {
46+
"no-console": 0,
47+
},
48+
},
49+
],
50+
}

example/env.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use strict';
2+
13
var parse = require('../').parse;
24
var xs = parse('beep --boop="$PWD"', { PWD: '/home/robot' });
35
console.dir(xs);

example/op.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use strict';
2+
13
var parse = require('../').parse;
24
var xs = parse('beep || boop > /byte');
35
console.dir(xs);

example/parse.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use strict';
2+
13
var parse = require('../').parse;
24
var xs = parse('a "b c" \\$def \'it\\\'s great\'');
35
console.dir(xs);

example/quote.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use strict';
2+
13
var quote = require('../').quote;
24
var s = quote([ 'a', 'b c d', '$f', '"g"' ]);
35
console.log(s);

index.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use strict';
2+
13
exports.quote = function (xs) {
24
return xs.map(function (s) {
35
if (s && typeof s === 'object') {

package.json

+4
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
},
1010
"bugs": "https://github.com/substack/node-shell-quote/issues",
1111
"devDependencies": {
12+
"@ljharb/eslint-config": "^21.0.0",
1213
"aud": "^2.0.1",
14+
"eslint": "=8.8.0",
1315
"tape": "^5.6.1"
1416
},
1517
"homepage": "https://github.com/substack/node-shell-quote",
@@ -26,6 +28,8 @@
2628
"url": "http://github.com/substack/node-shell-quote.git"
2729
},
2830
"scripts": {
31+
"lint": "eslint --ext=js,mjs .",
32+
"pretest": "npm run lint",
2933
"tests-only": "tape 'test/**/*.js'",
3034
"test": "npm run tests-only",
3135
"posttest": "aud --production"

test/comment.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use strict';
2+
13
var test = require('tape');
24
var parse = require('../').parse;
35

test/env.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use strict';
2+
13
var test = require('tape');
24
var parse = require('../').parse;
35

@@ -17,22 +19,22 @@ test('expand environment variables', function (t) {
1719
t.same(parse("ab${x}def", { x: 'c' }), [ 'abcdef' ]);
1820
t.same(parse("ab\\${x}def", { x: 'c' }), [ 'ab${x}def' ]);
1921
t.same(parse('"ab\\${x}def"', { x: 'c' }), [ 'ab${x}def' ]);
20-
22+
2123
t.end();
2224
});
2325

2426
test('environment variables with metacharacters', function (t) {
2527
t.same(parse('a $XYZ c', { XYZ: '"b"' }), [ 'a', '"b"', 'c' ]);
2628
t.same(parse('a $XYZ c', { XYZ: '$X', X: 5 }), [ 'a', '$X', 'c' ]);
2729
t.same(parse('a"$XYZ"c', { XYZ: "'xyz'" }), [ "a'xyz'c" ]);
28-
30+
2931
t.end();
3032
});
3133

3234
test('special shell parameters', function (t) {
3335
var chars = '*@#?-$!0_'.split('');
3436
t.plan(chars.length);
35-
37+
3638
chars.forEach(function (c) {
3739
var env = {};
3840
env[c] = 'xxx';

test/env_fn.js

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
1+
'use strict';
2+
13
var test = require('tape');
24
var parse = require('../').parse;
35

46
test('functional env expansion', function (t) {
57
t.plan(4);
6-
8+
79
t.same(parse('a $XYZ c', getEnv), [ 'a', 'xxx', 'c' ]);
810
t.same(parse('a $XYZ c', getEnvObj), [ 'a', { op: '@@' }, 'c' ]);
911
t.same(parse('a${XYZ}c', getEnvObj), [ 'a', { op: '@@' }, 'c' ]);
1012
t.same(parse('"a $XYZ c"', getEnvObj), [ 'a ', { op: '@@' }, ' c' ]);
11-
12-
function getEnv (key) {
13+
14+
function getEnv() {
1315
return 'xxx';
1416
}
15-
16-
function getEnvObj (key) {
17+
18+
function getEnvObj() {
1719
return { op: '@@' };
1820
}
1921
});

test/op.js

+8-6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use strict';
2+
13
var test = require('tape');
24
var parse = require('../').parse;
35

@@ -6,21 +8,21 @@ test('single operators', function (t) {
68
t.same(parse('beep|boop'), [ 'beep', { op: '|' }, 'boop' ]);
79
t.same(parse('beep \\| boop'), [ 'beep', '|', 'boop' ]);
810
t.same(parse('beep "|boop"'), [ 'beep', '|boop' ]);
9-
11+
1012
t.same(parse('echo zing &'), [ 'echo', 'zing', { op: '&' } ]);
1113
t.same(parse('echo zing&'), [ 'echo', 'zing', { op: '&' } ]);
1214
t.same(parse('echo zing\\&'), [ 'echo', 'zing&' ]);
1315
t.same(parse('echo "zing\\&"'), [ 'echo', 'zing\\&' ]);
14-
16+
1517
t.same(parse('beep;boop'), [ 'beep', { op: ';' }, 'boop' ]);
1618
t.same(parse('(beep;boop)'), [
1719
{ op: '(' }, 'beep', { op: ';' }, 'boop', { op: ')' }
1820
]);
19-
21+
2022
t.same(parse('beep>boop'), [ 'beep', { op: '>' }, 'boop' ]);
2123
t.same(parse('beep 2>boop'), [ 'beep', '2', { op: '>' }, 'boop' ]);
2224
t.same(parse('beep<boop'), [ 'beep', { op: '<' }, 'boop' ]);
23-
25+
2426
t.end();
2527
});
2628

@@ -30,7 +32,7 @@ test('double operators', function (t) {
3032
t.same(parse('beep ||boop'), [ 'beep', { op: '||' }, 'boop' ]);
3133
t.same(parse('beep|| boop'), [ 'beep', { op: '||' }, 'boop' ]);
3234
t.same(parse('beep || boop'), [ 'beep', { op: '||' }, 'boop' ]);
33-
35+
3436
t.same(parse('beep && boop'), [ 'beep', { op: '&&' }, 'boop' ]);
3537
t.same(
3638
parse('beep && boop || byte'),
@@ -75,4 +77,4 @@ test('glob patterns', function (t) {
7577

7678
t.same(parse('tap "test/*.test.js"'), ['tap', 'test/*.test.js']);
7779
t.end();
78-
})
80+
});

test/parse.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use strict';
2+
13
var test = require('tape');
24
var parse = require('../').parse;
35

@@ -16,7 +18,7 @@ test('parse shell commands', function (t) {
1618
t.same(parse('a"b c d"e'), [ 'ab c de' ]);
1719
t.same(parse('a\\ b"c d"\\ e f'), [ 'a bc d e', 'f' ]);
1820
t.same(parse('a\\ b"c d"\\ e\'f g\' h'), [ 'a bc d ef g', 'h' ]);
19-
t.same(parse("x \"bl'a\"'h'"), ['x', "bl'ah"])
21+
t.same(parse("x \"bl'a\"'h'"), ['x', "bl'ah"]);
2022
t.same(parse("x bl^'a^'h'", {}, { escape: '^'}), ['x', "bl'a'h"]);
2123

2224
t.end();

test/quote.js

+10-8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use strict';
2+
13
var test = require('tape');
24
var quote = require('../').quote;
35

@@ -34,15 +36,15 @@ test('quote ops', function (t) {
3436
});
3537

3638
test('quote windows paths', { skip: 'breaking change, disabled until 2.x' }, function (t) {
37-
var path = 'C:\\projects\\node-shell-quote\\index.js'
39+
var path = 'C:\\projects\\node-shell-quote\\index.js';
3840

39-
t.equal(quote([path, 'b', 'c d']), 'C:\\projects\\node-shell-quote\\index.js b \'c d\'')
41+
t.equal(quote([path, 'b', 'c d']), 'C:\\projects\\node-shell-quote\\index.js b \'c d\'');
4042

41-
t.end()
42-
})
43+
t.end();
44+
});
4345

4446
test("chars for windows paths don't break out", function (t) {
45-
var x = '`:\\a\\b'
46-
t.equal(quote([x]), '\\`\\:\\\\a\\\\b')
47-
t.end()
48-
})
47+
var x = '`:\\a\\b';
48+
t.equal(quote([x]), '\\`\\:\\\\a\\\\b');
49+
t.end();
50+
});

test/set.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use strict';
2+
13
var test = require('tape');
24
var parse = require('../').parse;
35

@@ -19,11 +21,11 @@ test('set env vars', function (t) {
1921
[ 'X=7 8 9', { op: ';' }, 'printx' ]
2022
);
2123
t.same(
22-
parse('X="7 8 9"; printx', function (key) {
24+
parse('X="7 8 9"; printx', function () {
2325
t.fail('should not have matched any keys');
2426
}),
2527
[ 'X=7 8 9', { op: ';' }, 'printx' ]
2628
);
27-
29+
2830
t.end();
2931
});

0 commit comments

Comments
 (0)