From 605b8982bc5d1bfe4077fac90cd9ab5c0557da2a Mon Sep 17 00:00:00 2001 From: Jumpei Ogawa Date: Sun, 14 Jan 2024 00:51:18 +0900 Subject: [PATCH 01/14] refactor: remove non-existing `@typescript-eslint` rules from `noconflict` --- main.js | 8 -------- 1 file changed, 8 deletions(-) diff --git a/main.js b/main.js index 44b0eef4..10d4629c 100644 --- a/main.js +++ b/main.js @@ -16,11 +16,7 @@ module.exports = { "linebreak-style": "off", "no-trailing-spaces": "off", "unicode-bom": "off", - "@typescript-eslint/eol-last": "off", "@typescript-eslint/indent": "off", - "@typescript-eslint/linebreak-style": "off", - "@typescript-eslint/no-trailing-spaces": "off", - "@typescript-eslint/unicode-bom": "off", }, }, all: { @@ -30,11 +26,7 @@ module.exports = { "linebreak-style": "off", "no-trailing-spaces": "off", "unicode-bom": "off", - "@typescript-eslint/eol-last": "off", "@typescript-eslint/indent": "off", - "@typescript-eslint/linebreak-style": "off", - "@typescript-eslint/no-trailing-spaces": "off", - "@typescript-eslint/unicode-bom": "off", "editorconfig/charset": "error", "editorconfig/eol-last": "error", From e4a8d8b121f121f2e0b390eab2c5456e91d02f52 Mon Sep 17 00:00:00 2001 From: Jumpei Ogawa Date: Mon, 15 Jan 2024 23:04:57 +0900 Subject: [PATCH 02/14] doc: remove non-existing `@typescript-eslint` rules from `noconflict` --- README.md | 4 ---- 1 file changed, 4 deletions(-) diff --git a/README.md b/README.md index bb7cdbb3..9425853d 100644 --- a/README.md +++ b/README.md @@ -78,11 +78,7 @@ It is recommended to disable them. - `linebreak-style` - `no-trailing-spaces` - `unicode-bom` -- `@typescript-eslint/eol-last` - `@typescript-eslint/indent` -- `@typescript-eslint/linebreak-style` -- `@typescript-eslint/no-trailing-spaces` -- `@typescript-eslint/unicode-bom` If above rules are specified in your .eslintrc, just remove them. If they are specified in the extended config, consider adding `plugin:editorconfig/noconflict` to your `extends`. From 5547230f6d098aa1ca34188d3e0c088e7140c954 Mon Sep 17 00:00:00 2001 From: Jumpei Ogawa Date: Sat, 13 Jan 2024 23:25:30 +0900 Subject: [PATCH 03/14] doc: remove installation instruction by yarn --- README.md | 6 ------ 1 file changed, 6 deletions(-) diff --git a/README.md b/README.md index 9425853d..7566e81d 100644 --- a/README.md +++ b/README.md @@ -16,12 +16,6 @@ An ESLint plugin to enforce EditorConfig rules $ npm install --save-dev eslint@8 eslint-plugin-editorconfig ``` -or - -```bash -$ yarn add --dev eslint@8 eslint-plugin-editorconfig -``` - If you use [typescript-eslint](https://github.com/typescript-eslint/typescript-eslint), you need to install `@typescript-eslint/eslint-plugin` too. ```bash From e324b8dce6ffd9c4c39306ff9f6b9621dda110d2 Mon Sep 17 00:00:00 2001 From: Jumpei Ogawa Date: Mon, 15 Jan 2024 23:47:41 +0900 Subject: [PATCH 04/14] chore: remove unnecessary comments --- tests/lib/rules/editorconfig-ts.js | 9 --------- tests/lib/rules/editorconfig.js | 9 --------- 2 files changed, 18 deletions(-) diff --git a/tests/lib/rules/editorconfig-ts.js b/tests/lib/rules/editorconfig-ts.js index c6e38d23..9069f4fb 100644 --- a/tests/lib/rules/editorconfig-ts.js +++ b/tests/lib/rules/editorconfig-ts.js @@ -1,17 +1,8 @@ "use strict"; -// ----------------------------------------------------------------------------- -// Requirements -// ----------------------------------------------------------------------------- - const path = require("path"); const RuleTester = require("eslint").RuleTester; - -// ----------------------------------------------------------------------------- -// Tests -// ----------------------------------------------------------------------------- - const ruleTester = new RuleTester({ parser: require.resolve("@typescript-eslint/parser"), parserOptions: { diff --git a/tests/lib/rules/editorconfig.js b/tests/lib/rules/editorconfig.js index 537244a7..49505d13 100644 --- a/tests/lib/rules/editorconfig.js +++ b/tests/lib/rules/editorconfig.js @@ -1,17 +1,8 @@ "use strict"; -// ----------------------------------------------------------------------------- -// Requirements -// ----------------------------------------------------------------------------- - const path = require("path"); const RuleTester = require("eslint").RuleTester; - -// ----------------------------------------------------------------------------- -// Tests -// ----------------------------------------------------------------------------- - const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 2019 }}); const commonValidTests = [ From 944a0428e21e5f524537ac366253bf91fb12f28a Mon Sep 17 00:00:00 2001 From: Jumpei Ogawa Date: Thu, 30 May 2024 22:21:20 +0900 Subject: [PATCH 05/14] chore: add missing tsconfig.json to example --- .eslintrc.js | 9 +++++++++ examples/flat-config/package.json | 1 + examples/flat-config/tsconfig.json | 4 ++++ 3 files changed, 14 insertions(+) create mode 100644 examples/flat-config/tsconfig.json diff --git a/.eslintrc.js b/.eslintrc.js index 65d6a289..151dda3a 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -15,4 +15,13 @@ module.exports = { rules: { "node/no-unpublished-require": "off", }, + overrides: [ + { + files: [ "examples/flat-config/**/*" ], + parserOptions: { + sourceType: "module", + project: "./examples/flat-config/tsconfig.json", + }, + }, + ], }; diff --git a/examples/flat-config/package.json b/examples/flat-config/package.json index b62109c4..ae78f8f3 100644 --- a/examples/flat-config/package.json +++ b/examples/flat-config/package.json @@ -8,6 +8,7 @@ "lint": "eslint ." }, "devDependencies": { + "@phanect/configs": "latest", "@types/node": "^20.10.6", "eslint": "^8.56.0", "eslint-plugin-editorconfig": "^4.0.3", diff --git a/examples/flat-config/tsconfig.json b/examples/flat-config/tsconfig.json new file mode 100644 index 00000000..6837c24c --- /dev/null +++ b/examples/flat-config/tsconfig.json @@ -0,0 +1,4 @@ +{ + "extends": "@phanect/configs/tsconfig/nodejs", + "include": [ "**/*.ts" ] +} From 9a0578d0eebd70c8deba126e526ad52684b88cf5 Mon Sep 17 00:00:00 2001 From: Jumpei Ogawa Date: Thu, 30 May 2024 22:22:50 +0900 Subject: [PATCH 06/14] test: add eslint-disable-\* comment to a test fixture which includes errors --- examples/flat-config/src/invalid.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/flat-config/src/invalid.ts b/examples/flat-config/src/invalid.ts index f8ced376..bc8f3a6b 100644 --- a/examples/flat-config/src/invalid.ts +++ b/examples/flat-config/src/invalid.ts @@ -3,6 +3,7 @@ import { fetch } from "undici"; const res = await fetch("https://example.com"); try { + // eslint-disable-next-line editorconfig/indent const data = await res.json(); // This line should be warned by this plugin console.log(data); } catch (err) { From 05e40cbc29d008639bf4a35fc094686f256da9fa Mon Sep 17 00:00:00 2001 From: Jumpei Ogawa Date: Thu, 30 May 2024 22:23:21 +0900 Subject: [PATCH 07/14] style: lint --- examples/flat-config/eslint.config.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/flat-config/eslint.config.js b/examples/flat-config/eslint.config.js index 6738b945..7e6e5795 100644 --- a/examples/flat-config/eslint.config.js +++ b/examples/flat-config/eslint.config.js @@ -16,6 +16,6 @@ export default [ plugins: [ "editorconfig" ], }).map(config => ({ ...config, - ignores: [ join(__dirname, "src/invalid.ts") ] + ignores: [ join(__dirname, "src/invalid.ts") ], })), ]; From 12449d3bb95d7181a565d6c1e2f3e8d3f966875e Mon Sep 17 00:00:00 2001 From: Jumpei Ogawa Date: Thu, 30 May 2024 22:24:31 +0900 Subject: [PATCH 08/14] chore: install undici as `dependencies` in the example --- examples/flat-config/package.json | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/examples/flat-config/package.json b/examples/flat-config/package.json index ae78f8f3..6b8a28bf 100644 --- a/examples/flat-config/package.json +++ b/examples/flat-config/package.json @@ -7,11 +7,13 @@ "scripts": { "lint": "eslint ." }, + "dependencies": { + "undici": "^6.2.1" + }, "devDependencies": { "@phanect/configs": "latest", "@types/node": "^20.10.6", "eslint": "^8.56.0", - "eslint-plugin-editorconfig": "^4.0.3", - "undici": "^6.2.1" + "eslint-plugin-editorconfig": "^4.0.3" } } From b1f3e07fa325af3e6934bf11f93df2de14711077 Mon Sep 17 00:00:00 2001 From: Jumpei Ogawa Date: Thu, 30 May 2024 22:26:52 +0900 Subject: [PATCH 09/14] chore: register examples/ directory as a workspace By this commit, example/flat-config/'s deps are automatically installed when you run `npm install` at the project root. --- package.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/package.json b/package.json index 4c2d052f..a5dec437 100644 --- a/package.json +++ b/package.json @@ -23,6 +23,9 @@ "url": "https://github.com/phanect/eslint-plugin-editorconfig/issues" }, "homepage": "https://github.com/phanect/eslint-plugin-editorconfig", + "workspaces": [ + "examples/*" + ], "dependencies": { "editorconfig": "^1.0.2", "eslint": "^8.40.0", From dcdea76d36ca493c9b39a22be76919c9e7500e93 Mon Sep 17 00:00:00 2001 From: Jumpei Ogawa Date: Thu, 30 May 2024 22:21:51 +0900 Subject: [PATCH 10/14] test: temporarily ignore some ESLint rules --- .eslintrc.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.eslintrc.js b/.eslintrc.js index 151dda3a..1d0efec0 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -13,7 +13,9 @@ module.exports = { }, ignorePatterns: [ "test-packages/**" ], rules: { + "node/no-unpublished-import": "off", "node/no-unpublished-require": "off", + "node/no-unsupported-features/es-syntax": "off", }, overrides: [ { From 50b433b78aa1d537556ef1d9da80599659f8f797 Mon Sep 17 00:00:00 2001 From: Jumpei Ogawa Date: Mon, 15 Jan 2024 22:12:42 +0900 Subject: [PATCH 11/14] test: add missing .editorconfig-s for test packages --- .../success/base-rules-conflict/.editorconfig | 12 ++++++++++++ test-packages/success/js/.editorconfig | 12 ++++++++++++ test-packages/success/ts/.editorconfig | 12 ++++++++++++ 3 files changed, 36 insertions(+) create mode 100644 test-packages/success/base-rules-conflict/.editorconfig create mode 100644 test-packages/success/js/.editorconfig create mode 100644 test-packages/success/ts/.editorconfig diff --git a/test-packages/success/base-rules-conflict/.editorconfig b/test-packages/success/base-rules-conflict/.editorconfig new file mode 100644 index 00000000..8c52ff93 --- /dev/null +++ b/test-packages/success/base-rules-conflict/.editorconfig @@ -0,0 +1,12 @@ +root = true + +[*] +charset = utf-8 +end_of_line = lf +indent_style = space +indent_size = 2 +insert_final_newline = true +trim_trailing_whitespace = true + +[*.md] +trim_trailing_whitespace = false diff --git a/test-packages/success/js/.editorconfig b/test-packages/success/js/.editorconfig new file mode 100644 index 00000000..8c52ff93 --- /dev/null +++ b/test-packages/success/js/.editorconfig @@ -0,0 +1,12 @@ +root = true + +[*] +charset = utf-8 +end_of_line = lf +indent_style = space +indent_size = 2 +insert_final_newline = true +trim_trailing_whitespace = true + +[*.md] +trim_trailing_whitespace = false diff --git a/test-packages/success/ts/.editorconfig b/test-packages/success/ts/.editorconfig new file mode 100644 index 00000000..8c52ff93 --- /dev/null +++ b/test-packages/success/ts/.editorconfig @@ -0,0 +1,12 @@ +root = true + +[*] +charset = utf-8 +end_of_line = lf +indent_style = space +indent_size = 2 +insert_final_newline = true +trim_trailing_whitespace = true + +[*.md] +trim_trailing_whitespace = false From 519a8f4b97bdb15786225c61796b73a932fb60a1 Mon Sep 17 00:00:00 2001 From: Jumpei Ogawa Date: Thu, 30 May 2024 22:25:45 +0900 Subject: [PATCH 12/14] chore: install missing package for the example --- examples/flat-config/package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/flat-config/package.json b/examples/flat-config/package.json index 6b8a28bf..a596e692 100644 --- a/examples/flat-config/package.json +++ b/examples/flat-config/package.json @@ -11,6 +11,7 @@ "undici": "^6.2.1" }, "devDependencies": { + "@eslint/eslintrc": "^3.1.0", "@phanect/configs": "latest", "@types/node": "^20.10.6", "eslint": "^8.56.0", From 936d2e3fac3aacf2a6fc99c1db59f4ac3afc610f Mon Sep 17 00:00:00 2001 From: Jumpei Ogawa Date: Sat, 13 Jan 2024 16:56:12 +0900 Subject: [PATCH 13/14] fix: replace deprecated `context.getFilename()` with `context.filename` --- lib/base.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/base.js b/lib/base.js index 14e89cb6..e1d09955 100644 --- a/lib/base.js +++ b/lib/base.js @@ -25,13 +25,12 @@ module.exports.buildRule = ({ baseRuleName, description, omitFirstOption, getESL }, create: function(context) { - const filename = context.getFilename(); - const ecParams = editorconfig.parseSync(context.getFilename(filename)); + const ecParams = editorconfig.parseSync(context.filename); const { enabled, eslintOption } = getESLintOption(ecParams); let baseRule; - if (filename.endsWith(".ts")) { + if (context.filename.endsWith(".ts")) { try { const { rules } = require("@typescript-eslint/eslint-plugin"); baseRule = rules[baseRuleName] ? klona(rules[baseRuleName]) : jsBaseRule; From b66156b35575ca635fdb8a603dc60e179bb0ea77 Mon Sep 17 00:00:00 2001 From: Jumpei Ogawa Date: Wed, 10 Jan 2024 20:30:35 +0900 Subject: [PATCH 14/14] fix: check if `require("@typescript-eslint/eslint-plugin").rules` exists --- lib/base.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/base.js b/lib/base.js index e1d09955..cdc676a4 100644 --- a/lib/base.js +++ b/lib/base.js @@ -33,7 +33,7 @@ module.exports.buildRule = ({ baseRuleName, description, omitFirstOption, getESL if (context.filename.endsWith(".ts")) { try { const { rules } = require("@typescript-eslint/eslint-plugin"); - baseRule = rules[baseRuleName] ? klona(rules[baseRuleName]) : jsBaseRule; + baseRule = rules?.[baseRuleName] ? klona(rules[baseRuleName]) : jsBaseRule; } catch (err) { if (err.code === "MODULE_NOT_FOUND") { throw new Error("eslint-plugin-editorconfig requires typescript and @typescript-eslint/eslint-plugin to lint *.ts files. Run `npm install typescript @typescript-eslint/eslint-plugin`.");