From 12dd5b5bd749029634d13a0cde573f28375dd5cb Mon Sep 17 00:00:00 2001 From: Anthony Fu Date: Tue, 21 Jan 2025 22:21:44 +0800 Subject: [PATCH] feat: turn off `prefer-const` in editor --- .vscode/settings.json | 4 ---- README.md | 6 +++++- src/configs/javascript.ts | 16 +++++++++------- src/factory.ts | 1 - 4 files changed, 14 insertions(+), 13 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index b0343ebecd..c085e9d49a 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -9,10 +9,6 @@ "source.organizeImports": "never" }, - "eslint.options": { - "flags": ["unstable_ts_config"] - }, - "eslint.runtime": "node", // Silent the stylistic rules in you IDE, but still auto fix them diff --git a/README.md b/README.md index 37c50dd247..9d27086bc7 100644 --- a/README.md +++ b/README.md @@ -730,7 +730,11 @@ export default antfu({ ### Editor Specific Disables -Some rules are disabled when inside ESLint IDE integrations, namely [`unused-imports/no-unused-imports`](https://www.npmjs.com/package/eslint-plugin-unused-imports) [`test/no-only-tests`](https://github.com/levibuzolic/eslint-plugin-no-only-tests) +Some rules are disabled when inside ESLint IDE integrations, namely: + +- [`prefer-const`](https://eslint.org/docs/rules/prefer-const) +- [`unused-imports/no-unused-imports`](https://www.npmjs.com/package/eslint-plugin-unused-imports) +- [`test/no-only-tests`](https://github.com/levibuzolic/eslint-plugin-no-only-tests) This is to prevent unused imports from getting removed by the IDE during refactoring to get a better developer experience. Those rules will be applied when you run ESLint in the terminal or [Lint Staged](#lint-staged). If you don't want this behavior, you can disable them: diff --git a/src/configs/javascript.ts b/src/configs/javascript.ts index 896acd7f2c..cf853b0cfa 100644 --- a/src/configs/javascript.ts +++ b/src/configs/javascript.ts @@ -177,13 +177,15 @@ export async function javascript( allowUnboundThis: true, }, ], - 'prefer-const': [ - 'error', - { - destructuring: 'all', - ignoreReadBeforeAssign: true, - }, - ], + 'prefer-const': isInEditor + ? 'off' + : [ + 'error', + { + destructuring: 'all', + ignoreReadBeforeAssign: true, + }, + ], 'prefer-exponentiation-operator': 'error', 'prefer-promise-reject-errors': 'error', 'prefer-regex-literals': ['error', { disallowRedundantWrapping: true }], diff --git a/src/factory.ts b/src/factory.ts index 96e9b7a71e..86506a3575 100644 --- a/src/factory.ts +++ b/src/factory.ts @@ -33,7 +33,6 @@ import { yaml, } from './configs' import { formatters } from './configs/formatters' - import { regexp } from './configs/regexp' import { interopDefault, isInEditorEnv } from './utils'