Skip to content

Commit efdcf5c

Browse files
committed
feat: change editor rules from disable to non-fixable
1 parent d7834e6 commit efdcf5c

File tree

5 files changed

+38
-24
lines changed

5 files changed

+38
-24
lines changed

README.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@
2424
<br>
2525
</div>
2626

27-
## Features
28-
29-
- "double quotes", must semi;
3027
- Auto fix for formatting (aimed to be used standalone **without** Prettier)
3128
- Reasonable defaults, best practices, only one line of config
3229
- Designed to work with TypeScript, JSX, Vue, JSON, YAML, Toml, Markdown, etc. Out-of-box.
@@ -748,9 +745,15 @@ export default kirklin({
748745

749746
### Editor Specific Disables
750747

751-
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)
748+
Auto-fixing for the following rules are disabled when ESLint is running in a code editor:
749+
750+
- [`prefer-const`](https://eslint.org/docs/rules/prefer-const)
751+
- [`test/no-only-tests`](https://github.com/levibuzolic/eslint-plugin-no-only-tests)
752+
- [`unused-imports/no-unused-imports`](https://www.npmjs.com/package/eslint-plugin-unused-imports)
753+
754+
Since v3.0.0, they are no longer disabled, but made non-fixable using [this helper](https://github.com/antfu/eslint-flat-config-utils#composerdisablerulesfix).
752755

753-
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:
756+
This is to prevent unused imports from getting removed by the editor 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:
754757

755758
```js
756759
// eslint.config.js

README.zh-cn.md

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@
4040
- 可选的[格式化程序](#formatters)支持CSS,HTML,XML等。
4141
- **样式原则**:最小化阅读,稳定的差异性,保持一致性
4242

43-
> [!IMPORTANT]
44-
> 从v1.0.0开始,该配置已重写为新的 [ESLint Flat配置](https://eslint.org/docs/latest/use/configure/configuration-files-new), 请查看[发布说明](https://github.com/kirklin/eslint-config/releases/tag/v1.0.0)以获取更多详细信息。
45-
>
46-
> 自 v2.7.0 起,需要 ESLint v9.5.0+。
43+
> [!NOTE]
44+
> 自 v1.0.0 版本起,该配置已重写为新的 [ESLint Flat 配置](https://eslint.org/docs/latest/use/configure/configuration-files-new),详细信息请查看 [发布说明](https://github.com/kirklin/eslint-config/releases/tag/v1.0.0)
45+
>
46+
> 自 v2.7.0 版本起,现要求使用 ESLint v9.5.0 及以上版本。
4747
4848
## 使用方法
4949

@@ -747,20 +747,19 @@ export default kirklin({
747747
});
748748
```
749749

750-
### 编辑器特定禁用
750+
### 编辑器特定的禁用规则
751751

752-
有些规则在ESLint IDE集成中被禁用,具体来说是 [`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)
752+
当 ESLint 在代码编辑器中运行时,以下规则的自动修复功能被禁用:
753753

754-
这样做是为了防止在重构过程中IDE自动移除未使用的导入,以提供更好的开发体验。当您在终端或使用 [Lint Staged](#lint-staged) 运行ESLint时,这些规则将会被应用。如果您不希望有这样的行为,可以通过以下方式禁用它们:
754+
- [`prefer-const`](https://eslint.org/docs/rules/prefer-const)
755+
- [`test/no-only-tests`](https://github.com/levibuzolic/eslint-plugin-no-only-tests)
756+
- [`unused-imports/no-unused-imports`](https://www.npmjs.com/package/eslint-plugin-unused-imports)
755757

756-
```js
757-
// eslint.config.js
758-
import kirklin from "@kirklin/eslint-config";
758+
自 v3.0.0 版本起,这些规则不再被完全禁用,而是通过 [此辅助工具](https://github.com/antfu/eslint-flat-config-utils#composerdisablerulesfix) 设为不可自动修复。
759759

760-
export default kirklin({
761-
isInEditor: false
762-
});
763-
```
760+
这样可以防止编辑器在重构代码时自动删除未使用的导入,以提供更好的开发体验。这些规则仍然会在你通过终端运行 ESLint 或使用 [Lint Staged](#lint-staged) 时生效。
761+
762+
如果你不希望有这种行为,你可以手动禁用它们。
764763

765764
### Lint Staged
766765

src/configs/javascript.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ export async function javascript(
4848
"accessor-pairs": ["error", { enforceForClassMembers: true, setWithoutGet: true }],
4949

5050
"array-callback-return": "error",
51+
5152
"block-scoped-var": "error",
5253
"constructor-super": "error",
5354
"default-case-last": "error",
@@ -177,7 +178,7 @@ export async function javascript(
177178
},
178179
],
179180
"prefer-const": [
180-
"error",
181+
isInEditor ? "warn" : "error",
181182
{
182183
destructuring: "all",
183184
ignoreReadBeforeAssign: true,
@@ -191,7 +192,7 @@ export async function javascript(
191192
"prefer-template": "error",
192193
"symbol-description": "error",
193194
"unicode-bom": ["error", "never"],
194-
"unused-imports/no-unused-imports": isInEditor ? "off" : "error",
195+
"unused-imports/no-unused-imports": isInEditor ? "warn" : "error",
195196
"unused-imports/no-unused-vars": [
196197
"error",
197198
{

src/configs/test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export async function test(
4747
"test/consistent-test-it": ["error", { fn: "it", withinDescribe: "it" }],
4848
"test/no-identical-title": "error",
4949
"test/no-import-node-test": "error",
50-
"test/no-only-tests": isInEditor ? "off" : "error",
50+
"test/no-only-tests": isInEditor ? "warn" : "error",
5151

5252
"test/prefer-hooks-in-order": "error",
5353
"test/prefer-lowercase-title": "error",

src/factory.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ import {
3333
yaml,
3434
} from "./configs";
3535
import { formatters } from "./configs/formatters";
36-
3736
import { regexp } from "./configs/regexp";
3837
import { interopDefault, isInEditorEnv } from "./utils";
3938

@@ -102,7 +101,7 @@ export function kirklin(
102101
if (isInEditor == null) {
103102
isInEditor = isInEditorEnv();
104103
if (isInEditor) {
105-
console.info("[@kirklin/eslint-config] Detected running in editor, some rules are disabled.");
104+
console.log("[@kirklin/eslint-config] Detected running in editor, some rules are disabled.");
106105
}
107106
}
108107

@@ -207,6 +206,7 @@ export function kirklin(
207206

208207
if (enableReact) {
209208
configs.push(react({
209+
...typescriptOptions,
210210
overrides: getOverrides(options, "react"),
211211
tsconfigPath,
212212
}));
@@ -318,6 +318,17 @@ export function kirklin(
318318
.renamePlugins(defaultPluginRenaming);
319319
}
320320

321+
if (isInEditor) {
322+
composer = composer
323+
.disableRulesFix([
324+
"unused-imports/no-unused-imports",
325+
"test/no-only-tests",
326+
"prefer-const",
327+
], {
328+
builtinRules: () => import(["eslint", "use-at-your-own-risk"].join("/")).then(r => r.builtinRules),
329+
});
330+
}
331+
321332
return composer;
322333
}
323334

0 commit comments

Comments
 (0)