@morev/eslint-disable-autofix 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +14 -0
- package/README.md +139 -0
- package/package.json +80 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright © 2025+ [Maxim Morev](https://github.com/MorevM)
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),
|
|
6
|
+
to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
7
|
+
and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
8
|
+
|
|
9
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
10
|
+
|
|
11
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
12
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES
|
|
13
|
+
OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
|
|
14
|
+
OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
<!-- markdownlint-disable-next-line md033 -->
|
|
2
|
+
<img src="./.github/assets/banner.svg" alt="Promo image of @morev/eslint-disable-autofix package" width="830" height="465" />
|
|
3
|
+
|
|
4
|
+

|
|
5
|
+
[](https://opensource.org/licenses/MIT)
|
|
6
|
+

|
|
7
|
+

|
|
8
|
+

|
|
9
|
+

|
|
10
|
+
|
|
11
|
+
# @morev/eslint-disable-autofix
|
|
12
|
+
|
|
13
|
+
This utility allows you to disable autofix for specific ESLint rules by using a custom prefix in your configurations. \
|
|
14
|
+
It's useful when you want a rule to remain active for linting purposes but prevent ESLint from automatically fixing it.
|
|
15
|
+
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
> [!NOTE]
|
|
19
|
+
> This is a temporary solution until [this RFC](https://github.com/eslint/rfcs/pull/134) is accepted
|
|
20
|
+
> and a final implementation is made that closes [this issue](https://github.com/eslint/eslint/issues/18696) -
|
|
21
|
+
> after that the feature for disabling autofix for rules will be in the ESLint core.
|
|
22
|
+
>
|
|
23
|
+
> I am working on RFC development and final implementation in the core myself,
|
|
24
|
+
> but the process will take some time, and the problem is already there.
|
|
25
|
+
>
|
|
26
|
+
> I'll probably be able to implement this as a polyfill for the final solution,
|
|
27
|
+
> once [the RFC](https://github.com/eslint/rfcs/pull/134) discussion reaches
|
|
28
|
+
> a consensus on a public API.
|
|
29
|
+
|
|
30
|
+
---
|
|
31
|
+
|
|
32
|
+
> [!IMPORTANT]
|
|
33
|
+
>
|
|
34
|
+
> * Only works with ESLint v9 and its flat config format;
|
|
35
|
+
> * You have to restart ESLint server after adding/removing `no-autofix/` prefix to take effect.
|
|
36
|
+
|
|
37
|
+
---
|
|
38
|
+
|
|
39
|
+
## Why?
|
|
40
|
+
|
|
41
|
+
Some rules support autofixing, which is often convenient, but in certain cases
|
|
42
|
+
the fixes may be broken, unsafe, or simply undesirable. \
|
|
43
|
+
Ideally, unsafe autofixes should be treated as suggestions, and broken fixes should be reported.
|
|
44
|
+
|
|
45
|
+
However, ESLint is a large ecosystem, and some useful plugins are no longer actively maintained. \
|
|
46
|
+
Even in actively maintained projects, users may want to disable autofixing for specific rules
|
|
47
|
+
due to project-specific or personal preferences.
|
|
48
|
+
|
|
49
|
+
## Installation
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
pnpm add -D @morev/eslint-disable-autofix
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
yarn add @morev/eslint-disable-autofix -D
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
npm install -D @morev/eslint-disable-autofix
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## Usage
|
|
64
|
+
|
|
65
|
+
### Basic usage
|
|
66
|
+
|
|
67
|
+
In your `eslint.config.js` (only flat config is supported):
|
|
68
|
+
|
|
69
|
+
```js
|
|
70
|
+
import { disableAutofix } from '@morev/eslint-disable-autofix';
|
|
71
|
+
import somePlugin from 'some-eslint-plugin';
|
|
72
|
+
|
|
73
|
+
export default disableAutofix([
|
|
74
|
+
{
|
|
75
|
+
plugins: {
|
|
76
|
+
'some-plugin': somePlugin,
|
|
77
|
+
},
|
|
78
|
+
rules: {
|
|
79
|
+
// Disable autofix for a core rule
|
|
80
|
+
'no-autofix/no-var': 'error',
|
|
81
|
+
// Disable autofix for a third-party rule
|
|
82
|
+
'no-autofix/some-plugin/some-rule': 'warn',
|
|
83
|
+
},
|
|
84
|
+
},
|
|
85
|
+
]);
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### Custom prefix
|
|
89
|
+
|
|
90
|
+
If you'd prefer a custom prefix other than `no-autofix/`, use the factory:
|
|
91
|
+
|
|
92
|
+
```js
|
|
93
|
+
import { createDisableAutofix } from '@morev/eslint-disable-autofix';
|
|
94
|
+
|
|
95
|
+
const disableAutofix = createDisableAutofix({
|
|
96
|
+
prefix: 'disable-autofix',
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
export default disableAutofix([
|
|
100
|
+
{
|
|
101
|
+
rules: {
|
|
102
|
+
'disable-autofix/no-var': 'error',
|
|
103
|
+
},
|
|
104
|
+
},
|
|
105
|
+
]);
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
## How it works internally
|
|
109
|
+
|
|
110
|
+
1. Scans passed ESLint configurations for rules with a specified prefix;
|
|
111
|
+
1. Strips the prefix to keep the original name of the rule;
|
|
112
|
+
1. Patches rules from ESLint core or third-party plugins directly to disable autofix.
|
|
113
|
+
|
|
114
|
+
Under the hood, it uses [`eslint-rule-composer`](https://github.com/not-an-aardvark/eslint-rule-composer)
|
|
115
|
+
to wrap rules with autofix disabled.
|
|
116
|
+
|
|
117
|
+
>[!CAUTION]
|
|
118
|
+
> Direct patching is quite risky and hacky, it relies on non-public ESLint API. \
|
|
119
|
+
> While it's currently the only way to access certain rule internals,
|
|
120
|
+
> it may break in future ESLint versions.
|
|
121
|
+
|
|
122
|
+
## Alternatives
|
|
123
|
+
|
|
124
|
+
I've been using [eslint-plugin-no-autofix](https://github.com/aladdin-add/eslint-plugin/tree/master/packages/no-autofix)
|
|
125
|
+
for a long time and haven't had much trouble with it, however recently problems have arisen:
|
|
126
|
+
|
|
127
|
+
1. Some popular plugins (like [eslint-plugin-unicorn](https://github.com/sindresorhus/eslint-plugin-unicorn)
|
|
128
|
+
or [eslint-stylistic](https://github.com/eslint-stylistic/eslint-stylistic))
|
|
129
|
+
switch to the ESM-only distribution format and
|
|
130
|
+
[eslint-plugin-no-autofix](https://github.com/aladdin-add/eslint-plugin/tree/master/packages/no-autofix) doesn't work with it.
|
|
131
|
+
The [issue have no response](https://github.com/aladdin-add/eslint-plugin/issues/104),
|
|
132
|
+
so I've decided to create my own solution that works in a different way.
|
|
133
|
+
1. I'm getting tired of rules being renamed just to make them work. \
|
|
134
|
+
Say I need to disable a rule with autofix turned off for a single file - I write `/* eslint-disable no-autofix/unicorn/no-lonely-if */`. \
|
|
135
|
+
Later, the broken autofix in the original rule gets fixed, I re-enable the main rule,
|
|
136
|
+
and now the directive no longer applies, which leads to unexpected changes I didn't want.
|
|
137
|
+
|
|
138
|
+
Patching the original rules instead of creating new ones might be a bit riskier technically,
|
|
139
|
+
but from a developer experience perspective, it's definitely cleaner and more intuitive.
|
package/package.json
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@morev/eslint-disable-autofix",
|
|
3
|
+
"description": "Utility to disable autofix for specific ESLint rules",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"private": false,
|
|
6
|
+
"version": "1.0.0",
|
|
7
|
+
"engines": {
|
|
8
|
+
"node": ">=18"
|
|
9
|
+
},
|
|
10
|
+
"license": "MIT",
|
|
11
|
+
"publishConfig": {
|
|
12
|
+
"access": "public",
|
|
13
|
+
"registry": "https://registry.npmjs.org/"
|
|
14
|
+
},
|
|
15
|
+
"author": {
|
|
16
|
+
"name": "Maxim Morev",
|
|
17
|
+
"email": "max.seainside@gmail.com"
|
|
18
|
+
},
|
|
19
|
+
"homepage": "https://github.com/MorevM/eslint-disable-autofix#readme",
|
|
20
|
+
"repository": {
|
|
21
|
+
"type": "git",
|
|
22
|
+
"url": "https://github.com/MorevM/eslint-disable-autofix"
|
|
23
|
+
},
|
|
24
|
+
"keywords": [
|
|
25
|
+
"eslint",
|
|
26
|
+
"autofix",
|
|
27
|
+
"no-autofix",
|
|
28
|
+
"disable-autofix"
|
|
29
|
+
],
|
|
30
|
+
"files": [
|
|
31
|
+
"dist"
|
|
32
|
+
],
|
|
33
|
+
"exports": {
|
|
34
|
+
".": {
|
|
35
|
+
"import": {
|
|
36
|
+
"types": "./dist/index.d.ts",
|
|
37
|
+
"default": "./dist/index.js"
|
|
38
|
+
},
|
|
39
|
+
"require": {
|
|
40
|
+
"types": "./dist/index.d.cts",
|
|
41
|
+
"default": "./dist/index.cjs"
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
"main": "./dist/index.cjs",
|
|
46
|
+
"module": "./dist/index.js",
|
|
47
|
+
"types": "./dist/index.d.ts",
|
|
48
|
+
"peerDependencies": {
|
|
49
|
+
"eslint": "^9.0.0"
|
|
50
|
+
},
|
|
51
|
+
"dependencies": {
|
|
52
|
+
"@morev/utils": "^3.12.2",
|
|
53
|
+
"eslint-rule-composer": "^0.3.0"
|
|
54
|
+
},
|
|
55
|
+
"devDependencies": {
|
|
56
|
+
"@morev/commitlint-config": "^0.2.2",
|
|
57
|
+
"@morev/eslint-config": "^38.1.0",
|
|
58
|
+
"@morev/stylelint-config": "^7.1.0",
|
|
59
|
+
"@release-it/conventional-changelog": "^8.0.1",
|
|
60
|
+
"@types/node": "^22.15.18",
|
|
61
|
+
"eslint": "9.27.0",
|
|
62
|
+
"eslint-plugin-unicorn": "^59.0.1",
|
|
63
|
+
"lefthook": "^1.11.13",
|
|
64
|
+
"release-it": "^19.0.2",
|
|
65
|
+
"stylelint": "^16.19.1",
|
|
66
|
+
"ts-node": "^10.9.2",
|
|
67
|
+
"tsup": "^8.5.0",
|
|
68
|
+
"tsx": "^4.19.4",
|
|
69
|
+
"typescript": "^5.8.3",
|
|
70
|
+
"vitest": "^3.1.3"
|
|
71
|
+
},
|
|
72
|
+
"scripts": {
|
|
73
|
+
"test": "vitest",
|
|
74
|
+
"test:dev": "vitest --watch",
|
|
75
|
+
"lint": "eslint \"**/*.{js,ts,vue,json,json5,jsonc,yml,yaml,md}\"",
|
|
76
|
+
"lint:fix": "eslint \"**/*.{js,ts,vue,json,json5,jsonc,yml,yaml,md}\" --fix",
|
|
77
|
+
"build": "rm -rf dist && tsup",
|
|
78
|
+
"release": "release-it --disable-metrics"
|
|
79
|
+
}
|
|
80
|
+
}
|