@lohn/eslint-plugin-disable-autofix 6.1.3
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 +21 -0
- package/README.md +9 -0
- package/index.d.ts +21 -0
- package/index.js +326 -0
- package/package.json +43 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) Mikl Wolfe
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# @lohn/eslint-plugin-disable-autofix
|
|
2
|
+
|
|
3
|
+
> **Temporary fork — use the original: [eslint-plugin-disable-autofix](https://www.npmjs.com/package/eslint-plugin-disable-autofix)**
|
|
4
|
+
|
|
5
|
+
This package publishes bug fixes pending merge upstream. Once the fixes are merged, this package will be removed and no longer usable — switch back to the original before then.
|
|
6
|
+
|
|
7
|
+
## License
|
|
8
|
+
|
|
9
|
+
MIT
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { Linter, Rule } from 'eslint';
|
|
2
|
+
interface CreatePluginOptions {
|
|
3
|
+
mode?: 'all' | 'fix' | 'suggest';
|
|
4
|
+
plugins?: string[];
|
|
5
|
+
}
|
|
6
|
+
interface PluginInstance {
|
|
7
|
+
meta: {
|
|
8
|
+
name: string;
|
|
9
|
+
version: string;
|
|
10
|
+
};
|
|
11
|
+
configs: Record<string, Linter.Config | Linter.Config[]>;
|
|
12
|
+
rules: Record<string, Rule.RuleModule>;
|
|
13
|
+
processors: Record<string, Linter.Processor>;
|
|
14
|
+
configure: (rules: Record<string, Linter.RuleEntry>) => {
|
|
15
|
+
plugins: Record<string, PluginInstance>;
|
|
16
|
+
rules: Record<string, Linter.RuleEntry>;
|
|
17
|
+
};
|
|
18
|
+
createPlugin: (options?: CreatePluginOptions) => PluginInstance;
|
|
19
|
+
}
|
|
20
|
+
declare const plugin: PluginInstance;
|
|
21
|
+
export = plugin;
|
package/index.js
ADDED
|
@@ -0,0 +1,326 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
6
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
7
|
+
const VERSION = '6.1.3';
|
|
8
|
+
const MODES = {
|
|
9
|
+
all: { fix: true, suggest: true },
|
|
10
|
+
fix: { fix: true, suggest: false },
|
|
11
|
+
suggest: { fix: false, suggest: true },
|
|
12
|
+
};
|
|
13
|
+
const MODE_PREFIXES = {
|
|
14
|
+
all: 'disable-autofix',
|
|
15
|
+
fix: 'disable-fix',
|
|
16
|
+
suggest: 'disable-suggest',
|
|
17
|
+
};
|
|
18
|
+
const disableFix = (rule, mode) => {
|
|
19
|
+
const result = {
|
|
20
|
+
create(context) {
|
|
21
|
+
const wrappedContext = Object.create(context, {
|
|
22
|
+
report: {
|
|
23
|
+
enumerable: true,
|
|
24
|
+
value(descriptor) {
|
|
25
|
+
const cleaned = { ...descriptor };
|
|
26
|
+
if (mode.fix) {
|
|
27
|
+
delete cleaned.fix;
|
|
28
|
+
}
|
|
29
|
+
if (mode.suggest) {
|
|
30
|
+
delete cleaned.suggest;
|
|
31
|
+
}
|
|
32
|
+
context.report(cleaned);
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
});
|
|
36
|
+
return rule.create(wrappedContext);
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
if (rule.meta) {
|
|
40
|
+
const meta = { ...rule.meta };
|
|
41
|
+
if (mode.fix) {
|
|
42
|
+
delete meta.fixable;
|
|
43
|
+
}
|
|
44
|
+
if (mode.suggest) {
|
|
45
|
+
delete meta.hasSuggestions;
|
|
46
|
+
}
|
|
47
|
+
result.meta = meta;
|
|
48
|
+
}
|
|
49
|
+
return result;
|
|
50
|
+
};
|
|
51
|
+
const convertPluginId = (pluginId) => {
|
|
52
|
+
if (pluginId.startsWith('@')) {
|
|
53
|
+
return pluginId.replace(/\/eslint-plugin(-|$)/u, '/').replace(/\/$/, '');
|
|
54
|
+
}
|
|
55
|
+
return pluginId.replace(/^eslint-plugin-/u, '');
|
|
56
|
+
};
|
|
57
|
+
const safeRequire = (id) => {
|
|
58
|
+
try {
|
|
59
|
+
const module_ = require(id);
|
|
60
|
+
if (module_.__esModule &&
|
|
61
|
+
module_.default &&
|
|
62
|
+
typeof module_.default === 'object') {
|
|
63
|
+
return module_.default;
|
|
64
|
+
}
|
|
65
|
+
return module_;
|
|
66
|
+
}
|
|
67
|
+
catch {
|
|
68
|
+
return undefined;
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
let eslintBuiltinRules;
|
|
72
|
+
try {
|
|
73
|
+
const unsupported = require('eslint/use-at-your-own-risk');
|
|
74
|
+
eslintBuiltinRules = unsupported.builtinRules;
|
|
75
|
+
}
|
|
76
|
+
catch {
|
|
77
|
+
}
|
|
78
|
+
let discoveryDone = false;
|
|
79
|
+
const builtinRuleNames = [];
|
|
80
|
+
const prefixToPackage = new Map();
|
|
81
|
+
const discover = () => {
|
|
82
|
+
if (discoveryDone) {
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
discoveryDone = true;
|
|
86
|
+
const nmDirectories = [];
|
|
87
|
+
try {
|
|
88
|
+
const eslintEntry = require.resolve('eslint/package.json');
|
|
89
|
+
nmDirectories.push(node_path_1.default.resolve(node_path_1.default.dirname(eslintEntry), '..'));
|
|
90
|
+
}
|
|
91
|
+
catch {
|
|
92
|
+
}
|
|
93
|
+
const searchPaths = require.resolve.paths?.('eslint-plugin-disable-autofix') ?? [];
|
|
94
|
+
for (const p of searchPaths) {
|
|
95
|
+
try {
|
|
96
|
+
if (!nmDirectories.includes(p) && node_fs_1.default.statSync(p).isDirectory()) {
|
|
97
|
+
nmDirectories.push(p);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
catch {
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
if (nmDirectories.length === 0) {
|
|
104
|
+
nmDirectories.push(node_path_1.default.join(process.cwd(), 'node_modules'));
|
|
105
|
+
}
|
|
106
|
+
if (eslintBuiltinRules) {
|
|
107
|
+
builtinRuleNames.push(...eslintBuiltinRules.keys());
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
for (const nmDir of nmDirectories) {
|
|
111
|
+
try {
|
|
112
|
+
const rulesDir = node_path_1.default.join(nmDir, 'eslint', 'lib', 'rules');
|
|
113
|
+
for (const f of node_fs_1.default.readdirSync(rulesDir)) {
|
|
114
|
+
if (f.endsWith('.js') && !f.includes('index')) {
|
|
115
|
+
const name = f.replace('.js', '');
|
|
116
|
+
if (!builtinRuleNames.includes(name)) {
|
|
117
|
+
builtinRuleNames.push(name);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
break;
|
|
122
|
+
}
|
|
123
|
+
catch {
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
const seen = new Set();
|
|
128
|
+
for (const nmDir of nmDirectories) {
|
|
129
|
+
try {
|
|
130
|
+
for (const entry of node_fs_1.default.readdirSync(nmDir)) {
|
|
131
|
+
if (entry === 'eslint-plugin-disable-autofix') {
|
|
132
|
+
continue;
|
|
133
|
+
}
|
|
134
|
+
if (entry === '@types' || entry.startsWith('@eslint')) {
|
|
135
|
+
continue;
|
|
136
|
+
}
|
|
137
|
+
if (entry.startsWith('eslint-plugin-') && !seen.has(entry)) {
|
|
138
|
+
seen.add(entry);
|
|
139
|
+
prefixToPackage.set(convertPluginId(entry), entry);
|
|
140
|
+
}
|
|
141
|
+
else if (entry.startsWith('@')) {
|
|
142
|
+
try {
|
|
143
|
+
const scopeDir = node_path_1.default.join(nmDir, entry);
|
|
144
|
+
for (const sub of node_fs_1.default.readdirSync(scopeDir)) {
|
|
145
|
+
if (!sub.startsWith('eslint-plugin')) {
|
|
146
|
+
continue;
|
|
147
|
+
}
|
|
148
|
+
const package_ = `${entry}/${sub}`;
|
|
149
|
+
if (!seen.has(package_)) {
|
|
150
|
+
seen.add(package_);
|
|
151
|
+
prefixToPackage.set(convertPluginId(package_), package_);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
catch {
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
catch {
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
const pluginRulesCache = new Map();
|
|
165
|
+
const loadPluginRules = (packageName) => {
|
|
166
|
+
if (pluginRulesCache.has(packageName)) {
|
|
167
|
+
return pluginRulesCache.get(packageName);
|
|
168
|
+
}
|
|
169
|
+
const module_ = safeRequire(packageName);
|
|
170
|
+
const rules = module_?.rules ?? {};
|
|
171
|
+
pluginRulesCache.set(packageName, rules);
|
|
172
|
+
return rules;
|
|
173
|
+
};
|
|
174
|
+
const loadBuiltinRule = (name) => {
|
|
175
|
+
if (eslintBuiltinRules) {
|
|
176
|
+
return eslintBuiltinRules.get(name);
|
|
177
|
+
}
|
|
178
|
+
try {
|
|
179
|
+
const eslintDir = node_path_1.default.dirname(require.resolve('eslint/package.json'));
|
|
180
|
+
return require(node_path_1.default.join(eslintDir, 'lib', 'rules', `${name}.js`));
|
|
181
|
+
}
|
|
182
|
+
catch {
|
|
183
|
+
return undefined;
|
|
184
|
+
}
|
|
185
|
+
};
|
|
186
|
+
const parseRuleName = (name) => {
|
|
187
|
+
let bestPrefix = '';
|
|
188
|
+
for (const prefix of prefixToPackage.keys()) {
|
|
189
|
+
if (name.startsWith(`${prefix}/`) && prefix.length > bestPrefix.length) {
|
|
190
|
+
bestPrefix = prefix;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
if (bestPrefix) {
|
|
194
|
+
return { prefix: bestPrefix, ruleId: name.slice(bestPrefix.length + 1) };
|
|
195
|
+
}
|
|
196
|
+
return undefined;
|
|
197
|
+
};
|
|
198
|
+
const createPlugin = (options) => {
|
|
199
|
+
discover();
|
|
200
|
+
const modeName = options?.mode ?? 'all';
|
|
201
|
+
const mode = MODES[modeName] ?? MODES.all;
|
|
202
|
+
const prefix = MODE_PREFIXES[modeName] ?? 'disable-autofix';
|
|
203
|
+
const allowedPrefixes = options?.plugins ? new Set(options.plugins) : null;
|
|
204
|
+
const ruleCache = new Map();
|
|
205
|
+
const isAllowed = (name) => {
|
|
206
|
+
if (!allowedPrefixes) {
|
|
207
|
+
return true;
|
|
208
|
+
}
|
|
209
|
+
if (!name.includes('/')) {
|
|
210
|
+
return true;
|
|
211
|
+
}
|
|
212
|
+
const parsed = parseRuleName(name);
|
|
213
|
+
return parsed ? allowedPrefixes.has(parsed.prefix) : false;
|
|
214
|
+
};
|
|
215
|
+
const getRule = (name) => {
|
|
216
|
+
if (ruleCache.has(name)) {
|
|
217
|
+
return ruleCache.get(name);
|
|
218
|
+
}
|
|
219
|
+
if (!isAllowed(name)) {
|
|
220
|
+
return undefined;
|
|
221
|
+
}
|
|
222
|
+
let original;
|
|
223
|
+
if (name.includes('/')) {
|
|
224
|
+
const parsed = parseRuleName(name);
|
|
225
|
+
if (!parsed) {
|
|
226
|
+
return undefined;
|
|
227
|
+
}
|
|
228
|
+
const packageName = prefixToPackage.get(parsed.prefix);
|
|
229
|
+
if (!packageName) {
|
|
230
|
+
return undefined;
|
|
231
|
+
}
|
|
232
|
+
const rules = loadPluginRules(packageName);
|
|
233
|
+
original = rules[parsed.ruleId];
|
|
234
|
+
}
|
|
235
|
+
else {
|
|
236
|
+
if (!builtinRuleNames.includes(name)) {
|
|
237
|
+
return undefined;
|
|
238
|
+
}
|
|
239
|
+
original = loadBuiltinRule(name);
|
|
240
|
+
}
|
|
241
|
+
if (!original) {
|
|
242
|
+
return undefined;
|
|
243
|
+
}
|
|
244
|
+
try {
|
|
245
|
+
const wrapped = disableFix(original, mode);
|
|
246
|
+
ruleCache.set(name, wrapped);
|
|
247
|
+
return wrapped;
|
|
248
|
+
}
|
|
249
|
+
catch {
|
|
250
|
+
return undefined;
|
|
251
|
+
}
|
|
252
|
+
};
|
|
253
|
+
const getRuleNames = () => {
|
|
254
|
+
const names = [...builtinRuleNames];
|
|
255
|
+
const entries = allowedPrefixes
|
|
256
|
+
? [...prefixToPackage.entries()].filter(([p]) => allowedPrefixes.has(p))
|
|
257
|
+
: [...prefixToPackage.entries()];
|
|
258
|
+
for (const [pfx, packageName] of entries) {
|
|
259
|
+
try {
|
|
260
|
+
for (const ruleId of Object.keys(loadPluginRules(packageName))) {
|
|
261
|
+
names.push(`${pfx}/${ruleId}`);
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
catch {
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
return names;
|
|
268
|
+
};
|
|
269
|
+
const rules = new Proxy(Object.create(null), {
|
|
270
|
+
get(_, property) {
|
|
271
|
+
if (typeof property !== 'string') {
|
|
272
|
+
return;
|
|
273
|
+
}
|
|
274
|
+
return getRule(property);
|
|
275
|
+
},
|
|
276
|
+
getOwnPropertyDescriptor(_, property) {
|
|
277
|
+
if (typeof property !== 'string') {
|
|
278
|
+
return;
|
|
279
|
+
}
|
|
280
|
+
if (builtinRuleNames.includes(property)) {
|
|
281
|
+
return { configurable: true, enumerable: true, writable: true };
|
|
282
|
+
}
|
|
283
|
+
const parsed = parseRuleName(property);
|
|
284
|
+
if (parsed && isAllowed(property)) {
|
|
285
|
+
const packageName = prefixToPackage.get(parsed.prefix);
|
|
286
|
+
if (packageName) {
|
|
287
|
+
const pluginRules = loadPluginRules(packageName);
|
|
288
|
+
if (parsed.ruleId in pluginRules) {
|
|
289
|
+
return { configurable: true, enumerable: true, writable: true };
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
},
|
|
294
|
+
has(_, property) {
|
|
295
|
+
if (typeof property !== 'string') {
|
|
296
|
+
return false;
|
|
297
|
+
}
|
|
298
|
+
return getRule(property) !== undefined;
|
|
299
|
+
},
|
|
300
|
+
ownKeys() {
|
|
301
|
+
return getRuleNames();
|
|
302
|
+
},
|
|
303
|
+
});
|
|
304
|
+
const configure = (input) => {
|
|
305
|
+
const resultRules = {};
|
|
306
|
+
for (const [name, config] of Object.entries(input)) {
|
|
307
|
+
resultRules[name] = 'off';
|
|
308
|
+
resultRules[`${prefix}/${name}`] = config;
|
|
309
|
+
}
|
|
310
|
+
return {
|
|
311
|
+
plugins: { [prefix]: instance },
|
|
312
|
+
rules: resultRules,
|
|
313
|
+
};
|
|
314
|
+
};
|
|
315
|
+
const instance = {
|
|
316
|
+
configs: {},
|
|
317
|
+
configure,
|
|
318
|
+
createPlugin,
|
|
319
|
+
meta: { name: 'eslint-plugin-disable-autofix', version: VERSION },
|
|
320
|
+
processors: {},
|
|
321
|
+
rules,
|
|
322
|
+
};
|
|
323
|
+
return instance;
|
|
324
|
+
};
|
|
325
|
+
const plugin = createPlugin();
|
|
326
|
+
module.exports = plugin;
|
package/package.json
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@lohn/eslint-plugin-disable-autofix",
|
|
3
|
+
"version": "6.1.3",
|
|
4
|
+
"description": "Temporary fork of eslint-plugin-disable-autofix — use the original at https://www.npmjs.com/package/eslint-plugin-disable-autofix instead",
|
|
5
|
+
"main": "./index.js",
|
|
6
|
+
"types": "./index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./index.d.ts",
|
|
10
|
+
"default": "./index.js"
|
|
11
|
+
},
|
|
12
|
+
"./package.json": "./package.json"
|
|
13
|
+
},
|
|
14
|
+
"engines": {
|
|
15
|
+
"node": ">=18.18.0"
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"index.js",
|
|
19
|
+
"index.d.ts",
|
|
20
|
+
"LICENSE",
|
|
21
|
+
"README.md"
|
|
22
|
+
],
|
|
23
|
+
"peerDependencies": {
|
|
24
|
+
"eslint": ">=9.0.0"
|
|
25
|
+
},
|
|
26
|
+
"license": "MIT",
|
|
27
|
+
"keywords": [
|
|
28
|
+
"eslint",
|
|
29
|
+
"eslintplugin",
|
|
30
|
+
"eslint-plugin",
|
|
31
|
+
"disable",
|
|
32
|
+
"autofix",
|
|
33
|
+
"suggestions",
|
|
34
|
+
"flat-config"
|
|
35
|
+
],
|
|
36
|
+
"homepage": "https://github.com/lohn/eslint-plugin-disable-autofix/tree/fix-scoped-types-plugin-discovery",
|
|
37
|
+
"repository": {
|
|
38
|
+
"type": "git",
|
|
39
|
+
"url": "git+https://github.com/lohn/eslint-plugin-disable-autofix.git#fix-scoped-types-plugin-discovery"
|
|
40
|
+
},
|
|
41
|
+
"bugs": "https://github.com/lohn/eslint-plugin-disable-autofix/issues",
|
|
42
|
+
"author": "Mikl Wolfe <wolfe@mikl.io> (https://github.com/chiefmikey)"
|
|
43
|
+
}
|