From 6ee1437df1b10a79bdf2aaa04f2bacc9f420dc15 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Wed, 12 Oct 2022 10:48:50 -0700 Subject: [PATCH] [eslint] add eslint --- .eslintrc | 50 ++++++++++++++++++++++++++++++++++++++++++++++++ example/env.js | 2 ++ example/op.js | 2 ++ example/parse.js | 2 ++ example/quote.js | 2 ++ index.js | 2 ++ package.json | 4 ++++ test/comment.js | 2 ++ test/env.js | 8 +++++--- test/env_fn.js | 12 +++++++----- test/op.js | 14 ++++++++------ test/parse.js | 4 +++- test/quote.js | 18 +++++++++-------- test/set.js | 6 ++++-- 14 files changed, 103 insertions(+), 25 deletions(-) create mode 100644 .eslintrc diff --git a/.eslintrc b/.eslintrc new file mode 100644 index 0000000..68df73c --- /dev/null +++ b/.eslintrc @@ -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, + }, + }, + ], +} diff --git a/example/env.js b/example/env.js index 3608a58..1493afc 100644 --- a/example/env.js +++ b/example/env.js @@ -1,3 +1,5 @@ +'use strict'; + var parse = require('../').parse; var xs = parse('beep --boop="$PWD"', { PWD: '/home/robot' }); console.dir(xs); diff --git a/example/op.js b/example/op.js index d8d9064..82ebf65 100644 --- a/example/op.js +++ b/example/op.js @@ -1,3 +1,5 @@ +'use strict'; + var parse = require('../').parse; var xs = parse('beep || boop > /byte'); console.dir(xs); diff --git a/example/parse.js b/example/parse.js index 4b3be5f..36e6758 100644 --- a/example/parse.js +++ b/example/parse.js @@ -1,3 +1,5 @@ +'use strict'; + var parse = require('../').parse; var xs = parse('a "b c" \\$def \'it\\\'s great\''); console.dir(xs); diff --git a/example/quote.js b/example/quote.js index 434bf8a..0be7ff2 100644 --- a/example/quote.js +++ b/example/quote.js @@ -1,3 +1,5 @@ +'use strict'; + var quote = require('../').quote; var s = quote([ 'a', 'b c d', '$f', '"g"' ]); console.log(s); diff --git a/index.js b/index.js index 0c0df8d..cc9f57e 100644 --- a/index.js +++ b/index.js @@ -1,3 +1,5 @@ +'use strict'; + exports.quote = function (xs) { return xs.map(function (s) { if (s && typeof s === 'object') { diff --git a/package.json b/package.json index 1e32086..7892075 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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" diff --git a/test/comment.js b/test/comment.js index bc6fbf2..f81d753 100644 --- a/test/comment.js +++ b/test/comment.js @@ -1,3 +1,5 @@ +'use strict'; + var test = require('tape'); var parse = require('../').parse; diff --git a/test/env.js b/test/env.js index b3faeb0..b19b58e 100644 --- a/test/env.js +++ b/test/env.js @@ -1,3 +1,5 @@ +'use strict'; + var test = require('tape'); var parse = require('../').parse; @@ -17,7 +19,7 @@ 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(); }); @@ -25,14 +27,14 @@ 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'; diff --git a/test/env_fn.js b/test/env_fn.js index b9f3c20..c83c653 100644 --- a/test/env_fn.js +++ b/test/env_fn.js @@ -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: '@@' }; } }); diff --git a/test/op.js b/test/op.js index 7aa9b49..91263cc 100644 --- a/test/op.js +++ b/test/op.js @@ -1,3 +1,5 @@ +'use strict'; + var test = require('tape'); var parse = require('../').parse; @@ -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