From 505c80e7f8a27353db8ea8d8ee762b97b9c4173f Mon Sep 17 00:00:00 2001 From: Pieter Wigboldus Date: Wed, 27 Oct 2021 10:30:13 +0200 Subject: [PATCH 1/3] Add more rules --- README.md | 2 ++ eslintrc.json | 63 ++++++++++++++++++++++++++++++++++++++++++--------- 2 files changed, 54 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index f52c989..9453df3 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,8 @@ JavaScript Standard Style with custom PON tweaks +The default standardjs lint rules: https://github.com/standard/eslint-config-standard/blob/master/.eslintrc.json + ## Install ``` diff --git a/eslintrc.json b/eslintrc.json index 6364538..9b4f3ca 100644 --- a/eslintrc.json +++ b/eslintrc.json @@ -10,12 +10,24 @@ ] } ], + "block-scoped-var": "error", "camelcase": [ "error", { "properties": "never" } ], + "complexity": [ + "error", + { + "max": 20 + } + ], + "consistent-return": "error", + "max-classes-per-file": [ + "error", + 1 + ], "max-params": [ "warn", 5 @@ -37,20 +49,28 @@ "warn", "last" ], + "no-alert": "error", + "no-caller": "error", + "no-extra-label": "error", + "no-labels": [ + "error", + { + "allowLoop": false, + "allowSwitch": false + } + ], + "no-loop-func": "error", "no-mixed-spaces-and-tabs": [ "warn" ], "no-prototype-builtins": "off", - "no-return-assign": [ - "error", - "except-parens" - ], "no-restricted-syntax": [ "error", "ForInStatement", "LabeledStatement", "WithStatement" ], + "no-return-await": "error", "no-unused-vars": [ "error", { @@ -58,6 +78,12 @@ "argsIgnorePattern": "res|next|^err" } ], + "no-else-return": [ + "error", + { + "allowElseIf": false + } + ], "prefer-const": [ "error", { @@ -68,18 +94,23 @@ "error", "as-needed" ], - "no-unused-expressions": [ - "error", - { - "allowTaggedTemplates": true - } - ], + "no-console": "warn", "no-param-reassign": [ "error", { - "props": false + "props": false, + "ignorePropertyModificationsFor": [ + "acc", + "accumulator", + "e", + "req", + "request", + "res", + "response" + ] } ], + "no-useless-concat": "error", "max-len": [ "error", { @@ -110,8 +141,18 @@ "allowTemplateLiterals": true } ], + "radix": "error", "import/prefer-default-export": "off", "vars-on-top": "error", + "for-direction": "error", + "getter-return": [ + "error", + { + "allowImplicit": true + } + ], + "no-await-in-loop": "error", + "no-inner-declarations": "error", "valid-jsdoc": [ "error", { From 9eccfacce85e396a384e2c8699389664872a9ba9 Mon Sep 17 00:00:00 2001 From: Pieter Wigboldus Date: Wed, 27 Oct 2021 10:57:52 +0200 Subject: [PATCH 2/3] More rules --- eslintrc.json | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/eslintrc.json b/eslintrc.json index 9b4f3ca..2a597c5 100644 --- a/eslintrc.json +++ b/eslintrc.json @@ -84,12 +84,6 @@ "allowElseIf": false } ], - "prefer-const": [ - "error", - { - "destructuring": "all" - } - ], "arrow-body-style": [ "error", "as-needed" @@ -153,6 +147,32 @@ ], "no-await-in-loop": "error", "no-inner-declarations": "error", + "no-var": "error", + "prefer-arrow-callback": [ + "error", + { + "allowNamedFunctions": false, + "allowUnboundThis": true + } + ], + "prefer-destructuring": [ + "error", + { + "VariableDeclarator": { + "array": false, + "object": true + }, + "AssignmentExpression": { + "array": true, + "object": false + } + }, + { + "enforceForRenamedProperties": false + } + ], + "prefer-rest-params": "error", + "prefer-spread": "error", "valid-jsdoc": [ "error", { From 1a6acd8393a27e6459388e7675d488e6a8c21cda Mon Sep 17 00:00:00 2001 From: Pieter Wigboldus Date: Wed, 27 Oct 2021 12:33:55 +0200 Subject: [PATCH 3/3] Cleanup and extend the lint list --- bin/cmd.js | 10 ++-- eslintrc.json | 117 ++++++++++++++++++++++++++++++++++------------ options.js | 25 +++++----- package-lock.json | 4 +- package.json | 2 +- 5 files changed, 107 insertions(+), 51 deletions(-) diff --git a/bin/cmd.js b/bin/cmd.js index 11c5f9d..da723de 100755 --- a/bin/cmd.js +++ b/bin/cmd.js @@ -6,11 +6,11 @@ var major = parseInt(match[1], 10) var minor = parseInt(match[2], 10) if (major >= 14 || (major === 14 && minor >= 14)) { - eval('import("standard-engine")').then(function (standardEngine) { - eval('import("../options.js")').then(function (options) { - standardEngine.cli(options.default) - }) + eval('import("standard-engine")').then((standardEngine) => { + eval('import("../options.js")').then((options) => { + standardEngine.cli(options.default) }) + }) } else { - console.error('ponstandard: Node 14.14.0 or greater is required. `pomstandard` did not run.') + console.error('ponstandard: Node 14.14.0 or greater is required. `pomstandard` did not run.') } diff --git a/eslintrc.json b/eslintrc.json index 2a597c5..c2d1d10 100644 --- a/eslintrc.json +++ b/eslintrc.json @@ -1,22 +1,7 @@ { "extends": "standard", "rules": { - "indent": [ - "error", - 4, - { - "ignoredNodes": [ - "TemplateLiteral" - ] - } - ], "block-scoped-var": "error", - "camelcase": [ - "error", - { - "properties": "never" - } - ], "complexity": [ "error", { @@ -45,10 +30,6 @@ "unix" ], "class-methods-use-this": "off", - "comma-style": [ - "warn", - "last" - ], "no-alert": "error", "no-caller": "error", "no-extra-label": "error", @@ -60,9 +41,6 @@ } ], "no-loop-func": "error", - "no-mixed-spaces-and-tabs": [ - "warn" - ], "no-prototype-builtins": "off", "no-restricted-syntax": [ "error", @@ -71,19 +49,15 @@ "WithStatement" ], "no-return-await": "error", - "no-unused-vars": [ - "error", - { - "ignoreRestSiblings": true, - "argsIgnorePattern": "res|next|^err" - } - ], "no-else-return": [ "error", { "allowElseIf": false } ], + "no-multi-assign": [ + "error" + ], "arrow-body-style": [ "error", "as-needed" @@ -92,7 +66,7 @@ "no-param-reassign": [ "error", { - "props": false, + "props": true, "ignorePropertyModificationsFor": [ "acc", "accumulator", @@ -105,12 +79,17 @@ } ], "no-useless-concat": "error", + "no-nested-ternary": "error", "max-len": [ "error", { "code": 120, "comments": 80, - "tabWidth": 4 + "tabWidth": 4, + "ignoreUrls": true, + "ignoreRegExpLiterals": true, + "ignoreStrings": true, + "ignoreTemplateLiterals": true } ], "no-shadow": [ @@ -127,6 +106,16 @@ ] } ], + "no-spaced-func": "error", + "no-underscore-dangle": [ + "error", + { + "allow": [], + "allowAfterThis": false, + "allowAfterSuper": false, + "enforceInMethodNames": true + } + ], "quotes": [ "error", "single", @@ -137,6 +126,42 @@ ], "radix": "error", "import/prefer-default-export": "off", + "import/no-unresolved": [ + "error", + { + "caseSensitive": true + } + ], + "import/named": "error", + "import/no-named-as-default": "error", + "import/no-named-as-default-member": "error", + "import/no-mutable-exports": "error", + "import/order": [ + "error", + { + "groups": [ + [ + "builtin", + "external", + "internal" + ] + ] + } + ], + "import/newline-after-import": "error", + "import/no-self-import": "error", + "import/no-cycle": [ + "error", + { + "maxDepth": "∞" + } + ], + "import/no-useless-path-segments": [ + "error", + { + "commonjs": true + } + ], "vars-on-top": "error", "for-direction": "error", "getter-return": [ @@ -148,6 +173,7 @@ "no-await-in-loop": "error", "no-inner-declarations": "error", "no-var": "error", + "no-lonely-if": "error", "prefer-arrow-callback": [ "error", { @@ -173,6 +199,35 @@ ], "prefer-rest-params": "error", "prefer-spread": "error", + "prefer-template": "error", + "require-yield": "error", + "function-paren-newline": [ + "error", + "consistent" + ], + "implicit-arrow-linebreak": [ + "error", + "beside" + ], + "newline-per-chained-call": [ + "error", + { + "ignoreChainWithDepth": 4 + } + ], + "nonblock-statement-body-position": [ + "error", + "beside", + { + "overrides": {} + } + ], + "operator-assignment": [ + "error", + "always" + ], + "prefer-object-spread": "error", + "no-delete-var": "error", "valid-jsdoc": [ "error", { diff --git a/options.js b/options.js index e0861a7..13df8ee 100644 --- a/options.js +++ b/options.js @@ -9,16 +9,17 @@ const pkg = JSON.parse(readFileSync(pkgUrl, 'utf-8')) const configFile = fileURLToPath(new URL('eslintrc.json', import.meta.url)) const baseConfig = JSON.parse(readFileSync(stdOpts.eslintConfig.configFile, 'utf-8')) -export default Object.assign({}, stdOpts, { - bugs: pkg.bugs.url, - cmd: 'ponstandard', - eslint, - eslintConfig: { - baseConfig, - configFile, - useEslintrc: true - }, - homepage: pkg.homepage, - tagline: 'Use JavaScript Standard Style (tweaked by PON)', - version: `${pkg.version} (standard ${stdVersion})` +export default ({ + ...stdOpts, + bugs: pkg.bugs.url, + cmd: 'ponstandard', + eslint, + eslintConfig: { + baseConfig, + configFile, + useEslintrc: true + }, + homepage: pkg.homepage, + tagline: 'Use JavaScript Standard Style (tweaked by PON)', + version: `${pkg.version} (standard ${stdVersion})` }) diff --git a/package-lock.json b/package-lock.json index d1054dc..1db27b2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@ponbike/ponstandard", - "version": "0.1.0", + "version": "0.2.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@ponbike/ponstandard", - "version": "0.1.0", + "version": "0.2.0", "license": "GPL-3", "dependencies": { "eslint": "^7.32.0", diff --git a/package.json b/package.json index f044743..fbbcb20 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@ponbike/ponstandard", "description": "JavaScript Standard Style with custom PON tweaks", - "version": "0.1.0", + "version": "0.2.0", "author": { "name": "Pieter Wigboldus", "email": "pieter.wigboldus@pon.com",