@alextheman/eslint-plugin 5.2.3 → 5.4.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/dist/index.cjs +78 -72
- package/dist/index.d.cts +57 -154
- package/dist/index.d.ts +56 -153
- package/dist/index.js +77 -58
- package/dist/utility/index.cjs +209 -0
- package/dist/utility/index.d.cts +208 -0
- package/dist/utility/index.d.ts +208 -0
- package/dist/utility/index.js +176 -0
- package/package.json +17 -2
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import { AST_NODE_TYPES } from "@typescript-eslint/utils";
|
|
2
|
+
import { DataError, camelToKebab, omitProperties } from "@alextheman/utility";
|
|
3
|
+
import z from "zod";
|
|
4
|
+
|
|
5
|
+
//#region src/utility/public/checkCallExpression.ts
|
|
6
|
+
/**
|
|
7
|
+
* Checks if a given node matches the expected object and property names.
|
|
8
|
+
*
|
|
9
|
+
* @category Utility
|
|
10
|
+
*
|
|
11
|
+
* @param node - The node to check.
|
|
12
|
+
* @param objectName - The object name to compare against the node.
|
|
13
|
+
* @param propertyName - The property name to compare against the node.
|
|
14
|
+
*
|
|
15
|
+
* @returns A value of `true` if the given `objectName` and `propertyName` matches those of the node, and `false` otherwise.
|
|
16
|
+
*/
|
|
17
|
+
function checkCallExpression(node, objectName, propertyName) {
|
|
18
|
+
return node.callee.type === AST_NODE_TYPES.MemberExpression && node.callee.object.type === AST_NODE_TYPES.Identifier && node.callee.object.name === objectName && node.callee.property.type === AST_NODE_TYPES.Identifier && node.callee.property.name === propertyName;
|
|
19
|
+
}
|
|
20
|
+
var checkCallExpression_default = checkCallExpression;
|
|
21
|
+
|
|
22
|
+
//#endregion
|
|
23
|
+
//#region src/utility/public/combineRestrictedImports.ts
|
|
24
|
+
/**
|
|
25
|
+
* Combines multiple option groups for the native ESLint `no-restricted-imports` rule, without overwriting previous configurations.
|
|
26
|
+
*
|
|
27
|
+
* @category Utility
|
|
28
|
+
*
|
|
29
|
+
* @param groups - Option groups to combine, applied in the order provided.
|
|
30
|
+
*
|
|
31
|
+
* @returns A new object combining all paths and patterns from the given groups, suitable as an option to pass to `no-restricted-imports`.
|
|
32
|
+
*/
|
|
33
|
+
function combineRestrictedImports(...groups) {
|
|
34
|
+
const paths = [];
|
|
35
|
+
const patterns = [];
|
|
36
|
+
for (const group of groups) {
|
|
37
|
+
if (group.paths) paths.push(...group.paths);
|
|
38
|
+
if (group.patterns) patterns.push(...group.patterns);
|
|
39
|
+
}
|
|
40
|
+
const combinedGroup = {
|
|
41
|
+
paths,
|
|
42
|
+
patterns
|
|
43
|
+
};
|
|
44
|
+
if (combinedGroup.paths.length === 0) return omitProperties(combinedGroup, "paths");
|
|
45
|
+
if (combinedGroup.patterns.length === 0) return omitProperties(combinedGroup, "patterns");
|
|
46
|
+
return combinedGroup;
|
|
47
|
+
}
|
|
48
|
+
var combineRestrictedImports_default = combineRestrictedImports;
|
|
49
|
+
|
|
50
|
+
//#endregion
|
|
51
|
+
//#region src/utility/public/createRuleSchemaFromZodSchema.ts
|
|
52
|
+
/**
|
|
53
|
+
* Converts a Zod schema to a JSON schema for usage in an ESLint rule.
|
|
54
|
+
*
|
|
55
|
+
* @category Utility
|
|
56
|
+
*
|
|
57
|
+
* @param schema - The Zod schema to convert.
|
|
58
|
+
*
|
|
59
|
+
* @returns An array containing the resulting JSON Schema, formatted for ESLint rule schema compatibility.
|
|
60
|
+
*/
|
|
61
|
+
function createRuleSchemaFromZodSchema(schema) {
|
|
62
|
+
return [omitProperties(z.toJSONSchema(schema), "$schema")];
|
|
63
|
+
}
|
|
64
|
+
var createRuleSchemaFromZodSchema_default = createRuleSchemaFromZodSchema;
|
|
65
|
+
|
|
66
|
+
//#endregion
|
|
67
|
+
//#region src/utility/public/fixOnCondition.ts
|
|
68
|
+
/**
|
|
69
|
+
* Returns a rule fixer function to run based on a given condition
|
|
70
|
+
*
|
|
71
|
+
* @category Utility
|
|
72
|
+
*
|
|
73
|
+
* @param fixable - Whether the rule should be treated as fixable or not, and therefore whether the fixer should run.
|
|
74
|
+
* @param fix - The rule fixer function to run.
|
|
75
|
+
*
|
|
76
|
+
* @returns The rule fixer function invoked with the fixer, provided the fixable condition is met.
|
|
77
|
+
*/
|
|
78
|
+
function fixOnCondition(fixable, fix) {
|
|
79
|
+
return (fixer) => {
|
|
80
|
+
if (!fixable) return null;
|
|
81
|
+
return fix(fixer);
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
var fixOnCondition_default = fixOnCondition;
|
|
85
|
+
|
|
86
|
+
//#endregion
|
|
87
|
+
//#region src/utility/private/camelToKebab.ts
|
|
88
|
+
function camelToKebab$1(string) {
|
|
89
|
+
if (string[0] === string[0].toUpperCase()) throw new DataError(string, "CAMEL_TO_KEBAB_CONVERSION_ERROR", "camelCase string must start with a lowercase letter.");
|
|
90
|
+
return camelToKebab(string, { preserveConsecutiveCapitals: false });
|
|
91
|
+
}
|
|
92
|
+
var camelToKebab_default = camelToKebab$1;
|
|
93
|
+
|
|
94
|
+
//#endregion
|
|
95
|
+
//#region src/utility/private/createConfigGroup.ts
|
|
96
|
+
function createConfigGroup(group, configs) {
|
|
97
|
+
const newConfigs = {};
|
|
98
|
+
for (const key in configs) newConfigs[`${camelToKebab_default(group)}/${camelToKebab_default(key)}`] = configs[key];
|
|
99
|
+
return newConfigs;
|
|
100
|
+
}
|
|
101
|
+
var createConfigGroup_default = createConfigGroup;
|
|
102
|
+
|
|
103
|
+
//#endregion
|
|
104
|
+
//#region src/utility/public/flattenConfigs.ts
|
|
105
|
+
/**
|
|
106
|
+
* Takes in a nested group of configs, and returns them flattened according to ESLint config naming conventions.
|
|
107
|
+
*
|
|
108
|
+
* @category Utility
|
|
109
|
+
*
|
|
110
|
+
* @template ConfigObject - The type of the input config object.
|
|
111
|
+
*
|
|
112
|
+
* @param config - A doubly-nested config object to pass in, where the key of the top-level object is the config group name, and the key of the nested object is the name of the config within the group (e.g. `groupName.configName`).
|
|
113
|
+
*
|
|
114
|
+
* @returns A single-layered object with the key flattened down to be `group-name/config-name`.
|
|
115
|
+
*
|
|
116
|
+
* @example
|
|
117
|
+
* flattenConfigs<AlexPluginConfigGroup>({
|
|
118
|
+
* general: {
|
|
119
|
+
* typeScript: generalTypeScriptConfig,
|
|
120
|
+
* javaScript: generalJavaScriptConfig,
|
|
121
|
+
* react: generalReactConfig,
|
|
122
|
+
* // ...
|
|
123
|
+
* }
|
|
124
|
+
* plugin: {
|
|
125
|
+
* base: pluginBaseConfig,
|
|
126
|
+
* tests: pluginTestsConfig,
|
|
127
|
+
* // ...
|
|
128
|
+
* }
|
|
129
|
+
* })
|
|
130
|
+
*
|
|
131
|
+
* // Returns:
|
|
132
|
+
* {
|
|
133
|
+
* "general/typescript": generalTypeScriptConfig,
|
|
134
|
+
* "general/javascript": generalJavaScriptConfig,
|
|
135
|
+
* "general/react": generalReactConfig,
|
|
136
|
+
* // ...,
|
|
137
|
+
* "plugin/base": pluginBaseConfig,
|
|
138
|
+
* "plugin/tests": pluginTestsConfig
|
|
139
|
+
* // ...
|
|
140
|
+
* }
|
|
141
|
+
*/
|
|
142
|
+
function flattenConfigs(config) {
|
|
143
|
+
const allConfigs = {};
|
|
144
|
+
for (const configGroupEntries of Object.entries(config)) Object.assign(allConfigs, createConfigGroup_default(...configGroupEntries));
|
|
145
|
+
return allConfigs;
|
|
146
|
+
}
|
|
147
|
+
var flattenConfigs_default = flattenConfigs;
|
|
148
|
+
|
|
149
|
+
//#endregion
|
|
150
|
+
//#region src/utility/public/getImportSpecifiersAfterRemoving.ts
|
|
151
|
+
/**
|
|
152
|
+
* Returns a comma-separated string of import specifiers, excluding the specified import.
|
|
153
|
+
*
|
|
154
|
+
* Useful for auto-fixable rules that remove a specific import from an import statement.
|
|
155
|
+
*
|
|
156
|
+
* @category Utility
|
|
157
|
+
*
|
|
158
|
+
* @template RuleOptions - The type of the RuleOptions from the given context.
|
|
159
|
+
*
|
|
160
|
+
* @param context - The current ESLint rule context.
|
|
161
|
+
* @param specifiers - Array of import clause nodes.
|
|
162
|
+
* @param importToRemove - The import name to remove from the list.
|
|
163
|
+
*
|
|
164
|
+
* @returns A comma-separated string of import specifiers after removing the specified import.
|
|
165
|
+
*/
|
|
166
|
+
function getImportSpecifiersAfterRemoving(context, specifiers, importToRemove) {
|
|
167
|
+
return specifiers.filter((specifier) => {
|
|
168
|
+
return !(specifier.imported.name === importToRemove);
|
|
169
|
+
}).map((specifier) => {
|
|
170
|
+
return context.sourceCode.getText(specifier);
|
|
171
|
+
}).join(", ");
|
|
172
|
+
}
|
|
173
|
+
var getImportSpecifiersAfterRemoving_default = getImportSpecifiersAfterRemoving;
|
|
174
|
+
|
|
175
|
+
//#endregion
|
|
176
|
+
export { checkCallExpression_default as checkCallExpression, combineRestrictedImports_default as combineRestrictedImports, createRuleSchemaFromZodSchema_default as createRuleSchemaFromZodSchema, fixOnCondition_default as fixOnCondition, flattenConfigs_default as flattenConfigs, getImportSpecifiersAfterRemoving_default as getImportSpecifiersAfterRemoving };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alextheman/eslint-plugin",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.4.0",
|
|
4
4
|
"description": "A package to provide custom ESLint rules and configs",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -9,6 +9,20 @@
|
|
|
9
9
|
"license": "MIT",
|
|
10
10
|
"author": "alextheman",
|
|
11
11
|
"type": "module",
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
15
|
+
"import": "./dist/index.js",
|
|
16
|
+
"require": "./dist/index.cjs",
|
|
17
|
+
"default": "./dist/index.js"
|
|
18
|
+
},
|
|
19
|
+
"./utility": {
|
|
20
|
+
"types": "./dist/utility/index.d.ts",
|
|
21
|
+
"import": "./dist/utility/index.js",
|
|
22
|
+
"require": "./dist/utility/index.cjs",
|
|
23
|
+
"default": "./dist/utility/index.js"
|
|
24
|
+
}
|
|
25
|
+
},
|
|
12
26
|
"main": "dist/index.js",
|
|
13
27
|
"types": "dist/index.d.ts",
|
|
14
28
|
"files": [
|
|
@@ -75,13 +89,14 @@
|
|
|
75
89
|
"eslint-plugin-react-refresh": ">=0.4.0",
|
|
76
90
|
"typedoc": ">=0.28.15",
|
|
77
91
|
"typedoc-plugin-markdown": ">=4.9.0",
|
|
78
|
-
"typedoc-rhineai-theme": "
|
|
92
|
+
"typedoc-rhineai-theme": ">=1.2.0",
|
|
79
93
|
"typescript-eslint": ">=8.0.0",
|
|
80
94
|
"vite-tsconfig-paths": ">=5.1.4",
|
|
81
95
|
"vitest": ">=4.0.13"
|
|
82
96
|
},
|
|
83
97
|
"scripts": {
|
|
84
98
|
"build": "tsdown",
|
|
99
|
+
"create-feature-docs": "typedoc",
|
|
85
100
|
"create-local-package": "pnpm run build && rm -f alextheman-eslint-plugin-*.tgz && pnpm pack",
|
|
86
101
|
"create-release-note-major": "git pull origin main && alex-c-line create-release-note major",
|
|
87
102
|
"create-release-note-minor": "git pull origin main && alex-c-line create-release-note minor",
|