@morev/eslint-disable-autofix 1.0.0 → 1.0.2
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/dist/index.cjs +110 -0
- package/dist/index.d.cts +66 -0
- package/dist/index.d.ts +66 -0
- package/dist/index.js +74 -0
- package/package.json +1 -1
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/index.ts
|
|
31
|
+
var index_exports = {};
|
|
32
|
+
__export(index_exports, {
|
|
33
|
+
createDisableAutofix: () => createDisableAutofix,
|
|
34
|
+
disableAutofix: () => disableAutofix
|
|
35
|
+
});
|
|
36
|
+
module.exports = __toCommonJS(index_exports);
|
|
37
|
+
var import_utils = require("@morev/utils");
|
|
38
|
+
var import_use_at_your_own_risk = __toESM(require("eslint/use-at-your-own-risk"), 1);
|
|
39
|
+
|
|
40
|
+
// src/utils.ts
|
|
41
|
+
var import_eslint_rule_composer = __toESM(require("eslint-rule-composer"), 1);
|
|
42
|
+
var createNonFixableRule = (rule) => {
|
|
43
|
+
if (!rule) return null;
|
|
44
|
+
return import_eslint_rule_composer.default.mapReports(
|
|
45
|
+
Object.create(rule),
|
|
46
|
+
(problem) => {
|
|
47
|
+
problem.fix = null;
|
|
48
|
+
return problem;
|
|
49
|
+
}
|
|
50
|
+
);
|
|
51
|
+
};
|
|
52
|
+
var omitMutable = (source, keys) => {
|
|
53
|
+
keys.forEach((key) => delete source[key]);
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
// src/index.ts
|
|
57
|
+
var internalDisableAutofix = (options) => {
|
|
58
|
+
const { configurations, prefix } = options;
|
|
59
|
+
const allNoAutofixRules = configurations.reduce((acc, configuration) => {
|
|
60
|
+
if ((0, import_utils.isEmpty)(configuration.rules)) return acc;
|
|
61
|
+
const rulesToDisableAutofix = import_utils.tsObject.fromEntries(
|
|
62
|
+
import_utils.tsObject.entries(configuration.rules).filter(([ruleName, ruleValue]) => ruleName.startsWith(prefix))
|
|
63
|
+
);
|
|
64
|
+
if ((0, import_utils.isEmpty)(rulesToDisableAutofix)) return acc;
|
|
65
|
+
const cleanRules = import_utils.tsObject.fromEntries(
|
|
66
|
+
import_utils.tsObject.entries(rulesToDisableAutofix).map(([ruleName, ruleValue]) => [
|
|
67
|
+
ruleName.replace(`${prefix}/`, ""),
|
|
68
|
+
ruleValue
|
|
69
|
+
])
|
|
70
|
+
);
|
|
71
|
+
omitMutable(configuration.rules, import_utils.tsObject.keys(rulesToDisableAutofix));
|
|
72
|
+
Object.assign(configuration.rules, cleanRules);
|
|
73
|
+
acc.push(...import_utils.tsObject.keys(cleanRules));
|
|
74
|
+
return acc;
|
|
75
|
+
}, []);
|
|
76
|
+
if ((0, import_utils.isEmpty)(allNoAutofixRules)) return configurations;
|
|
77
|
+
const allPlugins = configurations.reduce((acc, configuration) => {
|
|
78
|
+
import_utils.tsObject.entries(configuration.plugins ?? {}).forEach(([pluginMappingName, pluginObject]) => {
|
|
79
|
+
acc[pluginMappingName] ??= pluginObject;
|
|
80
|
+
});
|
|
81
|
+
return acc;
|
|
82
|
+
}, {});
|
|
83
|
+
const eslintRules = import_use_at_your_own_risk.default.builtinRules;
|
|
84
|
+
eslintRules._set = Map.prototype.set.bind(eslintRules);
|
|
85
|
+
allNoAutofixRules.forEach((fullRuleName) => {
|
|
86
|
+
const [_, pluginName, ruleName] = fullRuleName.match(/(?:(.*?)\/)?(.*)/);
|
|
87
|
+
if (pluginName && allPlugins[pluginName]?.rules?.[ruleName]) {
|
|
88
|
+
allPlugins[pluginName].rules[ruleName] = createNonFixableRule(allPlugins[pluginName].rules[ruleName]);
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
if (eslintRules.has(fullRuleName)) {
|
|
92
|
+
const originalRule = eslintRules.get(fullRuleName);
|
|
93
|
+
eslintRules._set(fullRuleName, () => createNonFixableRule(originalRule));
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
return configurations;
|
|
97
|
+
};
|
|
98
|
+
var createDisableAutofix = (options) => {
|
|
99
|
+
const { prefix = "no-autofix" } = options ?? {};
|
|
100
|
+
return (configurations) => internalDisableAutofix({
|
|
101
|
+
configurations,
|
|
102
|
+
prefix
|
|
103
|
+
});
|
|
104
|
+
};
|
|
105
|
+
var disableAutofix = createDisableAutofix();
|
|
106
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
107
|
+
0 && (module.exports = {
|
|
108
|
+
createDisableAutofix,
|
|
109
|
+
disableAutofix
|
|
110
|
+
});
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import * as eslint from 'eslint';
|
|
2
|
+
import { PlainObject } from '@morev/utils';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Options of the factory that creates a `disableAutofix` wrapper.
|
|
6
|
+
*/
|
|
7
|
+
type CreateDisableAutofixOptions = {
|
|
8
|
+
/**
|
|
9
|
+
* Prefix used to disable autofix for rules.
|
|
10
|
+
*
|
|
11
|
+
* @default 'no-autofix'
|
|
12
|
+
*/
|
|
13
|
+
prefix: string;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Creates a wrapper function that will disable autofix
|
|
18
|
+
* for config rules that have the specified prefix.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* // eslint.config.js
|
|
22
|
+
* const disableAutofix = createDisableAutofix({ prefix: 'disable-autofix' });
|
|
23
|
+
*
|
|
24
|
+
* export default disableAutofix([
|
|
25
|
+
* {
|
|
26
|
+
* plugins: {
|
|
27
|
+
* 'some-plugin': someEslintPlugin,
|
|
28
|
+
* },
|
|
29
|
+
* rules: {
|
|
30
|
+
* 'disable-autofix/no-var': 'error',
|
|
31
|
+
* 'disable-autofix/some-plugin/some-rule': 'error',
|
|
32
|
+
* },
|
|
33
|
+
* },
|
|
34
|
+
* ]);
|
|
35
|
+
*
|
|
36
|
+
* @param options Options of the factory.
|
|
37
|
+
*
|
|
38
|
+
* @returns Wrapper function that will disable autofix for config rules.
|
|
39
|
+
*/
|
|
40
|
+
declare const createDisableAutofix: (options?: Partial<CreateDisableAutofixOptions>) => (configurations: PlainObject[]) => eslint.Linter.Config<eslint.Linter.RulesRecord>[];
|
|
41
|
+
/**
|
|
42
|
+
* Wrapper function that will disable autofix
|
|
43
|
+
* for config rules that have `no-autofix/` prefix.
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* // eslint.config.js
|
|
47
|
+
* export default disableAutofix([
|
|
48
|
+
* {
|
|
49
|
+
* plugins: {
|
|
50
|
+
* 'some-plugin': someEslintPlugin,
|
|
51
|
+
* },
|
|
52
|
+
* rules: {
|
|
53
|
+
* 'no-autofix/no-var': 'error',
|
|
54
|
+
* 'no-autofix/some-plugin/some-rule': 'error',
|
|
55
|
+
* },
|
|
56
|
+
* },
|
|
57
|
+
* ]);
|
|
58
|
+
*
|
|
59
|
+
* @returns
|
|
60
|
+
* Configurations as passed, in which rules with the `no-autofix/` prefix
|
|
61
|
+
* are replaced with the same rules without the prefix,
|
|
62
|
+
* and the original rules are patched so that `autofix` is not performed.
|
|
63
|
+
*/
|
|
64
|
+
declare const disableAutofix: (configurations: PlainObject[]) => eslint.Linter.Config<eslint.Linter.RulesRecord>[];
|
|
65
|
+
|
|
66
|
+
export { createDisableAutofix, disableAutofix };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import * as eslint from 'eslint';
|
|
2
|
+
import { PlainObject } from '@morev/utils';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Options of the factory that creates a `disableAutofix` wrapper.
|
|
6
|
+
*/
|
|
7
|
+
type CreateDisableAutofixOptions = {
|
|
8
|
+
/**
|
|
9
|
+
* Prefix used to disable autofix for rules.
|
|
10
|
+
*
|
|
11
|
+
* @default 'no-autofix'
|
|
12
|
+
*/
|
|
13
|
+
prefix: string;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Creates a wrapper function that will disable autofix
|
|
18
|
+
* for config rules that have the specified prefix.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* // eslint.config.js
|
|
22
|
+
* const disableAutofix = createDisableAutofix({ prefix: 'disable-autofix' });
|
|
23
|
+
*
|
|
24
|
+
* export default disableAutofix([
|
|
25
|
+
* {
|
|
26
|
+
* plugins: {
|
|
27
|
+
* 'some-plugin': someEslintPlugin,
|
|
28
|
+
* },
|
|
29
|
+
* rules: {
|
|
30
|
+
* 'disable-autofix/no-var': 'error',
|
|
31
|
+
* 'disable-autofix/some-plugin/some-rule': 'error',
|
|
32
|
+
* },
|
|
33
|
+
* },
|
|
34
|
+
* ]);
|
|
35
|
+
*
|
|
36
|
+
* @param options Options of the factory.
|
|
37
|
+
*
|
|
38
|
+
* @returns Wrapper function that will disable autofix for config rules.
|
|
39
|
+
*/
|
|
40
|
+
declare const createDisableAutofix: (options?: Partial<CreateDisableAutofixOptions>) => (configurations: PlainObject[]) => eslint.Linter.Config<eslint.Linter.RulesRecord>[];
|
|
41
|
+
/**
|
|
42
|
+
* Wrapper function that will disable autofix
|
|
43
|
+
* for config rules that have `no-autofix/` prefix.
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* // eslint.config.js
|
|
47
|
+
* export default disableAutofix([
|
|
48
|
+
* {
|
|
49
|
+
* plugins: {
|
|
50
|
+
* 'some-plugin': someEslintPlugin,
|
|
51
|
+
* },
|
|
52
|
+
* rules: {
|
|
53
|
+
* 'no-autofix/no-var': 'error',
|
|
54
|
+
* 'no-autofix/some-plugin/some-rule': 'error',
|
|
55
|
+
* },
|
|
56
|
+
* },
|
|
57
|
+
* ]);
|
|
58
|
+
*
|
|
59
|
+
* @returns
|
|
60
|
+
* Configurations as passed, in which rules with the `no-autofix/` prefix
|
|
61
|
+
* are replaced with the same rules without the prefix,
|
|
62
|
+
* and the original rules are patched so that `autofix` is not performed.
|
|
63
|
+
*/
|
|
64
|
+
declare const disableAutofix: (configurations: PlainObject[]) => eslint.Linter.Config<eslint.Linter.RulesRecord>[];
|
|
65
|
+
|
|
66
|
+
export { createDisableAutofix, disableAutofix };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import { isEmpty, tsObject } from "@morev/utils";
|
|
3
|
+
import riskyEslint from "eslint/use-at-your-own-risk";
|
|
4
|
+
|
|
5
|
+
// src/utils.ts
|
|
6
|
+
import ruleComposer from "eslint-rule-composer";
|
|
7
|
+
var createNonFixableRule = (rule) => {
|
|
8
|
+
if (!rule) return null;
|
|
9
|
+
return ruleComposer.mapReports(
|
|
10
|
+
Object.create(rule),
|
|
11
|
+
(problem) => {
|
|
12
|
+
problem.fix = null;
|
|
13
|
+
return problem;
|
|
14
|
+
}
|
|
15
|
+
);
|
|
16
|
+
};
|
|
17
|
+
var omitMutable = (source, keys) => {
|
|
18
|
+
keys.forEach((key) => delete source[key]);
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
// src/index.ts
|
|
22
|
+
var internalDisableAutofix = (options) => {
|
|
23
|
+
const { configurations, prefix } = options;
|
|
24
|
+
const allNoAutofixRules = configurations.reduce((acc, configuration) => {
|
|
25
|
+
if (isEmpty(configuration.rules)) return acc;
|
|
26
|
+
const rulesToDisableAutofix = tsObject.fromEntries(
|
|
27
|
+
tsObject.entries(configuration.rules).filter(([ruleName, ruleValue]) => ruleName.startsWith(prefix))
|
|
28
|
+
);
|
|
29
|
+
if (isEmpty(rulesToDisableAutofix)) return acc;
|
|
30
|
+
const cleanRules = tsObject.fromEntries(
|
|
31
|
+
tsObject.entries(rulesToDisableAutofix).map(([ruleName, ruleValue]) => [
|
|
32
|
+
ruleName.replace(`${prefix}/`, ""),
|
|
33
|
+
ruleValue
|
|
34
|
+
])
|
|
35
|
+
);
|
|
36
|
+
omitMutable(configuration.rules, tsObject.keys(rulesToDisableAutofix));
|
|
37
|
+
Object.assign(configuration.rules, cleanRules);
|
|
38
|
+
acc.push(...tsObject.keys(cleanRules));
|
|
39
|
+
return acc;
|
|
40
|
+
}, []);
|
|
41
|
+
if (isEmpty(allNoAutofixRules)) return configurations;
|
|
42
|
+
const allPlugins = configurations.reduce((acc, configuration) => {
|
|
43
|
+
tsObject.entries(configuration.plugins ?? {}).forEach(([pluginMappingName, pluginObject]) => {
|
|
44
|
+
acc[pluginMappingName] ??= pluginObject;
|
|
45
|
+
});
|
|
46
|
+
return acc;
|
|
47
|
+
}, {});
|
|
48
|
+
const eslintRules = riskyEslint.builtinRules;
|
|
49
|
+
eslintRules._set = Map.prototype.set.bind(eslintRules);
|
|
50
|
+
allNoAutofixRules.forEach((fullRuleName) => {
|
|
51
|
+
const [_, pluginName, ruleName] = fullRuleName.match(/(?:(.*?)\/)?(.*)/);
|
|
52
|
+
if (pluginName && allPlugins[pluginName]?.rules?.[ruleName]) {
|
|
53
|
+
allPlugins[pluginName].rules[ruleName] = createNonFixableRule(allPlugins[pluginName].rules[ruleName]);
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
if (eslintRules.has(fullRuleName)) {
|
|
57
|
+
const originalRule = eslintRules.get(fullRuleName);
|
|
58
|
+
eslintRules._set(fullRuleName, () => createNonFixableRule(originalRule));
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
return configurations;
|
|
62
|
+
};
|
|
63
|
+
var createDisableAutofix = (options) => {
|
|
64
|
+
const { prefix = "no-autofix" } = options ?? {};
|
|
65
|
+
return (configurations) => internalDisableAutofix({
|
|
66
|
+
configurations,
|
|
67
|
+
prefix
|
|
68
|
+
});
|
|
69
|
+
};
|
|
70
|
+
var disableAutofix = createDisableAutofix();
|
|
71
|
+
export {
|
|
72
|
+
createDisableAutofix,
|
|
73
|
+
disableAutofix
|
|
74
|
+
};
|