@morev/eslint-disable-autofix 1.0.0 → 1.0.1

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 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
+ });
@@ -0,0 +1,65 @@
1
+ import { Linter } from 'eslint';
2
+
3
+ /**
4
+ * Options of the factory that creates a `disableAutofix` wrapper.
5
+ */
6
+ type CreateDisableAutofixOptions = {
7
+ /**
8
+ * Prefix used to disable autofix for rules.
9
+ *
10
+ * @default 'no-autofix'
11
+ */
12
+ prefix: string;
13
+ };
14
+
15
+ /**
16
+ * Creates a wrapper function that will disable autofix
17
+ * for config rules that have the specified prefix.
18
+ *
19
+ * @example
20
+ * // eslint.config.js
21
+ * const disableAutofix = createDisableAutofix({ prefix: 'disable-autofix' });
22
+ *
23
+ * export default disableAutofix([
24
+ * {
25
+ * plugins: {
26
+ * 'some-plugin': someEslintPlugin,
27
+ * },
28
+ * rules: {
29
+ * 'disable-autofix/no-var': 'error',
30
+ * 'disable-autofix/some-plugin/some-rule': 'error',
31
+ * },
32
+ * },
33
+ * ]);
34
+ *
35
+ * @param options Options of the factory.
36
+ *
37
+ * @returns Wrapper function that will disable autofix for config rules.
38
+ */
39
+ declare const createDisableAutofix: (options?: Partial<CreateDisableAutofixOptions>) => (configurations: Linter.Config[]) => Linter.Config<Linter.RulesRecord>[];
40
+ /**
41
+ * Wrapper function that will disable autofix
42
+ * for config rules that have `no-autofix/` prefix.
43
+ *
44
+ * @example
45
+ * // eslint.config.js
46
+ * export default disableAutofix([
47
+ * {
48
+ * plugins: {
49
+ * 'some-plugin': someEslintPlugin,
50
+ * },
51
+ * rules: {
52
+ * 'no-autofix/no-var': 'error',
53
+ * 'no-autofix/some-plugin/some-rule': 'error',
54
+ * },
55
+ * },
56
+ * ]);
57
+ *
58
+ * @returns
59
+ * Configurations as passed, in which rules with the `no-autofix/` prefix
60
+ * are replaced with the same rules without the prefix,
61
+ * and the original rules are patched so that `autofix` is not performed.
62
+ */
63
+ declare const disableAutofix: (configurations: Linter.Config[]) => Linter.Config<Linter.RulesRecord>[];
64
+
65
+ export { createDisableAutofix, disableAutofix };
@@ -0,0 +1,65 @@
1
+ import { Linter } from 'eslint';
2
+
3
+ /**
4
+ * Options of the factory that creates a `disableAutofix` wrapper.
5
+ */
6
+ type CreateDisableAutofixOptions = {
7
+ /**
8
+ * Prefix used to disable autofix for rules.
9
+ *
10
+ * @default 'no-autofix'
11
+ */
12
+ prefix: string;
13
+ };
14
+
15
+ /**
16
+ * Creates a wrapper function that will disable autofix
17
+ * for config rules that have the specified prefix.
18
+ *
19
+ * @example
20
+ * // eslint.config.js
21
+ * const disableAutofix = createDisableAutofix({ prefix: 'disable-autofix' });
22
+ *
23
+ * export default disableAutofix([
24
+ * {
25
+ * plugins: {
26
+ * 'some-plugin': someEslintPlugin,
27
+ * },
28
+ * rules: {
29
+ * 'disable-autofix/no-var': 'error',
30
+ * 'disable-autofix/some-plugin/some-rule': 'error',
31
+ * },
32
+ * },
33
+ * ]);
34
+ *
35
+ * @param options Options of the factory.
36
+ *
37
+ * @returns Wrapper function that will disable autofix for config rules.
38
+ */
39
+ declare const createDisableAutofix: (options?: Partial<CreateDisableAutofixOptions>) => (configurations: Linter.Config[]) => Linter.Config<Linter.RulesRecord>[];
40
+ /**
41
+ * Wrapper function that will disable autofix
42
+ * for config rules that have `no-autofix/` prefix.
43
+ *
44
+ * @example
45
+ * // eslint.config.js
46
+ * export default disableAutofix([
47
+ * {
48
+ * plugins: {
49
+ * 'some-plugin': someEslintPlugin,
50
+ * },
51
+ * rules: {
52
+ * 'no-autofix/no-var': 'error',
53
+ * 'no-autofix/some-plugin/some-rule': 'error',
54
+ * },
55
+ * },
56
+ * ]);
57
+ *
58
+ * @returns
59
+ * Configurations as passed, in which rules with the `no-autofix/` prefix
60
+ * are replaced with the same rules without the prefix,
61
+ * and the original rules are patched so that `autofix` is not performed.
62
+ */
63
+ declare const disableAutofix: (configurations: Linter.Config[]) => Linter.Config<Linter.RulesRecord>[];
64
+
65
+ 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
+ };
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "Utility to disable autofix for specific ESLint rules",
4
4
  "type": "module",
5
5
  "private": false,
6
- "version": "1.0.0",
6
+ "version": "1.0.1",
7
7
  "engines": {
8
8
  "node": ">=18"
9
9
  },