From 661b57c731b370353bfc8ca5725954cfd6dc5967 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20De=20Boey?= Date: Tue, 30 Nov 2021 14:00:06 +0100 Subject: [PATCH 1/8] chore(CI): simplify testing strategy --- .github/workflows/CI.yml | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 1d61214..0c4bc15 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -10,21 +10,35 @@ on: jobs: test: name: Test - runs-on: ubuntu-latest strategy: matrix: - node: [12.x, 10.x, 8.x] + os: [ubuntu-latest] + eslint: [6] + node: [8, 10, 12, 14, 16, 18] + include: + # On other platforms + - os: windows-latest + node: 18 + - os: macos-latest + node: 18 + # On the minimum supported ESLint/Node.js version + - eslint: 6.6.0 + node: 8.10.0 + + runs-on: ${{ matrix.os }} steps: - name: Checkout - uses: actions/checkout@v1 - with: - fetch-depth: 1 + uses: actions/checkout@v3 - name: Install Node.js ${{ matrix.node }} - uses: actions/setup-node@v1 + uses: actions/setup-node@v3 with: node-version: ${{ matrix.node }} - name: Install Packages run: npm install + env: + CI: true + - name: Install ESLint@${{ matrix.eslint }} + run: npm install eslint@${{ matrix.eslint }} - name: Test run: npm test - name: Send Coverage From 7a4769f1e4ff31a79754abaa327e15092f2c8341 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20De=20Boey?= Date: Tue, 30 Nov 2021 18:04:44 +0100 Subject: [PATCH 2/8] feat: drop Node 8 & 10 support BREAKING CHANGE: Requires Node@^12.22.0 || ^14.17.0 || >=16.0.0 --- .github/workflows/CI.yml | 4 ++-- README.md | 4 ++-- package.json | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 0c4bc15..c0d188f 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -14,7 +14,7 @@ jobs: matrix: os: [ubuntu-latest] eslint: [6] - node: [8, 10, 12, 14, 16, 18] + node: [12.22.0, 12, 14.17.0, 14, 16, 18] include: # On other platforms - os: windows-latest @@ -23,7 +23,7 @@ jobs: node: 18 # On the minimum supported ESLint/Node.js version - eslint: 6.6.0 - node: 8.10.0 + node: 12.22.0 runs-on: ${{ matrix.os }} steps: diff --git a/README.md b/README.md index 2d9263c..a9262ad 100644 --- a/README.md +++ b/README.md @@ -16,8 +16,8 @@ npm install --save-dev eslint @mysticatea/eslint-plugin ### Requirements -- Node.js `^8.10.0` or newer versions. -- ESLint `^6.3.0` or newer versions. +- Node.js `^12.22.0 || ^14.17.0 || >=16.0.0` or newer versions. +- ESLint `^6.6.0` or newer versions. ## 📖 Usage diff --git a/package.json b/package.json index 65aad32..9ed52ee 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "version": "13.0.0", "description": "Additional ESLint rules.", "engines": { - "node": ">=8.10.0" + "node": "^12.22.0 || ^14.17.0 || >=16.0.0" }, "main": "index.js", "files": [ From 4d7736bf177aa5630e6110320a82b5b446c3e42f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20De=20Boey?= Date: Tue, 30 Nov 2021 14:39:55 +0100 Subject: [PATCH 3/8] chore: update dependencies to latest minor version --- package.json | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/package.json b/package.json index 65aad32..98e6d9b 100644 --- a/package.json +++ b/package.json @@ -13,28 +13,27 @@ "eslint": ">=6.6.0" }, "dependencies": { - "@typescript-eslint/eslint-plugin": "~2.6.1", - "@typescript-eslint/parser": "~2.6.1", - "eslint-plugin-eslint-comments": "~3.1.2", - "eslint-plugin-eslint-plugin": "~2.1.0", - "eslint-plugin-node": "~10.0.0", - "eslint-plugin-prettier": "~3.1.1", - "eslint-plugin-vue": "~6.0.0", - "prettier": "~1.19.1", - "vue-eslint-parser": "^7.0.0" + "@typescript-eslint/eslint-plugin": "^2.34.0", + "@typescript-eslint/parser": "^2.34.0", + "eslint-plugin-eslint-comments": "^3.2.0", + "eslint-plugin-eslint-plugin": "^2.3.0", + "eslint-plugin-node": "^10.0.0", + "eslint-plugin-prettier": "^3.4.1", + "eslint-plugin-vue": "^6.2.2", + "prettier": "^1.19.1", + "vue-eslint-parser": "^7.11.0" }, "devDependencies": { "@mysticatea/eslint-plugin": "file:.", - "codecov": "^3.6.1", - "eslint": "~6.6.0", - "fs-extra": "^8.1.0", - "globals": "^12.1.1", - "mocha": "^6.2.2", + "codecov": "^3.8.3", + "eslint": "^6.8.0", + "globals": "^12.4.0", + "mocha": "^6.2.3", "npm-run-all": "^4.1.5", "nyc": "^14.1.1", - "opener": "^1.5.1", - "rimraf": "^3.0.0", - "typescript": "~3.7.2" + "opener": "^1.5.2", + "rimraf": "^3.0.2", + "typescript": "^3.9.10" }, "scripts": { "clean": "rimraf .nyc_output coverage", From 274c9a5d11568e75f5fd0a64db9f0edf1735734b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20De=20Boey?= Date: Sat, 18 Dec 2021 03:25:08 +0100 Subject: [PATCH 4/8] chore: fix ESLint errors --- lib/rules/no-literal-call.js | 2 +- lib/rules/no-this-in-static.js | 2 +- lib/rules/no-use-ignored-vars.js | 2 +- lib/rules/no-useless-rest-spread.js | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/rules/no-literal-call.js b/lib/rules/no-literal-call.js index 22e6856..a6973dd 100644 --- a/lib/rules/no-literal-call.js +++ b/lib/rules/no-literal-call.js @@ -18,7 +18,7 @@ const LITERAL_AND_CLASS_TYPE = /^(?:(?:Array|Class|Object)Expression|(?:Template module.exports = { meta: { docs: { - description: "Disallow a call of a literal.", + description: "disallow a call of a literal.", category: "Possible Errors", recommended: false, url: diff --git a/lib/rules/no-this-in-static.js b/lib/rules/no-this-in-static.js index a6a342f..0f6f5cf 100644 --- a/lib/rules/no-this-in-static.js +++ b/lib/rules/no-this-in-static.js @@ -12,7 +12,7 @@ module.exports = { meta: { docs: { - description: "Disallow `this`/`super` in static methods", + description: "disallow `this`/`super` in static methods", category: "Best Practices", url: "https://github.com/mysticatea/eslint-plugin/blob/v13.0.0/docs/rules/no-this-in-static.md", diff --git a/lib/rules/no-use-ignored-vars.js b/lib/rules/no-use-ignored-vars.js index 5a4855b..e69e24b 100644 --- a/lib/rules/no-use-ignored-vars.js +++ b/lib/rules/no-use-ignored-vars.js @@ -17,7 +17,7 @@ const DEFAULT_IGNORE_PATTERN = /^_[a-zA-Z]+$/u module.exports = { meta: { docs: { - description: "Disallow a use of ignored variables.", + description: "disallow a use of ignored variables.", category: "Stylistic Issues", recommended: false, url: diff --git a/lib/rules/no-useless-rest-spread.js b/lib/rules/no-useless-rest-spread.js index ccca71b..e85c6ca 100644 --- a/lib/rules/no-useless-rest-spread.js +++ b/lib/rules/no-useless-rest-spread.js @@ -94,7 +94,7 @@ function defineFixer(sourceCode, node) { module.exports = { meta: { docs: { - description: "Disallow unnecessary spread operators.", + description: "disallow unnecessary spread operators.", category: "Best Practices", recommended: false, url: From 7ab3eaf92a84af05e42a41e2a111bce2ed0e27f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20De=20Boey?= Date: Sat, 18 Dec 2021 03:13:06 +0100 Subject: [PATCH 5/8] feat: update configs --- lib/configs/+eslint-plugin.js | 4 +++ lib/configs/_base.js | 6 +++++ lib/configs/_override-ts.js | 46 +++++++++++++++++++++++++++++------ lib/configs/_override-vue.js | 14 +++++++++++ 4 files changed, 63 insertions(+), 7 deletions(-) diff --git a/lib/configs/+eslint-plugin.js b/lib/configs/+eslint-plugin.js index 1241df1..d39bef6 100644 --- a/lib/configs/+eslint-plugin.js +++ b/lib/configs/+eslint-plugin.js @@ -34,6 +34,7 @@ module.exports = { "@mysticatea/eslint-plugin/no-missing-placeholders": "error", "@mysticatea/eslint-plugin/no-unused-placeholders": "error", "@mysticatea/eslint-plugin/no-useless-token-range": "error", + "@mysticatea/eslint-plugin/prefer-object-rule": "error", "@mysticatea/eslint-plugin/prefer-output-null": "error", "@mysticatea/eslint-plugin/prefer-placeholders": "error", "@mysticatea/eslint-plugin/prefer-replace-text": "error", @@ -41,11 +42,14 @@ module.exports = { "error", "[^a-z'\"{].*\\.$", ], + "@mysticatea/eslint-plugin/require-meta-docs-description": + "error", "@mysticatea/eslint-plugin/require-meta-docs-url": [ "error", { pattern: rulesDocumentUrl }, ], "@mysticatea/eslint-plugin/require-meta-fixable": "error", + "@mysticatea/eslint-plugin/require-meta-schema": "error", "@mysticatea/eslint-plugin/require-meta-type": "error", "@mysticatea/eslint-plugin/test-case-property-ordering": [ "error", diff --git a/lib/configs/_base.js b/lib/configs/_base.js index 4a21337..7708e61 100644 --- a/lib/configs/_base.js +++ b/lib/configs/_base.js @@ -33,6 +33,7 @@ module.exports = { "for-direction": "error", "func-style": ["error", "declaration"], "getter-return": "error", + "grouped-accessor-pairs": "error", "init-declarations": "error", "linebreak-style": ["error", "unix"], "lines-between-class-members": "error", @@ -47,11 +48,13 @@ module.exports = { "no-compare-neg-zero": "error", "no-cond-assign": "error", "no-constant-condition": "error", + "no-constructor-return": "error", "no-control-regex": "error", "no-debugger": "error", "no-delete-var": "error", "no-div-regex": "error", "no-dupe-args": "error", + "no-dupe-else-if": "error", "no-dupe-keys": "error", "no-duplicate-case": "error", "no-else-return": "error", @@ -128,6 +131,7 @@ module.exports = { "no-self-assign": ["error", { props: true }], "no-self-compare": "error", "no-sequences": "error", + "no-setter-return": "error", "no-shadow": ["error", { builtinGlobals: true }], "no-shadow-restricted-names": "error", "no-sparse-arrays": "error", @@ -173,6 +177,7 @@ module.exports = { { blankLine: "always", next: "function", prev: "*" }, { blankLine: "always", next: "*", prev: "function" }, ], + "prefer-exponentiation-operator": "error", "prefer-promise-reject-errors": "error", "prefer-regex-literals": "error", quotes: ["error", "double", { avoidEscape: true }], @@ -387,6 +392,7 @@ module.exports = { ], }, ], + "@mysticatea/eslint-comments/require-description": "off", // prettier "@mysticatea/prettier": [ diff --git a/lib/configs/_override-ts.js b/lib/configs/_override-ts.js index 3b94d9a..900e37c 100644 --- a/lib/configs/_override-ts.js +++ b/lib/configs/_override-ts.js @@ -19,40 +19,75 @@ module.exports = { "@mysticatea/ts/adjacent-overload-signatures": "error", "@mysticatea/ts/array-type": "error", "@mysticatea/ts/await-thenable": "error", - "@mysticatea/ts/ban-ts-ignore": "error", - "@mysticatea/ts/class-name-casing": "error", + "@mysticatea/ts/ban-ts-comment": "error", + "@mysticatea/ts/class-literal-property-style": "error", + "@mysticatea/ts/comma-spacing": "error", "@mysticatea/ts/consistent-type-assertions": "error", + "@mysticatea/ts/default-param-last": "error", + "@mysticatea/ts/dot-notation": "error", "@mysticatea/ts/explicit-member-accessibility": "error", - "@mysticatea/ts/interface-name-prefix": "error", - "@mysticatea/ts/member-naming": "error", + "@mysticatea/ts/explicit-module-boundary-types": "error", + "@mysticatea/ts/init-declarations": "error", + "@mysticatea/ts/keyword-spacing": "error", + "@mysticatea/ts/lines-between-class-members": "error", + "@mysticatea/ts/method-signature-style": "error", + "@mysticatea/ts/naming-convention": "error", "@mysticatea/ts/no-array-constructor": "error", + "@mysticatea/ts/no-base-to-string": "error", + "@mysticatea/ts/no-dupe-class-members": "error", + "@mysticatea/ts/no-dynamic-delete": "error", "@mysticatea/ts/no-empty-interface": "error", + "@mysticatea/ts/no-extra-non-null-assertion": "error", + "@mysticatea/ts/no-extra-semi": "error", "@mysticatea/ts/no-extraneous-class": "error", "@mysticatea/ts/no-floating-promises": "error", "@mysticatea/ts/no-for-in-array": "error", + "@mysticatea/ts/no-implied-eval": "error", "@mysticatea/ts/no-inferrable-types": "error", + "@mysticatea/ts/no-invalid-this": "error", + "@mysticatea/ts/no-invalid-void-type": "error", "@mysticatea/ts/no-misused-new": "error", "@mysticatea/ts/no-misused-promises": "error", + "@mysticatea/ts/no-non-null-asserted-optional-chain": "error", "@mysticatea/ts/no-parameter-properties": "error", "@mysticatea/ts/no-require-imports": "error", "@mysticatea/ts/no-this-alias": [ "error", { allowDestructuring: true }, ], + "@mysticatea/ts/no-throw-literal": "error", + "@mysticatea/ts/no-unnecessary-boolean-literal-compare": + "error", "@mysticatea/ts/no-unnecessary-qualifier": "error", "@mysticatea/ts/no-unnecessary-type-arguments": "error", "@mysticatea/ts/no-unnecessary-type-assertion": "error", + "@mysticatea/ts/no-unsafe-assignment": "error", + "@mysticatea/ts/no-unsafe-call": "error", + "@mysticatea/ts/no-unsafe-member-access": "error", + "@mysticatea/ts/no-unsafe-return": "error", + "@mysticatea/ts/no-unused-expressions": "error", + "@mysticatea/ts/no-unused-vars-experimental": "error", "@mysticatea/ts/no-var-requires": "error", + "@mysticatea/ts/prefer-as-const": "error", // https://github.com/typescript-eslint/typescript-eslint/issues/454 "@mysticatea/ts/prefer-function-type": "off", "@mysticatea/ts/prefer-includes": "error", "@mysticatea/ts/prefer-namespace-keyword": "error", + "@mysticatea/ts/prefer-nullish-coalescing": "error", + "@mysticatea/ts/prefer-optional-chain": "error", + "@mysticatea/ts/prefer-readonly-parameter-types": "error", // https://github.com/typescript-eslint/typescript-eslint/issues/946 "@mysticatea/ts/prefer-readonly": "off", + "@mysticatea/ts/prefer-reduce-type-parameter": "off", "@mysticatea/ts/prefer-regexp-exec": "error", "@mysticatea/ts/prefer-string-starts-ends-with": "error", + "@mysticatea/ts/prefer-ts-expect-error": "off", "@mysticatea/ts/restrict-plus-operands": "error", "@mysticatea/ts/require-array-sort-compare": "error", + "@mysticatea/ts/restrict-template-expressions": "error", + "@mysticatea/ts/return-await": "error", + "@mysticatea/ts/space-before-function-paren": "error", + "@mysticatea/ts/switch-exhaustiveness-check": "error", "@mysticatea/ts/triple-slash-reference": "error", // ăȘんかèȘ€æ€œçŸ„ăŒć€šă„... "@mysticatea/ts/unbound-method": [ @@ -75,8 +110,6 @@ module.exports = { ], // Replacements - camelcase: "off", - "@mysticatea/ts/camelcase": "error", "no-empty-function": "off", "@mysticatea/ts/no-empty-function": "error", "no-useless-constructor": "off", @@ -101,7 +134,6 @@ module.exports = { "@mysticatea/ts/consistent-type-definitions": "off", "@mysticatea/ts/explicit-function-return-type": "off", // I want but this is not so... "@mysticatea/ts/func-call-spacing": "off", // favor of Prettier. - "@mysticatea/ts/generic-type-naming": "off", "@mysticatea/ts/indent": "off", // favor of Prettier. "@mysticatea/ts/member-delimiter-style": "off", // favor of Prettier. "@mysticatea/ts/member-ordering": "off", diff --git a/lib/configs/_override-vue.js b/lib/configs/_override-vue.js index 9d38f11..005f32e 100644 --- a/lib/configs/_override-vue.js +++ b/lib/configs/_override-vue.js @@ -31,6 +31,8 @@ module.exports = { }, ], "@mysticatea/vue/comment-directive": "error", + "@mysticatea/vue/component-definition-name-casing": "error", + "@mysticatea/vue/component-tags-order": "error", "@mysticatea/vue/dot-location": "error", "@mysticatea/vue/eqeqeq": [ "error", @@ -51,32 +53,44 @@ module.exports = { }, }, ], + "@mysticatea/vue/max-len": ["error", { tabWidth: 4 }], "@mysticatea/vue/no-async-in-computed-properties": "error", "@mysticatea/vue/no-boolean-default": "error", "@mysticatea/vue/no-deprecated-scope-attribute": "error", + "@mysticatea/vue/no-deprecated-slot-attribute": "error", + "@mysticatea/vue/no-deprecated-slot-scope-attribute": "error", "@mysticatea/vue/no-dupe-keys": "error", "@mysticatea/vue/no-duplicate-attributes": "error", "@mysticatea/vue/no-empty-pattern": "error", + "@mysticatea/vue/no-irregular-whitespace": "error", "@mysticatea/vue/no-parsing-error": "error", + "@mysticatea/vue/no-reserved-component-names": "error", "@mysticatea/vue/no-reserved-keys": "error", "@mysticatea/vue/no-shared-component-data": "error", "@mysticatea/vue/no-side-effects-in-computed-properties": "error", + "@mysticatea/vue/no-static-inline-styles": "error", "@mysticatea/vue/no-template-key": "error", "@mysticatea/vue/no-textarea-mustache": "error", + "@mysticatea/vue/no-unsupported-features": "error", "@mysticatea/vue/no-unused-vars": "error", "@mysticatea/vue/object-curly-spacing": ["error", "always"], + "@mysticatea/vue/padding-line-between-blocks": "error", "@mysticatea/vue/require-component-is": "error", "@mysticatea/vue/require-direct-export": "error", + "@mysticatea/vue/require-name-property": "error", "@mysticatea/vue/require-render-return": "error", "@mysticatea/vue/require-v-for-key": "error", "@mysticatea/vue/require-valid-default-prop": "error", "@mysticatea/vue/return-in-computed-property": "error", + "@mysticatea/vue/sort-keys": "error", "@mysticatea/vue/space-infix-ops": "error", "@mysticatea/vue/space-unary-ops": "error", + "@mysticatea/vue/static-class-names-order": "error", "@mysticatea/vue/v-on-function-call": "error", "@mysticatea/vue/v-slot-style": "error", "@mysticatea/vue/valid-template-root": "error", + "@mysticatea/vue/valid-v-bind-sync": "error", "@mysticatea/vue/valid-v-bind": "error", "@mysticatea/vue/valid-v-cloak": "error", "@mysticatea/vue/valid-v-else-if": "error", From 15a8f1f91759bf84b96b95adc0f40a85d236ee4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20De=20Boey?= Date: Sat, 18 Dec 2021 04:27:32 +0100 Subject: [PATCH 6/8] feat: update `prettier` --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 99120dd..a598887 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,7 @@ "eslint-plugin-node": "^10.0.0", "eslint-plugin-prettier": "^3.4.1", "eslint-plugin-vue": "^6.2.2", - "prettier": "^1.19.1", + "prettier": "^2.7.1", "vue-eslint-parser": "^7.11.0" }, "devDependencies": { From 8d2f9257d54a5b37e8b11b11bcf98b0abf32aeb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20De=20Boey?= Date: Sat, 18 Dec 2021 04:28:02 +0100 Subject: [PATCH 7/8] chore: fix ESLint errors --- lib/processors/vue.js | 2 +- lib/rules/arrow-parens.js | 3 +-- lib/rules/block-scoped-var.js | 9 ++++---- lib/rules/no-instanceof-array.js | 5 ++--- lib/rules/no-instanceof-wrapper.js | 5 ++--- lib/rules/no-literal-call.js | 6 +++--- lib/rules/no-this-in-static.js | 3 +-- lib/rules/no-use-ignored-vars.js | 3 +-- lib/rules/no-useless-rest-spread.js | 10 ++++----- lib/rules/prefer-for-of.js | 10 ++++----- scripts/generate-configs.js | 6 +++--- scripts/generate-rules.js | 8 +++---- tests/lib/configs/_rules.js | 14 ++++++------ tests/lib/rules/block-scoped-var.js | 6 ++---- tests/lib/rules/prefer-for-of.js | 33 ++++++++++------------------- 15 files changed, 53 insertions(+), 70 deletions(-) diff --git a/lib/processors/vue.js b/lib/processors/vue.js index b6aa629..be211ea 100644 --- a/lib/processors/vue.js +++ b/lib/processors/vue.js @@ -22,7 +22,7 @@ module.exports = { } // Filter messages which are in disabled area. - return messages[0].filter(message => { + return messages[0].filter((message) => { if (message.ruleId === "@mysticatea/vue/comment-directive") { const rules = message.message.split(" ") const type = rules.shift() diff --git a/lib/rules/arrow-parens.js b/lib/rules/arrow-parens.js index 3736763..45bf21e 100644 --- a/lib/rules/arrow-parens.js +++ b/lib/rules/arrow-parens.js @@ -30,8 +30,7 @@ module.exports = { description: "enforce the parentheses style of arrow functions.", category: "Stylistic Issues", recommended: false, - url: - "https://github.com/mysticatea/eslint-plugin/blob/v13.0.0/docs/rules/arrow-parens.md", + url: "https://github.com/mysticatea/eslint-plugin/blob/v13.0.0/docs/rules/arrow-parens.md", }, fixable: "code", schema: [], diff --git a/lib/rules/block-scoped-var.js b/lib/rules/block-scoped-var.js index b212809..7d774ca 100644 --- a/lib/rules/block-scoped-var.js +++ b/lib/rules/block-scoped-var.js @@ -9,8 +9,10 @@ // Helpers //------------------------------------------------------------------------------ -const scopeNodeType = /^(?:(?:Block|Switch|For(?:In|Of)?)Statement|CatchClause|Program)$/u -const containerNodeType = /^(?:For(?:In|Of)?Statement|(?:Arrow)?Function(?:Declaration|Expression))$/u +const scopeNodeType = + /^(?:(?:Block|Switch|For(?:In|Of)?)Statement|CatchClause|Program)$/u +const containerNodeType = + /^(?:For(?:In|Of)?Statement|(?:Arrow)?Function(?:Declaration|Expression))$/u /** * Checks whether or not a given definition should be skipped. @@ -196,8 +198,7 @@ module.exports = { description: "disallow illegal usage of variables as block-scoped.", category: "Possible Errors", recommended: false, - url: - "https://github.com/mysticatea/eslint-plugin/blob/v13.0.0/docs/rules/block-scoped-var.md", + url: "https://github.com/mysticatea/eslint-plugin/blob/v13.0.0/docs/rules/block-scoped-var.md", }, fixable: null, schema: [], diff --git a/lib/rules/no-instanceof-array.js b/lib/rules/no-instanceof-array.js index 5cc1e54..2cb8734 100644 --- a/lib/rules/no-instanceof-array.js +++ b/lib/rules/no-instanceof-array.js @@ -14,8 +14,7 @@ module.exports = { docs: { description: "disallow 'instanceof' for Array", category: "Best Practices", - url: - "https://github.com/mysticatea/eslint-plugin/blob/v13.0.0/docs/rules/no-instanceof-array.md", + url: "https://github.com/mysticatea/eslint-plugin/blob/v13.0.0/docs/rules/no-instanceof-array.md", }, fixable: "code", schema: [], @@ -64,7 +63,7 @@ module.exports = { loc: node.loc, message: "Unexpected 'instanceof' operator. Use 'Array.isArray' instead.", - fix: fixer => + fix: (fixer) => fixer.replaceText( node, `Array.isArray(${sourceCode.getText( diff --git a/lib/rules/no-instanceof-wrapper.js b/lib/rules/no-instanceof-wrapper.js index c30ee6b..f35bf2e 100644 --- a/lib/rules/no-instanceof-wrapper.js +++ b/lib/rules/no-instanceof-wrapper.js @@ -14,8 +14,7 @@ module.exports = { docs: { description: "disallow 'instanceof' for wrapper objects", category: "Best Practices", - url: - "https://github.com/mysticatea/eslint-plugin/blob/v13.0.0/docs/rules/no-instanceof-wrapper.md", + url: "https://github.com/mysticatea/eslint-plugin/blob/v13.0.0/docs/rules/no-instanceof-wrapper.md", }, fixable: "code", schema: [], @@ -76,7 +75,7 @@ module.exports = { message: "Unexpected 'instanceof' operator. Use 'typeof x === \"{{typeName}}\"' instead.", data: { typeName }, - fix: fixer => + fix: (fixer) => fixer.replaceText( node, `typeof ${sourceCode.getText( diff --git a/lib/rules/no-literal-call.js b/lib/rules/no-literal-call.js index a6973dd..6733c5e 100644 --- a/lib/rules/no-literal-call.js +++ b/lib/rules/no-literal-call.js @@ -9,7 +9,8 @@ //------------------------------------------------------------------------------ const LITERAL_TYPE = /^(?:(?:Array|Object)Expression|(?:Template)?Literal)$/u -const LITERAL_AND_CLASS_TYPE = /^(?:(?:Array|Class|Object)Expression|(?:Template)?Literal)$/u +const LITERAL_AND_CLASS_TYPE = + /^(?:(?:Array|Class|Object)Expression|(?:Template)?Literal)$/u //------------------------------------------------------------------------------ // Rule Definition @@ -21,8 +22,7 @@ module.exports = { description: "disallow a call of a literal.", category: "Possible Errors", recommended: false, - url: - "https://github.com/mysticatea/eslint-plugin/blob/v13.0.0/docs/rules/no-literal-call.md", + url: "https://github.com/mysticatea/eslint-plugin/blob/v13.0.0/docs/rules/no-literal-call.md", }, fixable: null, schema: [], diff --git a/lib/rules/no-this-in-static.js b/lib/rules/no-this-in-static.js index 0f6f5cf..d065d21 100644 --- a/lib/rules/no-this-in-static.js +++ b/lib/rules/no-this-in-static.js @@ -14,8 +14,7 @@ module.exports = { docs: { description: "disallow `this`/`super` in static methods", category: "Best Practices", - url: - "https://github.com/mysticatea/eslint-plugin/blob/v13.0.0/docs/rules/no-this-in-static.md", + url: "https://github.com/mysticatea/eslint-plugin/blob/v13.0.0/docs/rules/no-this-in-static.md", }, fixable: null, schema: [], diff --git a/lib/rules/no-use-ignored-vars.js b/lib/rules/no-use-ignored-vars.js index e69e24b..ec9cd12 100644 --- a/lib/rules/no-use-ignored-vars.js +++ b/lib/rules/no-use-ignored-vars.js @@ -20,8 +20,7 @@ module.exports = { description: "disallow a use of ignored variables.", category: "Stylistic Issues", recommended: false, - url: - "https://github.com/mysticatea/eslint-plugin/blob/v13.0.0/docs/rules/no-use-ignored-vars.md", + url: "https://github.com/mysticatea/eslint-plugin/blob/v13.0.0/docs/rules/no-use-ignored-vars.md", }, fixable: null, schema: [{ type: "string" }], diff --git a/lib/rules/no-useless-rest-spread.js b/lib/rules/no-useless-rest-spread.js index e85c6ca..ee6ba2b 100644 --- a/lib/rules/no-useless-rest-spread.js +++ b/lib/rules/no-useless-rest-spread.js @@ -8,7 +8,8 @@ // Helpers //------------------------------------------------------------------------------ -const FUNC_TYPE = /^(?:FunctionDeclaration|(?:New|Call|(?:Arrow)?Function)Expression)$/u +const FUNC_TYPE = + /^(?:FunctionDeclaration|(?:New|Call|(?:Arrow)?Function)Expression)$/u const PROPERTY_PATTERN = /^(?:Experimental)?(Rest|Spread)Property$/u /** @@ -56,7 +57,7 @@ function getLastElementToken(sourceCode, node) { * @returns {function} A fixer function. */ function defineFixer(sourceCode, node) { - return fixer => { + return (fixer) => { const child = node.argument // If the inner array includes holes, do nothing. @@ -97,8 +98,7 @@ module.exports = { description: "disallow unnecessary spread operators.", category: "Best Practices", recommended: false, - url: - "https://github.com/mysticatea/eslint-plugin/blob/v13.0.0/docs/rules/no-useless-rest-spread.md", + url: "https://github.com/mysticatea/eslint-plugin/blob/v13.0.0/docs/rules/no-useless-rest-spread.md", }, fixable: "code", schema: [], @@ -116,7 +116,7 @@ module.exports = { function verify(node) { const nodeType = node.type.replace( PROPERTY_PATTERN, - t => `${t}Element` + (t) => `${t}Element` ) const parentType = node.parent.type const argumentType = node.argument.type diff --git a/lib/rules/prefer-for-of.js b/lib/rules/prefer-for-of.js index 37ea4e6..d63ba15 100644 --- a/lib/rules/prefer-for-of.js +++ b/lib/rules/prefer-for-of.js @@ -243,7 +243,7 @@ function isIndexVarOnlyUsedToGetArrayElements(context, node) { const arrayText = getArrayTextOfForStatement(sourceCode, node) const indexVar = context.getDeclaredVariables(node.init)[0] - return indexVar.references.every(reference => { + return indexVar.references.every((reference) => { const id = reference.identifier return ( @@ -273,7 +273,8 @@ function isLengthVarOnlyUsedToTest(context, node) { const lengthVar = context.getDeclaredVariables(node.init.declarations[1])[0] return lengthVar.references.every( - reference => reference.init || contains(node.test, reference.identifier) + (reference) => + reference.init || contains(node.test, reference.identifier) ) } @@ -497,8 +498,7 @@ module.exports = { description: "requires for-of statements instead of Array#forEach", category: "Best Practices", recommended: false, - url: - "https://github.com/mysticatea/eslint-plugin/blob/v13.0.0/docs/rules/prefer-for-of.md", + url: "https://github.com/mysticatea/eslint-plugin/blob/v13.0.0/docs/rules/prefer-for-of.md", }, fixable: "code", schema: [], @@ -580,7 +580,7 @@ module.exports = { if ( thisFuncInfo != null && thisFuncInfo.isTarget && - !thisFuncInfo.returnNodes.some(returnNode => + !thisFuncInfo.returnNodes.some((returnNode) => contains(returnNode, node) ) ) { diff --git a/scripts/generate-configs.js b/scripts/generate-configs.js index a0587d1..6884b7c 100644 --- a/scripts/generate-configs.js +++ b/scripts/generate-configs.js @@ -20,9 +20,9 @@ fs.writeFileSync( module.exports = { ${fs .readdirSync(path.resolve(__dirname, "../lib/configs")) - .map(fileName => path.basename(fileName, ".js")) - .filter(id => !id.startsWith("_")) - .map(id => ` "${id}": require("./configs/${id}"),`) + .map((fileName) => path.basename(fileName, ".js")) + .filter((id) => !id.startsWith("_")) + .map((id) => ` "${id}": require("./configs/${id}"),`) .join("\n")} } ` diff --git a/scripts/generate-rules.js b/scripts/generate-rules.js index 141e876..1ff36ce 100644 --- a/scripts/generate-rules.js +++ b/scripts/generate-rules.js @@ -20,14 +20,14 @@ fs.writeFileSync( module.exports = Object.assign( ${fs .readdirSync(path.resolve(__dirname, "../lib/foreign-rules")) - .map(fileName => path.basename(fileName, ".js")) - .map(id => ` require("./foreign-rules/${id}"),`) + .map((fileName) => path.basename(fileName, ".js")) + .map((id) => ` require("./foreign-rules/${id}"),`) .join("\n")} { ${fs .readdirSync(path.resolve(__dirname, "../lib/rules")) - .map(fileName => path.basename(fileName, ".js")) - .map(id => ` "${id}": require("./rules/${id}"),`) + .map((fileName) => path.basename(fileName, ".js")) + .map((id) => ` "${id}": require("./rules/${id}"),`) .join("\n")} } ) diff --git a/tests/lib/configs/_rules.js b/tests/lib/configs/_rules.js index 170f2cb..454caa5 100644 --- a/tests/lib/configs/_rules.js +++ b/tests/lib/configs/_rules.js @@ -13,7 +13,7 @@ const { rules: PluginRulesIndex } = require("@mysticatea/eslint-plugin") const coreRules = new Linter().getRules() const pluginRules = new Map( - Object.keys(PluginRulesIndex).map(key => [ + Object.keys(PluginRulesIndex).map((key) => [ `@mysticatea/${key}`, PluginRulesIndex[key], ]) @@ -39,12 +39,12 @@ module.exports = { * @returns {void} */ validateConfig(config, source) { - Validator.validate(config, source, ruleId => allRules.get(ruleId)) + Validator.validate(config, source, (ruleId) => allRules.get(ruleId)) /* istanbul ignore next */ for (const ruleId of [].concat( Object.keys(config.rules || {}), - ...(config.overrides || []).map(c => Object.keys(c.rules || {})) + ...(config.overrides || []).map((c) => Object.keys(c.rules || {})) )) { const rule = allRules.get(ruleId) if (rule == null) { @@ -74,7 +74,7 @@ module.exports = { */ getCoreRuleNames() { return Array.from(coreRules.keys()).filter( - ruleId => + (ruleId) => !deprecatedRuleNames.has(ruleId) && !removedRuleNames.has(ruleId) ) @@ -87,14 +87,14 @@ module.exports = { */ getPluginRuleNames(pluginName) { return Object.keys(PluginRulesIndex) - .filter(ruleId => + .filter((ruleId) => pluginName === "mysticatea" ? !ruleId.includes("/") : ruleId.startsWith(`${pluginName}/`) ) - .map(ruleId => `@mysticatea/${ruleId}`) + .map((ruleId) => `@mysticatea/${ruleId}`) .filter( - ruleId => + (ruleId) => !deprecatedRuleNames.has(ruleId) && !removedRuleNames.has(ruleId) ) diff --git a/tests/lib/rules/block-scoped-var.js b/tests/lib/rules/block-scoped-var.js index c5385e5..8cb8b03 100644 --- a/tests/lib/rules/block-scoped-var.js +++ b/tests/lib/rules/block-scoped-var.js @@ -14,8 +14,7 @@ new RuleTester().run("block-scoped-var", rule, { "if (true) { var a; a; } else if (true) { var a; a; } else { var a; a; }", "while (true) { var a; a; } do { var a; a; } while (true);", { - code: - "for (var a = 0; a; a) { a; var b; b; } for (var a in []) { a; var b; b; } for (var a of []) { a; var b; b; }", + code: "for (var a = 0; a; a) { a; var b; b; } for (var a in []) { a; var b; b; } for (var a of []) { a; var b; b; }", env: { es6: true }, }, "switch (0) { case 0: var a; a; case 1: a; default: a; } { var a; a; }", @@ -85,8 +84,7 @@ new RuleTester().run("block-scoped-var", rule, { ], }, { - code: - "{ var {x: [a = 0]} = {x: [1]}; a; } { var a; ({x: [a = 0]} = {x: [1]}); }", + code: "{ var {x: [a = 0]} = {x: [1]}; a; } { var a; ({x: [a = 0]} = {x: [1]}); }", env: { es6: true }, errors: [ { diff --git a/tests/lib/rules/prefer-for-of.js b/tests/lib/rules/prefer-for-of.js index 7583264..e7feefd 100644 --- a/tests/lib/rules/prefer-for-of.js +++ b/tests/lib/rules/prefer-for-of.js @@ -37,10 +37,8 @@ tester.run("prefer-for-of", rule, { ], invalid: [ { - code: - "list.forEach(function(value) { return; function foo() { return } });", - output: - "for (let value of list) { continue; function foo() { return } }", + code: "list.forEach(function(value) { return; function foo() { return } });", + output: "for (let value of list) { continue; function foo() { return } }", errors: ["Expected for-of statement."], }, { @@ -62,8 +60,7 @@ tester.run("prefer-for-of", rule, { errors: ["Expected for-of statement."], }, { - code: - "list.forEach(function(value) { return; let obj; this.a }, obj);", + code: "list.forEach(function(value) { return; let obj; this.a }, obj);", output: null, globals: { list: false, obj: false }, errors: ["Expected for-of statement."], @@ -87,8 +84,7 @@ tester.run("prefer-for-of", rule, { errors: ["Expected for-of statement."], }, { - code: - "list.forEach(function(value) { return; foo(a => this[a]) });", + code: "list.forEach(function(value) { return; foo(a => this[a]) });", output: "for (let value of list) { continue; foo(a => list[a]) }", globals: { list: false, obj: false }, errors: ["Expected for-of statement."], @@ -126,8 +122,7 @@ tester.run("prefer-for-of", rule, { errors: ["Expected for-of statement."], }, { - code: - "list.filter(p)\n .map(t)\n .forEach(value => { return });", + code: "list.filter(p)\n .map(t)\n .forEach(value => { return });", output: null, errors: ["Expected for-of statement."], }, @@ -137,38 +132,32 @@ tester.run("prefer-for-of", rule, { errors: ["Expected for-of statement."], }, { - code: - "function wrap() { for (let i = 0; i < list.length; ++i) { return } }", + code: "function wrap() { for (let i = 0; i < list.length; ++i) { return } }", output: null, errors: ["Expected for-of statement."], }, { - code: - "function wrap() { for (let i = 0; i < list.length; ++i) { const value = list[i]; return } }", + code: "function wrap() { for (let i = 0; i < list.length; ++i) { const value = list[i]; return } }", output: "function wrap() { for (let value of list) { return } }", errors: ["Expected for-of statement."], }, { - code: - "function wrap() { for (let i = 0; i < list.length; i++) { const value = list[i]; return } }", + code: "function wrap() { for (let i = 0; i < list.length; i++) { const value = list[i]; return } }", output: "function wrap() { for (let value of list) { return } }", errors: ["Expected for-of statement."], }, { - code: - "function wrap() { for (let i = 0; i < list.length; i += 1) { const value = list[i]; return } }", + code: "function wrap() { for (let i = 0; i < list.length; i += 1) { const value = list[i]; return } }", output: "function wrap() { for (let value of list) { return } }", errors: ["Expected for-of statement."], }, { - code: - "for (let i = 0, end = list.length; i < end;i = 1 + i) { const value = list[i]; }", + code: "for (let i = 0, end = list.length; i < end;i = 1 + i) { const value = list[i]; }", output: "for (let value of list) { }", errors: ["Expected for-of statement."], }, { - code: - "for (let i = 0, length = list.length; i < length; i = i + 1) { const value = list[i]; }", + code: "for (let i = 0, length = list.length; i < length; i = i + 1) { const value = list[i]; }", output: "for (let value of list) { }", errors: ["Expected for-of statement."], }, From 67cf6dbf0051802b6e04686c08746060012b3cbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20De=20Boey?= Date: Sat, 18 Dec 2021 04:38:30 +0100 Subject: [PATCH 8/8] chore: run Prettier on codebase --- .eslintrc.yml | 4 +- .github/FUNDING.yml | 2 +- .github/workflows/CI.yml | 84 ++++++++++++------------ .nycrc.yml | 8 +-- .prettierrc.js | 5 ++ README.md | 98 +++++++++++++--------------- docs/rules/arrow-parens.md | 30 +++++---- docs/rules/block-scoped-var.md | 46 +++++++------ docs/rules/no-literal-call.md | 10 +-- docs/rules/no-this-in-static.md | 4 +- docs/rules/no-use-ignored-vars.md | 10 +-- docs/rules/no-useless-rest-spread.md | 9 ++- docs/rules/prefer-for-of.md | 2 +- lib/rules/no-useless-rest-spread.js | 4 +- lib/rules/prefer-for-of.js | 4 +- package.json | 1 + 16 files changed, 162 insertions(+), 159 deletions(-) create mode 100644 .prettierrc.js diff --git a/.eslintrc.yml b/.eslintrc.yml index 6683556..fff3289 100644 --- a/.eslintrc.yml +++ b/.eslintrc.yml @@ -1,4 +1,4 @@ root: true extends: - - plugin:@mysticatea/es2015 - - plugin:@mysticatea/+eslint-plugin + - plugin:@mysticatea/es2015 + - plugin:@mysticatea/+eslint-plugin diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml index ce763b1..95ec794 100644 --- a/.github/FUNDING.yml +++ b/.github/FUNDING.yml @@ -1,2 +1,2 @@ github: -- mysticatea + - mysticatea diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index c0d188f..7b817f4 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -1,47 +1,47 @@ name: CI on: - push: - branches: [master] - pull_request: - branches: [master] - schedule: - - cron: 0 0 * * 0 + push: + branches: [master] + pull_request: + branches: [master] + schedule: + - cron: 0 0 * * 0 jobs: - test: - name: Test - strategy: - matrix: - os: [ubuntu-latest] - eslint: [6] - node: [12.22.0, 12, 14.17.0, 14, 16, 18] - include: - # On other platforms - - os: windows-latest - node: 18 - - os: macos-latest - node: 18 - # On the minimum supported ESLint/Node.js version - - eslint: 6.6.0 - node: 12.22.0 + test: + name: Test + strategy: + matrix: + os: [ubuntu-latest] + eslint: [6] + node: [12.22.0, 12, 14.17.0, 14, 16, 18] + include: + # On other platforms + - os: windows-latest + node: 18 + - os: macos-latest + node: 18 + # On the minimum supported ESLint/Node.js version + - eslint: 6.6.0 + node: 12.22.0 - runs-on: ${{ matrix.os }} - steps: - - name: Checkout - uses: actions/checkout@v3 - - name: Install Node.js ${{ matrix.node }} - uses: actions/setup-node@v3 - with: - node-version: ${{ matrix.node }} - - name: Install Packages - run: npm install - env: - CI: true - - name: Install ESLint@${{ matrix.eslint }} - run: npm install eslint@${{ matrix.eslint }} - - name: Test - run: npm test - - name: Send Coverage - run: npm run -s codecov - env: - CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} + runs-on: ${{ matrix.os }} + steps: + - name: Checkout + uses: actions/checkout@v3 + - name: Install Node.js ${{ matrix.node }} + uses: actions/setup-node@v3 + with: + node-version: ${{ matrix.node }} + - name: Install Packages + run: npm install + env: + CI: true + - name: Install ESLint@${{ matrix.eslint }} + run: npm install eslint@${{ matrix.eslint }} + - name: Test + run: npm test + - name: Send Coverage + run: npm run -s codecov + env: + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} diff --git a/.nycrc.yml b/.nycrc.yml index 5bf9a3c..95d8164 100644 --- a/.nycrc.yml +++ b/.nycrc.yml @@ -1,7 +1,7 @@ include: -- lib + - lib exclude: -- lib/processors/vue.js + - lib/processors/vue.js reporter: -- text-summary -- lcov + - text-summary + - lcov diff --git a/.prettierrc.js b/.prettierrc.js new file mode 100644 index 0000000..c60295a --- /dev/null +++ b/.prettierrc.js @@ -0,0 +1,5 @@ +module.exports = { + tabWidth: 4, + semi: false, + trailingComma: "es5", +} diff --git a/README.md b/README.md index a9262ad..b20a186 100644 --- a/README.md +++ b/README.md @@ -16,8 +16,8 @@ npm install --save-dev eslint @mysticatea/eslint-plugin ### Requirements -- Node.js `^12.22.0 || ^14.17.0 || >=16.0.0` or newer versions. -- ESLint `^6.6.0` or newer versions. +- Node.js `^12.22.0 || ^14.17.0 || >=16.0.0` or newer versions. +- ESLint `^6.6.0` or newer versions. ## 📖 Usage @@ -25,31 +25,31 @@ Write in your ESLint configurations: http://eslint.org/docs/user-guide/configuri ### Configs -- `plugin:@mysticatea/es2020` ... Basic configuration for ES2020. -- `plugin:@mysticatea/es2019` ... Basic configuration for ES2019. -- `plugin:@mysticatea/es2018` ... Basic configuration for ES2018. -- `plugin:@mysticatea/es2017` ... Basic configuration for ES2017. -- `plugin:@mysticatea/es2016` ... Basic configuration for ES2016. -- `plugin:@mysticatea/es2015` ... Basic configuration for ES2015. -- `plugin:@mysticatea/es5` ... Basic configuration for ES5. -- `plugin:@mysticatea/+modules` ... Additional configuration for ES modules. -- `plugin:@mysticatea/+browser` ... Additional configuration for browser environment. -- `plugin:@mysticatea/+node` ... Additional configuration for Node.js environment. -- `plugin:@mysticatea/+eslint-plugin` ... Additional configuration for ESLint plugins. This includes `plugin:mysticatea/+node` setting. +- `plugin:@mysticatea/es2020` ... Basic configuration for ES2020. +- `plugin:@mysticatea/es2019` ... Basic configuration for ES2019. +- `plugin:@mysticatea/es2018` ... Basic configuration for ES2018. +- `plugin:@mysticatea/es2017` ... Basic configuration for ES2017. +- `plugin:@mysticatea/es2016` ... Basic configuration for ES2016. +- `plugin:@mysticatea/es2015` ... Basic configuration for ES2015. +- `plugin:@mysticatea/es5` ... Basic configuration for ES5. +- `plugin:@mysticatea/+modules` ... Additional configuration for ES modules. +- `plugin:@mysticatea/+browser` ... Additional configuration for browser environment. +- `plugin:@mysticatea/+node` ... Additional configuration for Node.js environment. +- `plugin:@mysticatea/+eslint-plugin` ... Additional configuration for ESLint plugins. This includes `plugin:mysticatea/+node` setting. #### Details The main configurations `plugin:@mysticatea/es*` does: -- detect bug-like code by ESLint rules. -- enforce whitespace style by Prettier. -- handle the `.ts` files as TypeScript then check by `typescript-eslint-parser` and `eslint-plugin-typescript`. -- handle the `.vue` files as Vue.js SFC then check by `vue-eslint-parser` and `eslint-plugin-vue`. -- handle the files in `test`/`tests` directory as `mocha`'s test code. -- handle the files in `scripts` directory as Node.js environment. -- handle the `.eslintrc.js` file as a Node.js script. -- handle the `webpack.config.js` file as a Node.js script. -- handle the `rollup.config.js` file as an ES module. +- detect bug-like code by ESLint rules. +- enforce whitespace style by Prettier. +- handle the `.ts` files as TypeScript then check by `typescript-eslint-parser` and `eslint-plugin-typescript`. +- handle the `.vue` files as Vue.js SFC then check by `vue-eslint-parser` and `eslint-plugin-vue`. +- handle the files in `test`/`tests` directory as `mocha`'s test code. +- handle the files in `scripts` directory as Node.js environment. +- handle the `.eslintrc.js` file as a Node.js script. +- handle the `webpack.config.js` file as a Node.js script. +- handle the `rollup.config.js` file as an ES module. You can use combination of a main configuration and some additional configurations. For examples: @@ -58,10 +58,7 @@ For examples: ```json { - "extends": [ - "plugin:@mysticatea/es2015", - "plugin:@mysticatea/+node" - ] + "extends": ["plugin:@mysticatea/es2015", "plugin:@mysticatea/+node"] } ``` @@ -71,10 +68,7 @@ For examples: ```json { - "extends": [ - "plugin:@mysticatea/es2015", - "plugin:@mysticatea/+browser" - ] + "extends": ["plugin:@mysticatea/es2015", "plugin:@mysticatea/+browser"] } ``` @@ -107,26 +101,26 @@ This plugin has some original rules and foreign rules. #### Original rules -- [@mysticatea/arrow-parens](docs/rules/arrow-parens.md) enforces parens of argument lists (excludes too redundant parens) (fixable). -- [@mysticatea/block-scoped-var](docs/rules/block-scoped-var.md) handles variables which are declared by `var` declaration as block-scoped. It disallows redeclarations, uses from outside of the scope, shadowing. -- [@mysticatea/no-instanceof-array](docs/rules/no-instanceof-array.md) disallows 'instanceof' for Array (fixable). -- [@mysticatea/no-instanceof-wrapper](docs/rules/no-instanceof-wrapper.md) disallows 'instanceof' for wrapper objects (fixable). -- [@mysticatea/no-literal-call](docs/rules/no-literal-call.md) disallows a call of a literal. -- [@mysticatea/no-this-in-static](docs/rules/no-this-in-static.md) disallows `this`/`super` in static methods. -- [@mysticatea/no-use-ignored-vars](docs/rules/no-use-ignored-vars.md) disallows a use of ignored variables. -- [@mysticatea/no-useless-rest-spread](docs/rules/no-useless-rest-spread.md) disallows unnecessary rest/spread operators (fixable). -- [@mysticatea/prefer-for-of](docs/rules/prefer-for-of.md) requires `for-of` statements instead of `Array#forEach` or something like (fixable). +- [@mysticatea/arrow-parens](docs/rules/arrow-parens.md) enforces parens of argument lists (excludes too redundant parens) (fixable). +- [@mysticatea/block-scoped-var](docs/rules/block-scoped-var.md) handles variables which are declared by `var` declaration as block-scoped. It disallows redeclarations, uses from outside of the scope, shadowing. +- [@mysticatea/no-instanceof-array](docs/rules/no-instanceof-array.md) disallows 'instanceof' for Array (fixable). +- [@mysticatea/no-instanceof-wrapper](docs/rules/no-instanceof-wrapper.md) disallows 'instanceof' for wrapper objects (fixable). +- [@mysticatea/no-literal-call](docs/rules/no-literal-call.md) disallows a call of a literal. +- [@mysticatea/no-this-in-static](docs/rules/no-this-in-static.md) disallows `this`/`super` in static methods. +- [@mysticatea/no-use-ignored-vars](docs/rules/no-use-ignored-vars.md) disallows a use of ignored variables. +- [@mysticatea/no-useless-rest-spread](docs/rules/no-useless-rest-spread.md) disallows unnecessary rest/spread operators (fixable). +- [@mysticatea/prefer-for-of](docs/rules/prefer-for-of.md) requires `for-of` statements instead of `Array#forEach` or something like (fixable). #### Foreign rules -- All `@mysticatea/eslint-comments/*` rules are imported from [eslint-plugin-eslint-comments](https://www.npmjs.com/package/eslint-plugin-eslint-comments). -- All `@mysticatea/eslint-plugin/*` rules are imported from [eslint-plugin-eslint-plugin](https://www.npmjs.com/package/eslint-plugin-eslint-plugin). -- All `@mysticatea/node/*` rules are imported from [eslint-plugin-node](https://www.npmjs.com/package/eslint-plugin-node). -- All `@mysticatea/ts/*` rules are imported from [eslint-plugin-typescript](https://www.npmjs.com/package/eslint-plugin-typescript). -- All `@mysticatea/vue/*` rules are imported from [eslint-plugin-vue](https://www.npmjs.com/package/eslint-plugin-vue). -- The `@mysticatea/prettier` rule is imported from [eslint-plugin-prettier](https://www.npmjs.com/package/eslint-plugin-prettier). +- All `@mysticatea/eslint-comments/*` rules are imported from [eslint-plugin-eslint-comments](https://www.npmjs.com/package/eslint-plugin-eslint-comments). +- All `@mysticatea/eslint-plugin/*` rules are imported from [eslint-plugin-eslint-plugin](https://www.npmjs.com/package/eslint-plugin-eslint-plugin). +- All `@mysticatea/node/*` rules are imported from [eslint-plugin-node](https://www.npmjs.com/package/eslint-plugin-node). +- All `@mysticatea/ts/*` rules are imported from [eslint-plugin-typescript](https://www.npmjs.com/package/eslint-plugin-typescript). +- All `@mysticatea/vue/*` rules are imported from [eslint-plugin-vue](https://www.npmjs.com/package/eslint-plugin-vue). +- The `@mysticatea/prettier` rule is imported from [eslint-plugin-prettier](https://www.npmjs.com/package/eslint-plugin-prettier). -> **Q:** Why don't you use those plugins directly?
+> **Q:** Why don't you use those plugins directly? > **A:** The combination with shareable configs and plugins has some problems because shareable configs were not designed to be used with plugins. @nzakas illustrated a way to use plugins as shareable configs together with other plugins in the discussion [eslint/eslint#3458](https://github.com/eslint/eslint/issues/3458#issuecomment-257161846). This is the way. ## đŸš„ Semantic Versioning Policy @@ -135,7 +129,7 @@ This plugin follows [semantic versioning](http://semver.org/) and [ESLint's Sema ## 📰 Changelog -- [GitHub Releases](https://github.com/mysticatea/eslint-plugin/releases) +- [GitHub Releases](https://github.com/mysticatea/eslint-plugin/releases) ## ❀ Contributing @@ -145,8 +139,8 @@ Please use GitHub's Issues/PRs. ### Development Tools -- `npm test` runs tests and measures coverage. -- `npm run clean` removes the coverage result of `npm test` command. -- `npm run coverage` shows the coverage result of `npm test` command. -- `npm run update` updates auto-generated files. -- `npm run watch` runs tests and measures coverage when source code are changed. +- `npm test` runs tests and measures coverage. +- `npm run clean` removes the coverage result of `npm test` command. +- `npm run coverage` shows the coverage result of `npm test` command. +- `npm run update` updates auto-generated files. +- `npm run watch` runs tests and measures coverage when source code are changed. diff --git a/docs/rules/arrow-parens.md b/docs/rules/arrow-parens.md index 9054b31..984d08b 100644 --- a/docs/rules/arrow-parens.md +++ b/docs/rules/arrow-parens.md @@ -12,39 +12,45 @@ This rule ignores arrow functions that there is a open paren before itself. ### The following patterns are considered warnings: ```js -const twice = x => 2 * x; +const twice = (x) => 2 * x ``` ```js const obj = { - twich: x => 2 * x -}; + twich: (x) => 2 * x, +} ``` ```js -p.then(x => 2 * x, err => console.error(err)); +p.then( + (x) => 2 * x, + (err) => console.error(err) +) ``` ### The following patterns are not considered warnings: ```js -const twice = (x) => 2 * x; -const twice = (x => 2 * x); +const twice = (x) => 2 * x +const twice = (x) => 2 * x ``` ```js const obj = { - twich: (x) => 2 * x -}; + twich: (x) => 2 * x, +} const obj2 = { - twich: (x => 2 * x) -}; + twich: (x) => 2 * x, +} ``` ```js -xs.map(x => 2 * x); +xs.map((x) => 2 * x) ``` ```js -p.then(x => 2 * x, (err) => console.error(err)); +p.then( + (x) => 2 * x, + (err) => console.error(err) +) ``` diff --git a/docs/rules/block-scoped-var.md b/docs/rules/block-scoped-var.md index e66b9a2..461b4df 100644 --- a/docs/rules/block-scoped-var.md +++ b/docs/rules/block-scoped-var.md @@ -8,54 +8,53 @@ Please turn `no-redeclare` rule off if you use this rule. This rule aims to flag below about variables which are defined with `var` declaration: -- References from outside of the block which declare the variable. -- Re-declarations in a same block. -- Shadowing in a same function scope. +- References from outside of the block which declare the variable. +- Re-declarations in a same block. +- Shadowing in a same function scope. ### The following patterns are considered warnings: ```js { - var a = 0; + var a = 0 } -console.log(a); // not defined. +console.log(a) // not defined. ``` ```js -for (var a = 0;;) { -} -console.log(a); // not defined. +for (var a = 0; ; ) {} +console.log(a) // not defined. ``` ```js -var a = 0; -var a = 0; // already defined. +var a = 0 +var a = 0 // already defined. ``` ```js -for (var a = 0;;) { - var a = 0; // already defined. +for (var a = 0; ; ) { + var a = 0 // already defined. } ``` ```js function foo(a) { - var a = 0; // already defined. + var a = 0 // already defined. } ``` ```js -var a = 0; +var a = 0 { - var a = 0; // already defined in the upper scope. + var a = 0 // already defined in the upper scope. } ``` ```js function foo(a) { - if (Math.random() < 0.5) { - var a = 0; // already defined in the upper scope. - } + if (Math.random() < 0.5) { + var a = 0 // already defined in the upper scope. + } } ``` @@ -63,11 +62,10 @@ function foo(a) { ```js if (Math.random() < 0.5) { - var a = 0; - console.log(a); -} -else { - var a = 1; - console.log(a); + var a = 0 + console.log(a) +} else { + var a = 1 + console.log(a) } ``` diff --git a/docs/rules/no-literal-call.md b/docs/rules/no-literal-call.md index 733ede7..d649ef7 100644 --- a/docs/rules/no-literal-call.md +++ b/docs/rules/no-literal-call.md @@ -1,4 +1,4 @@ -# Disallow a call of a literal (no-literal-call) +# Disallow a call of a literal (no-literal-call) A call of a literal is a valid syntax, but it would cause a runtime error. @@ -9,8 +9,8 @@ Examples of **incorrect** code for this rule: ```js /*eslint no-literal-call: "error"*/ -123(); -"hello"(); +123() +"hello"() ``` Examples of **correct** code for this rule: @@ -18,6 +18,6 @@ Examples of **correct** code for this rule: ```js /*eslint no-literal-call: "error"*/ -foo(); -(function() {})(); +foo() +;(function () {})() ``` diff --git a/docs/rules/no-this-in-static.md b/docs/rules/no-this-in-static.md index 7a7d64b..efb4dc0 100644 --- a/docs/rules/no-this-in-static.md +++ b/docs/rules/no-this-in-static.md @@ -19,13 +19,13 @@ class A { } static bar() { - this.foo() //ERROR: Unexpected 'this'. + this.foo() //ERROR: Unexpected 'this'. } } class B extends A { static foo() { - super.foo() //ERROR: Unexpected 'super'. + super.foo() //ERROR: Unexpected 'super'. } } ``` diff --git a/docs/rules/no-use-ignored-vars.md b/docs/rules/no-use-ignored-vars.md index e63a63c..aea7c08 100644 --- a/docs/rules/no-use-ignored-vars.md +++ b/docs/rules/no-use-ignored-vars.md @@ -13,11 +13,11 @@ Examples of **incorrect** code for this rule: ```js /*eslint no-use-ignored-vars: "error"*/ -let _foo = 0; -doSomething(_foo); +let _foo = 0 +doSomething(_foo) function foo(_a) { - doSomething(_a); + doSomething(_a) } ``` @@ -26,10 +26,10 @@ Examples of **correct** code for this rule: ```js /*eslint no-use-ignored-vars: "error"*/ -let _foo = 0; +let _foo = 0 function foo(_a) { - doSomething(); + doSomething() } ``` diff --git a/docs/rules/no-useless-rest-spread.md b/docs/rules/no-useless-rest-spread.md index ca1e48b..ebcb001 100644 --- a/docs/rules/no-useless-rest-spread.md +++ b/docs/rules/no-useless-rest-spread.md @@ -25,11 +25,10 @@ Examples of **correct** code for this rule: /*eslint no-useless-rest-spread: "error"*/ let list = [a, b, c, d] -let obj = {a, b, c, d} +let obj = { a, b, c, d } foo(a, b, c) -let [a, b, c, d] = list; -let {a, b, c, d} = obj; -function foo(a, b, c, d) { -} +let [a, b, c, d] = list +let { a, b, c, d } = obj +function foo(a, b, c, d) {} ``` diff --git a/docs/rules/prefer-for-of.md b/docs/rules/prefer-for-of.md index 79144dd..64a9780 100644 --- a/docs/rules/prefer-for-of.md +++ b/docs/rules/prefer-for-of.md @@ -10,7 +10,7 @@ It's more readable than `Array#forEach` since it does not require closures. ```js /*eslint prefer-for-of: "error"*/ -list.forEach(value => { +list.forEach((value) => { doSomething(value) }) diff --git a/lib/rules/no-useless-rest-spread.js b/lib/rules/no-useless-rest-spread.js index ee6ba2b..e15d3e4 100644 --- a/lib/rules/no-useless-rest-spread.js +++ b/lib/rules/no-useless-rest-spread.js @@ -131,11 +131,11 @@ module.exports = { nodeType === "RestElement" && argumentType !== parentType const type1 = nodeType === "RestElement" ? "rest" : "spread" const type2 = - /*eslint-disable @mysticatea/prettier */ + /* eslint-disable @mysticatea/prettier */ isRestParameter ? "parameter" : isArray ? "element" : /* otherwise */ "property" - /*eslint-enable @mysticatea/prettier */ + /* eslint-enable @mysticatea/prettier */ context.report({ node, diff --git a/lib/rules/prefer-for-of.js b/lib/rules/prefer-for-of.js index d63ba15..684d911 100644 --- a/lib/rules/prefer-for-of.js +++ b/lib/rules/prefer-for-of.js @@ -115,7 +115,7 @@ function isTraversingArray(node) { let indexDecl = null let lengthDecl = null - /*eslint-disable @mysticatea/prettier */ + /* eslint-disable @mysticatea/prettier */ return ( init != null && init.type === "VariableDeclaration" && @@ -186,7 +186,7 @@ function isTraversingArray(node) { ) ) ) - /*eslint-enable @mysticatea/prettier */ + /* eslint-enable @mysticatea/prettier */ } /** diff --git a/package.json b/package.json index a598887..b84be2b 100644 --- a/package.json +++ b/package.json @@ -39,6 +39,7 @@ "clean": "rimraf .nyc_output coverage", "coverage": "opener coverage/lcov-report/index.html", "codecov": "codecov --disable=gcov -t $CODECOV_TOKEN", + "format": "prettier -w .", "lint": "eslint lib scripts tests", "test": "npm run -s lint && nyc mocha \"tests/lib/**/*.js\" --reporter dot", "update": "node scripts/generate-browser-globals && node scripts/generate-configs && node scripts/generate-rules",