Skip to content

Commit

Permalink
[eslint] add eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Oct 12, 2022
1 parent dc1cc12 commit 6ee1437
Show file tree
Hide file tree
Showing 14 changed files with 103 additions and 25 deletions.
50 changes: 50 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
"root": true,

"extends": "@ljharb",

"rules": {
"array-bracket-newline": 0,
"array-bracket-spacing": 1,
"array-callback-return": 1,
"brace-style": 1,
"comma-spacing": 1,
"complexity": 0,
"consistent-return": 1,
"curly": 1,
"eqeqeq": 1,
"func-style": 1,
"indent": [1, 4],
"max-depth": 0,
"max-lines-per-function": 1,
"max-statements": 0,
"multiline-comment-style": 0,
"no-else-return": 1,
"no-lonely-if": 1,
"no-negated-condition": 1,
"no-param-reassign": 1,
"no-shadow": 1,
"no-template-curly-in-string": 0,
"no-trailing-spaces": 1,
"no-use-before-define": 1,
"no-useless-escape": 1,
"nonblock-statement-body-position": 1,
"object-curly-spacing": 1,
"prefer-regex-literals": 1,
"quotes": 1,
"space-before-blocks": 1,
"space-before-function-paren": 1,
"space-infix-ops": 1,
"spaced-comment": 1,
"wrap-regex": 1,
},

"overrides": [
{
"files": "example/**",
"rules": {
"no-console": 0,
},
},
],
}
2 changes: 2 additions & 0 deletions example/env.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict';

var parse = require('../').parse;
var xs = parse('beep --boop="$PWD"', { PWD: '/home/robot' });
console.dir(xs);
2 changes: 2 additions & 0 deletions example/op.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict';

var parse = require('../').parse;
var xs = parse('beep || boop > /byte');
console.dir(xs);
2 changes: 2 additions & 0 deletions example/parse.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict';

var parse = require('../').parse;
var xs = parse('a "b c" \\$def \'it\\\'s great\'');
console.dir(xs);
2 changes: 2 additions & 0 deletions example/quote.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict';

var quote = require('../').quote;
var s = quote([ 'a', 'b c d', '$f', '"g"' ]);
console.log(s);
2 changes: 2 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict';

exports.quote = function (xs) {
return xs.map(function (s) {
if (s && typeof s === 'object') {
Expand Down
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
},
"bugs": "https://github.com/substack/node-shell-quote/issues",
"devDependencies": {
"@ljharb/eslint-config": "^21.0.0",
"aud": "^2.0.1",
"eslint": "=8.8.0",
"tape": "^5.6.1"
},
"homepage": "https://github.com/substack/node-shell-quote",
Expand All @@ -26,6 +28,8 @@
"url": "http://github.com/substack/node-shell-quote.git"
},
"scripts": {
"lint": "eslint --ext=js,mjs .",
"pretest": "npm run lint",
"tests-only": "tape 'test/**/*.js'",
"test": "npm run tests-only",
"posttest": "aud --production"
Expand Down
2 changes: 2 additions & 0 deletions test/comment.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict';

var test = require('tape');
var parse = require('../').parse;

Expand Down
8 changes: 5 additions & 3 deletions test/env.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict';

var test = require('tape');
var parse = require('../').parse;

Expand All @@ -17,22 +19,22 @@ test('expand environment variables', function (t) {
t.same(parse("ab${x}def", { x: 'c' }), [ 'abcdef' ]);
t.same(parse("ab\\${x}def", { x: 'c' }), [ 'ab${x}def' ]);
t.same(parse('"ab\\${x}def"', { x: 'c' }), [ 'ab${x}def' ]);

t.end();
});

test('environment variables with metacharacters', function (t) {
t.same(parse('a $XYZ c', { XYZ: '"b"' }), [ 'a', '"b"', 'c' ]);
t.same(parse('a $XYZ c', { XYZ: '$X', X: 5 }), [ 'a', '$X', 'c' ]);
t.same(parse('a"$XYZ"c', { XYZ: "'xyz'" }), [ "a'xyz'c" ]);

t.end();
});

test('special shell parameters', function (t) {
var chars = '*@#?-$!0_'.split('');
t.plan(chars.length);

chars.forEach(function (c) {
var env = {};
env[c] = 'xxx';
Expand Down
12 changes: 7 additions & 5 deletions test/env_fn.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
'use strict';

var test = require('tape');
var parse = require('../').parse;

test('functional env expansion', function (t) {
t.plan(4);

t.same(parse('a $XYZ c', getEnv), [ 'a', 'xxx', 'c' ]);
t.same(parse('a $XYZ c', getEnvObj), [ 'a', { op: '@@' }, 'c' ]);
t.same(parse('a${XYZ}c', getEnvObj), [ 'a', { op: '@@' }, 'c' ]);
t.same(parse('"a $XYZ c"', getEnvObj), [ 'a ', { op: '@@' }, ' c' ]);
function getEnv (key) {

function getEnv() {
return 'xxx';
}
function getEnvObj (key) {

function getEnvObj() {
return { op: '@@' };
}
});
14 changes: 8 additions & 6 deletions test/op.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict';

var test = require('tape');
var parse = require('../').parse;

Expand All @@ -6,21 +8,21 @@ test('single operators', function (t) {
t.same(parse('beep|boop'), [ 'beep', { op: '|' }, 'boop' ]);
t.same(parse('beep \\| boop'), [ 'beep', '|', 'boop' ]);
t.same(parse('beep "|boop"'), [ 'beep', '|boop' ]);

t.same(parse('echo zing &'), [ 'echo', 'zing', { op: '&' } ]);
t.same(parse('echo zing&'), [ 'echo', 'zing', { op: '&' } ]);
t.same(parse('echo zing\\&'), [ 'echo', 'zing&' ]);
t.same(parse('echo "zing\\&"'), [ 'echo', 'zing\\&' ]);

t.same(parse('beep;boop'), [ 'beep', { op: ';' }, 'boop' ]);
t.same(parse('(beep;boop)'), [
{ op: '(' }, 'beep', { op: ';' }, 'boop', { op: ')' }
]);

t.same(parse('beep>boop'), [ 'beep', { op: '>' }, 'boop' ]);
t.same(parse('beep 2>boop'), [ 'beep', '2', { op: '>' }, 'boop' ]);
t.same(parse('beep<boop'), [ 'beep', { op: '<' }, 'boop' ]);

t.end();
});

Expand All @@ -30,7 +32,7 @@ test('double operators', function (t) {
t.same(parse('beep ||boop'), [ 'beep', { op: '||' }, 'boop' ]);
t.same(parse('beep|| boop'), [ 'beep', { op: '||' }, 'boop' ]);
t.same(parse('beep || boop'), [ 'beep', { op: '||' }, 'boop' ]);

t.same(parse('beep && boop'), [ 'beep', { op: '&&' }, 'boop' ]);
t.same(
parse('beep && boop || byte'),
Expand Down Expand Up @@ -75,4 +77,4 @@ test('glob patterns', function (t) {

t.same(parse('tap "test/*.test.js"'), ['tap', 'test/*.test.js']);
t.end();
})
});
4 changes: 3 additions & 1 deletion test/parse.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict';

var test = require('tape');
var parse = require('../').parse;

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

t.end();
Expand Down
18 changes: 10 additions & 8 deletions test/quote.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict';

var test = require('tape');
var quote = require('../').quote;

Expand Down Expand Up @@ -34,15 +36,15 @@ test('quote ops', function (t) {
});

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

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

t.end()
})
t.end();
});

test("chars for windows paths don't break out", function (t) {
var x = '`:\\a\\b'
t.equal(quote([x]), '\\`\\:\\\\a\\\\b')
t.end()
})
var x = '`:\\a\\b';
t.equal(quote([x]), '\\`\\:\\\\a\\\\b');
t.end();
});
6 changes: 4 additions & 2 deletions test/set.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict';

var test = require('tape');
var parse = require('../').parse;

Expand All @@ -19,11 +21,11 @@ test('set env vars', function (t) {
[ 'X=7 8 9', { op: ';' }, 'printx' ]
);
t.same(
parse('X="7 8 9"; printx', function (key) {
parse('X="7 8 9"; printx', function () {
t.fail('should not have matched any keys');
}),
[ 'X=7 8 9', { op: ';' }, 'printx' ]
);

t.end();
});

0 comments on commit 6ee1437

Please sign in to comment.