eslint-plugin-zod-mini 0.1.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 +21 -0
- package/README.md +149 -0
- package/dist/_virtual/_rolldown/runtime.cjs +23 -0
- package/dist/index.cjs +62 -0
- package/dist/index.d.cts +22 -0
- package/dist/index.d.mts +23 -0
- package/dist/index.mjs +62 -0
- package/dist/meta.cjs +12 -0
- package/dist/meta.mjs +9 -0
- package/dist/rules/consistent-import-source.cjs +61 -0
- package/dist/rules/consistent-import-source.mjs +60 -0
- package/dist/rules/consistent-import.cjs +153 -0
- package/dist/rules/consistent-import.mjs +152 -0
- package/dist/rules/consistent-object-schema-type.cjs +82 -0
- package/dist/rules/consistent-object-schema-type.mjs +81 -0
- package/dist/rules/consistent-schema-output-type-style.cjs +70 -0
- package/dist/rules/consistent-schema-output-type-style.mjs +69 -0
- package/dist/rules/consistent-schema-var-name.cjs +76 -0
- package/dist/rules/consistent-schema-var-name.mjs +75 -0
- package/dist/rules/no-any-schema.cjs +63 -0
- package/dist/rules/no-any-schema.mjs +62 -0
- package/dist/rules/no-empty-custom-schema.cjs +36 -0
- package/dist/rules/no-empty-custom-schema.mjs +36 -0
- package/dist/rules/no-unknown-schema.cjs +31 -0
- package/dist/rules/no-unknown-schema.mjs +31 -0
- package/dist/rules/prefer-meta.cjs +46 -0
- package/dist/rules/prefer-meta.mjs +45 -0
- package/dist/rules/prefer-namespace-import.cjs +117 -0
- package/dist/rules/prefer-namespace-import.mjs +116 -0
- package/dist/rules/require-brand-type-parameter.cjs +49 -0
- package/dist/rules/require-brand-type-parameter.mjs +49 -0
- package/dist/rules/require-error-message.cjs +85 -0
- package/dist/rules/require-error-message.mjs +84 -0
- package/dist/rules/require-schema-suffix.cjs +69 -0
- package/dist/rules/require-schema-suffix.mjs +68 -0
- package/dist/rules/schema-error-property-style.cjs +96 -0
- package/dist/rules/schema-error-property-style.mjs +94 -0
- package/dist/src/index.d.ts +21 -0
- package/dist/src/index.js +56 -0
- package/dist/src/meta.d.ts +3 -0
- package/dist/src/meta.js +8 -0
- package/dist/src/rules/consistent-import-source.d.ts +11 -0
- package/dist/src/rules/consistent-import-source.js +64 -0
- package/dist/src/rules/consistent-import-source.spec.d.ts +1 -0
- package/dist/src/rules/consistent-import-source.spec.js +103 -0
- package/dist/src/rules/consistent-import.d.ts +12 -0
- package/dist/src/rules/consistent-import.js +176 -0
- package/dist/src/rules/consistent-import.spec.d.ts +1 -0
- package/dist/src/rules/consistent-import.spec.js +194 -0
- package/dist/src/rules/consistent-object-schema-type.d.ts +13 -0
- package/dist/src/rules/consistent-object-schema-type.js +82 -0
- package/dist/src/rules/consistent-object-schema-type.spec.d.ts +1 -0
- package/dist/src/rules/consistent-object-schema-type.spec.js +138 -0
- package/dist/src/rules/consistent-schema-output-type-style.d.ts +12 -0
- package/dist/src/rules/consistent-schema-output-type-style.js +81 -0
- package/dist/src/rules/consistent-schema-output-type-style.spec.d.ts +1 -0
- package/dist/src/rules/consistent-schema-output-type-style.spec.js +128 -0
- package/dist/src/rules/consistent-schema-var-name.d.ts +10 -0
- package/dist/src/rules/consistent-schema-var-name.js +86 -0
- package/dist/src/rules/consistent-schema-var-name.spec.d.ts +1 -0
- package/dist/src/rules/consistent-schema-var-name.spec.js +130 -0
- package/dist/src/rules/no-any-schema.d.ts +6 -0
- package/dist/src/rules/no-any-schema.js +65 -0
- package/dist/src/rules/no-any-schema.spec.d.ts +1 -0
- package/dist/src/rules/no-any-schema.spec.js +155 -0
- package/dist/src/rules/no-empty-custom-schema.d.ts +5 -0
- package/dist/src/rules/no-empty-custom-schema.js +43 -0
- package/dist/src/rules/no-empty-custom-schema.spec.d.ts +1 -0
- package/dist/src/rules/no-empty-custom-schema.spec.js +97 -0
- package/dist/src/rules/no-unknown-schema.d.ts +5 -0
- package/dist/src/rules/no-unknown-schema.js +33 -0
- package/dist/src/rules/no-unknown-schema.spec.d.ts +1 -0
- package/dist/src/rules/no-unknown-schema.spec.js +75 -0
- package/dist/src/rules/prefer-meta.d.ts +5 -0
- package/dist/src/rules/prefer-meta.js +51 -0
- package/dist/src/rules/prefer-meta.spec.d.ts +1 -0
- package/dist/src/rules/prefer-meta.spec.js +118 -0
- package/dist/src/rules/prefer-namespace-import.d.ts +5 -0
- package/dist/src/rules/prefer-namespace-import.js +146 -0
- package/dist/src/rules/prefer-namespace-import.spec.d.ts +1 -0
- package/dist/src/rules/prefer-namespace-import.spec.js +100 -0
- package/dist/src/rules/require-brand-type-parameter.d.ts +6 -0
- package/dist/src/rules/require-brand-type-parameter.js +58 -0
- package/dist/src/rules/require-brand-type-parameter.spec.d.ts +1 -0
- package/dist/src/rules/require-brand-type-parameter.spec.js +157 -0
- package/dist/src/rules/require-error-message.d.ts +5 -0
- package/dist/src/rules/require-error-message.js +103 -0
- package/dist/src/rules/require-error-message.spec.d.ts +1 -0
- package/dist/src/rules/require-error-message.spec.js +161 -0
- package/dist/src/rules/require-schema-suffix.d.ts +9 -0
- package/dist/src/rules/require-schema-suffix.js +79 -0
- package/dist/src/rules/require-schema-suffix.spec.d.ts +1 -0
- package/dist/src/rules/require-schema-suffix.spec.js +131 -0
- package/dist/src/rules/schema-error-property-style.d.ts +10 -0
- package/dist/src/rules/schema-error-property-style.js +102 -0
- package/dist/src/rules/schema-error-property-style.spec.d.ts +1 -0
- package/dist/src/rules/schema-error-property-style.spec.js +134 -0
- package/dist/src/utils/create-plugin-rule.d.ts +8 -0
- package/dist/src/utils/create-plugin-rule.js +3 -0
- package/dist/tests/setup.d.ts +1 -0
- package/dist/tests/setup.js +12 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/tsdown.config.d.ts +2 -0
- package/dist/tsdown.config.js +11 -0
- package/dist/utils/create-plugin-rule.cjs +6 -0
- package/dist/utils/create-plugin-rule.mjs +6 -0
- package/dist/vitest.config.d.ts +2 -0
- package/dist/vitest.config.js +7 -0
- package/package.json +80 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025-present Marco Pasqualetti
|
|
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,149 @@
|
|
|
1
|
+
# eslint-plugin-zod-mini
|
|
2
|
+
|
|
3
|
+
[![CI][CIBadge]][CIURL]
|
|
4
|
+
[![Code style: prettier][CodeStyleBadge]][CodeStyleURL]
|
|
5
|
+
[![Lint: eslint][lintBadge]][lintURL]
|
|
6
|
+
[![npm version][npmVersionBadge]][npmVersionURL]
|
|
7
|
+
[![issues][issuesBadge]][issuesURL]
|
|
8
|
+
|
|
9
|
+
[CIBadge]: https://img.shields.io/github/actions/workflow/status/marcalexiei/eslint-plugin-zod/ci.yml?style=for-the-badge&logo=github&event=push&label=CI
|
|
10
|
+
[CIURL]: https://github.com/marcalexiei/eslint-plugin-zod/actions/workflows/CI.yml/badge.svg
|
|
11
|
+
[CodeStyleBadge]: https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=for-the-badge&logo=prettier
|
|
12
|
+
[CodeStyleURL]: https://prettier.io
|
|
13
|
+
[npmVersionBadge]: https://img.shields.io/npm/v/eslint-plugin-zod-mini.svg?style=for-the-badge&logo=npm
|
|
14
|
+
[npmVersionURL]: https://www.npmjs.com/package/eslint-plugin-zod-mini
|
|
15
|
+
[lintBadge]: https://img.shields.io/badge/lint-eslint-3A33D1?logo=eslint&style=for-the-badge
|
|
16
|
+
[lintURL]: https://eslint.org
|
|
17
|
+
[issuesBadge]: https://img.shields.io/github/issues/marcalexiei/eslint-plugin-zod.svg?style=for-the-badge
|
|
18
|
+
[issuesURL]: https://github.com/marcalexiei/eslint-plugin-zod/issues
|
|
19
|
+
|
|
20
|
+
[ESLint](https://eslint.org) plugin that adds custom linting rules to enforce best practices when using [Zod Mini](https://zod.dev/?id=zod-mini) (`zod/mini`).
|
|
21
|
+
|
|
22
|
+
It can also work with [Oxlint](https://oxc.rs/docs/guide/usage/linter.html)!\
|
|
23
|
+
Find out more about [Oxlint's `jsPLugins`](https://oxc.rs/docs/guide/usage/linter/js-plugins.html).
|
|
24
|
+
|
|
25
|
+
## Rules
|
|
26
|
+
|
|
27
|
+
<!-- begin auto-generated rules list -->
|
|
28
|
+
|
|
29
|
+
💼 Configurations enabled in.\
|
|
30
|
+
✅ Set in the `recommended` configuration.\
|
|
31
|
+
🔧 Automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/user-guide/command-line-interface#--fix).\
|
|
32
|
+
💡 Manually fixable by [editor suggestions](https://eslint.org/docs/latest/use/core-concepts#rule-suggestions).\
|
|
33
|
+
❌ Deprecated.
|
|
34
|
+
|
|
35
|
+
| Name | Description | 💼 | 🔧 | 💡 | ❌ |
|
|
36
|
+
| :--------------------------------------------------------------------------------------- | :------------------------------------------------------------------------------------------------- | :-- | :-- | :-- | :-- |
|
|
37
|
+
| [consistent-import](docs/rules/consistent-import.md) | Enforce a consistent import style for Zod Mini | ✅ | 🔧 | | |
|
|
38
|
+
| [consistent-import-source](docs/rules/consistent-import-source.md) | Enforce consistent source from Zod Mini imports | | | 💡 | |
|
|
39
|
+
| [consistent-object-schema-type](docs/rules/consistent-object-schema-type.md) | Enforce consistent usage of Zod Mini schema methods | | | 💡 | |
|
|
40
|
+
| [consistent-schema-output-type-style](docs/rules/consistent-schema-output-type-style.md) | Enforce consistent use of z.infer or z.output for schema type inference | | 🔧 | | |
|
|
41
|
+
| [consistent-schema-var-name](docs/rules/consistent-schema-var-name.md) | Enforce a consistent naming convention for Zod Mini schema variables | ✅ | | | |
|
|
42
|
+
| [no-any-schema](docs/rules/no-any-schema.md) | Disallow usage of `z.any()` in Zod Mini schemas | ✅ | | 💡 | |
|
|
43
|
+
| [no-empty-custom-schema](docs/rules/no-empty-custom-schema.md) | Disallow usage of `z.custom()` without arguments | ✅ | | | |
|
|
44
|
+
| [no-unknown-schema](docs/rules/no-unknown-schema.md) | Disallow usage of `z.unknown()` in Zod Mini schemas | | | | |
|
|
45
|
+
| [prefer-meta](docs/rules/prefer-meta.md) | Enforce usage of `z.meta()` over `z.describe()` | ✅ | 🔧 | | |
|
|
46
|
+
| [prefer-namespace-import](docs/rules/prefer-namespace-import.md) | Enforce importing zod/mini as a namespace import (`import * as z from 'zod/mini'`) | | 🔧 | | ❌ |
|
|
47
|
+
| [require-brand-type-parameter](docs/rules/require-brand-type-parameter.md) | Require type parameter on `.brand()` functions | ✅ | | 💡 | |
|
|
48
|
+
| [require-error-message](docs/rules/require-error-message.md) | Enforce that custom refinements include an error message | ✅ | 🔧 | | |
|
|
49
|
+
| [require-schema-suffix](docs/rules/require-schema-suffix.md) | Require schema suffix when declaring a Zod Mini schema | | | | ❌ |
|
|
50
|
+
| [schema-error-property-style](docs/rules/schema-error-property-style.md) | Enforce consistent style for error messages in Zod Mini schema validation (using ESQuery patterns) | | | | |
|
|
51
|
+
|
|
52
|
+
<!-- end auto-generated rules list -->
|
|
53
|
+
|
|
54
|
+
## Installation
|
|
55
|
+
|
|
56
|
+
### ESLint
|
|
57
|
+
|
|
58
|
+
Install `eslint` and `eslint-plugin-zod-mini` using your preferred package manager:
|
|
59
|
+
|
|
60
|
+
```shell
|
|
61
|
+
npm i --save-dev eslint eslint-plugin-zod-mini
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
```shell
|
|
65
|
+
yarn add --dev eslint eslint-plugin-zod-mini
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
```shell
|
|
69
|
+
pnpm add --save-dev eslint eslint-plugin-zod-mini
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
#### ESLint Configuration
|
|
73
|
+
|
|
74
|
+
1. Import the plugin
|
|
75
|
+
|
|
76
|
+
```ts
|
|
77
|
+
import eslintPluginZodMini from 'eslint-plugin-zod-mini';
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
2. Add `recommended` config to your ESLint setup
|
|
81
|
+
|
|
82
|
+
```ts
|
|
83
|
+
eslintPluginZodMini.configs.recommended,
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
Here's a minimal example using the flat config format:
|
|
87
|
+
|
|
88
|
+
```ts
|
|
89
|
+
// eslint.config.js
|
|
90
|
+
import { defineConfig } from 'eslint/config';
|
|
91
|
+
import eslint from '@eslint/js';
|
|
92
|
+
import eslintPluginZodMini from 'eslint-plugin-zod-mini';
|
|
93
|
+
|
|
94
|
+
export default defineConfig(
|
|
95
|
+
eslint.configs.recommended,
|
|
96
|
+
eslintPluginZodMini.configs.recommended,
|
|
97
|
+
);
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### Oxlint
|
|
101
|
+
|
|
102
|
+
Install `oxlint` and `eslint-plugin-zod-mini` using your preferred package manager:
|
|
103
|
+
|
|
104
|
+
```shell
|
|
105
|
+
npm i --save-dev oxlint eslint-plugin-zod-mini
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
```shell
|
|
109
|
+
yarn add --dev oxlint eslint-plugin-zod-mini
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
```shell
|
|
113
|
+
pnpm add --save-dev oxlint eslint-plugin-zod-mini
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
#### Oxlint Configuration
|
|
117
|
+
|
|
118
|
+
1. Import the plugin
|
|
119
|
+
|
|
120
|
+
```ts
|
|
121
|
+
import eslintPluginZodMini from 'eslint-plugin-zod-mini';
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
2. Add `eslint-plugin-zod-mini` to the `jsPlugins` key
|
|
125
|
+
|
|
126
|
+
```ts
|
|
127
|
+
{
|
|
128
|
+
jsPlugins: ['eslint-plugin-zod-mini'],
|
|
129
|
+
// ...
|
|
130
|
+
}
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
3. Add `eslintPluginZodMini.configs.recommended.rules` to your Oxlint config.\
|
|
134
|
+
Alternatively you can specify the rules manually
|
|
135
|
+
|
|
136
|
+
Here's a minimal example using the flat config format:
|
|
137
|
+
|
|
138
|
+
```ts
|
|
139
|
+
// oxlint.config.ts
|
|
140
|
+
import eslintPluginZodMini from 'eslint-plugin-zod-mini';
|
|
141
|
+
import { defineConfig } from 'oxlint';
|
|
142
|
+
|
|
143
|
+
export default defineConfig({
|
|
144
|
+
jsPlugins: ['eslint-plugin-zod-mini'],
|
|
145
|
+
rules: {
|
|
146
|
+
...eslintPluginZodMini.configs.recommended.rules,
|
|
147
|
+
},
|
|
148
|
+
});
|
|
149
|
+
```
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
//#region \0rolldown/runtime.js
|
|
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 __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
10
|
+
key = keys[i];
|
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
12
|
+
get: ((k) => from[k]).bind(null, key),
|
|
13
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
19
|
+
value: mod,
|
|
20
|
+
enumerable: true
|
|
21
|
+
}) : target, mod));
|
|
22
|
+
//#endregion
|
|
23
|
+
exports.__toESM = __toESM;
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
const require_meta = require("./meta.cjs");
|
|
2
|
+
const require_consistent_import_source = require("./rules/consistent-import-source.cjs");
|
|
3
|
+
const require_consistent_import = require("./rules/consistent-import.cjs");
|
|
4
|
+
const require_consistent_object_schema_type = require("./rules/consistent-object-schema-type.cjs");
|
|
5
|
+
const require_consistent_schema_output_type_style = require("./rules/consistent-schema-output-type-style.cjs");
|
|
6
|
+
const require_consistent_schema_var_name = require("./rules/consistent-schema-var-name.cjs");
|
|
7
|
+
const require_no_any_schema = require("./rules/no-any-schema.cjs");
|
|
8
|
+
const require_no_empty_custom_schema = require("./rules/no-empty-custom-schema.cjs");
|
|
9
|
+
const require_no_unknown_schema = require("./rules/no-unknown-schema.cjs");
|
|
10
|
+
const require_prefer_meta = require("./rules/prefer-meta.cjs");
|
|
11
|
+
const require_prefer_namespace_import = require("./rules/prefer-namespace-import.cjs");
|
|
12
|
+
const require_require_brand_type_parameter = require("./rules/require-brand-type-parameter.cjs");
|
|
13
|
+
const require_require_error_message = require("./rules/require-error-message.cjs");
|
|
14
|
+
const require_require_schema_suffix = require("./rules/require-schema-suffix.cjs");
|
|
15
|
+
const require_schema_error_property_style = require("./rules/schema-error-property-style.cjs");
|
|
16
|
+
//#region src/index.ts
|
|
17
|
+
const eslintPluginZodMini = {
|
|
18
|
+
meta: {
|
|
19
|
+
name: require_meta.PLUGIN_NAME,
|
|
20
|
+
version: require_meta.PLUGIN_VERSION
|
|
21
|
+
},
|
|
22
|
+
rules: {
|
|
23
|
+
"consistent-import": require_consistent_import.consistentImport,
|
|
24
|
+
"consistent-import-source": require_consistent_import_source.consistentImportSource,
|
|
25
|
+
"consistent-object-schema-type": require_consistent_object_schema_type.consistentObjectSchemaType,
|
|
26
|
+
"consistent-schema-output-type-style": require_consistent_schema_output_type_style.consistentSchemaOutputTypeStyle,
|
|
27
|
+
"consistent-schema-var-name": require_consistent_schema_var_name.consistentSchemaVarName,
|
|
28
|
+
"no-any-schema": require_no_any_schema.noAnySchema,
|
|
29
|
+
"no-empty-custom-schema": require_no_empty_custom_schema.noEmptyCustomSchema,
|
|
30
|
+
"no-unknown-schema": require_no_unknown_schema.noUnknownSchema,
|
|
31
|
+
"prefer-meta": require_prefer_meta.preferMeta,
|
|
32
|
+
"prefer-namespace-import": require_prefer_namespace_import.preferNamespaceImport,
|
|
33
|
+
"require-brand-type-parameter": require_require_brand_type_parameter.requireBrandTypeParameter,
|
|
34
|
+
"require-error-message": require_require_error_message.requireErrorMessage,
|
|
35
|
+
"require-schema-suffix": require_require_schema_suffix.requireSchemaSuffix,
|
|
36
|
+
"schema-error-property-style": require_schema_error_property_style.schemaErrorPropertyStyle
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
const recommendedConfig = {
|
|
40
|
+
name: `${require_meta.PLUGIN_NAME}/recommended`,
|
|
41
|
+
files: ["**/*.{js,mjs,cjs,jsx,mjsx,ts,tsx,mtsx}"],
|
|
42
|
+
plugins: { "zod-mini": eslintPluginZodMini },
|
|
43
|
+
rules: {
|
|
44
|
+
"zod-mini/consistent-import": "error",
|
|
45
|
+
"zod-mini/consistent-schema-var-name": "error",
|
|
46
|
+
"zod-mini/no-any-schema": "error",
|
|
47
|
+
"zod-mini/no-empty-custom-schema": "error",
|
|
48
|
+
"zod-mini/prefer-meta": "error",
|
|
49
|
+
"zod-mini/require-brand-type-parameter": "error",
|
|
50
|
+
"zod-mini/require-error-message": "error"
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
var src_default = {
|
|
54
|
+
...eslintPluginZodMini,
|
|
55
|
+
configs: { recommended: recommendedConfig }
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* why `satisfies`?
|
|
59
|
+
* @see https://github.com/marcalexiei/eslint-plugin-zod/issues/49
|
|
60
|
+
*/
|
|
61
|
+
//#endregion
|
|
62
|
+
module.exports = src_default;
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
//#region src/index.d.ts
|
|
2
|
+
interface CompatibleConfig {
|
|
3
|
+
name?: string;
|
|
4
|
+
rules?: object;
|
|
5
|
+
plugins?: Record<string, CompatiblePlugin>;
|
|
6
|
+
}
|
|
7
|
+
interface CompatiblePlugin {
|
|
8
|
+
meta: {
|
|
9
|
+
name: string;
|
|
10
|
+
version: string;
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
declare const _default: {
|
|
14
|
+
configs: {
|
|
15
|
+
recommended: CompatibleConfig;
|
|
16
|
+
};
|
|
17
|
+
meta: {
|
|
18
|
+
name: string;
|
|
19
|
+
version: string;
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
export = _default;
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
//#region src/index.d.ts
|
|
2
|
+
interface CompatibleConfig {
|
|
3
|
+
name?: string;
|
|
4
|
+
rules?: object;
|
|
5
|
+
plugins?: Record<string, CompatiblePlugin>;
|
|
6
|
+
}
|
|
7
|
+
interface CompatiblePlugin {
|
|
8
|
+
meta: {
|
|
9
|
+
name: string;
|
|
10
|
+
version: string;
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
declare const _default: {
|
|
14
|
+
configs: {
|
|
15
|
+
recommended: CompatibleConfig;
|
|
16
|
+
};
|
|
17
|
+
meta: {
|
|
18
|
+
name: string;
|
|
19
|
+
version: string;
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
//#endregion
|
|
23
|
+
export { _default as default };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { PLUGIN_NAME, PLUGIN_VERSION } from "./meta.mjs";
|
|
2
|
+
import { consistentImportSource } from "./rules/consistent-import-source.mjs";
|
|
3
|
+
import { consistentImport } from "./rules/consistent-import.mjs";
|
|
4
|
+
import { consistentObjectSchemaType } from "./rules/consistent-object-schema-type.mjs";
|
|
5
|
+
import { consistentSchemaOutputTypeStyle } from "./rules/consistent-schema-output-type-style.mjs";
|
|
6
|
+
import { consistentSchemaVarName } from "./rules/consistent-schema-var-name.mjs";
|
|
7
|
+
import { noAnySchema } from "./rules/no-any-schema.mjs";
|
|
8
|
+
import { noEmptyCustomSchema } from "./rules/no-empty-custom-schema.mjs";
|
|
9
|
+
import { noUnknownSchema } from "./rules/no-unknown-schema.mjs";
|
|
10
|
+
import { preferMeta } from "./rules/prefer-meta.mjs";
|
|
11
|
+
import { preferNamespaceImport } from "./rules/prefer-namespace-import.mjs";
|
|
12
|
+
import { requireBrandTypeParameter } from "./rules/require-brand-type-parameter.mjs";
|
|
13
|
+
import { requireErrorMessage } from "./rules/require-error-message.mjs";
|
|
14
|
+
import { requireSchemaSuffix } from "./rules/require-schema-suffix.mjs";
|
|
15
|
+
import { schemaErrorPropertyStyle } from "./rules/schema-error-property-style.mjs";
|
|
16
|
+
//#region src/index.ts
|
|
17
|
+
const eslintPluginZodMini = {
|
|
18
|
+
meta: {
|
|
19
|
+
name: PLUGIN_NAME,
|
|
20
|
+
version: PLUGIN_VERSION
|
|
21
|
+
},
|
|
22
|
+
rules: {
|
|
23
|
+
"consistent-import": consistentImport,
|
|
24
|
+
"consistent-import-source": consistentImportSource,
|
|
25
|
+
"consistent-object-schema-type": consistentObjectSchemaType,
|
|
26
|
+
"consistent-schema-output-type-style": consistentSchemaOutputTypeStyle,
|
|
27
|
+
"consistent-schema-var-name": consistentSchemaVarName,
|
|
28
|
+
"no-any-schema": noAnySchema,
|
|
29
|
+
"no-empty-custom-schema": noEmptyCustomSchema,
|
|
30
|
+
"no-unknown-schema": noUnknownSchema,
|
|
31
|
+
"prefer-meta": preferMeta,
|
|
32
|
+
"prefer-namespace-import": preferNamespaceImport,
|
|
33
|
+
"require-brand-type-parameter": requireBrandTypeParameter,
|
|
34
|
+
"require-error-message": requireErrorMessage,
|
|
35
|
+
"require-schema-suffix": requireSchemaSuffix,
|
|
36
|
+
"schema-error-property-style": schemaErrorPropertyStyle
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
const recommendedConfig = {
|
|
40
|
+
name: `${PLUGIN_NAME}/recommended`,
|
|
41
|
+
files: ["**/*.{js,mjs,cjs,jsx,mjsx,ts,tsx,mtsx}"],
|
|
42
|
+
plugins: { "zod-mini": eslintPluginZodMini },
|
|
43
|
+
rules: {
|
|
44
|
+
"zod-mini/consistent-import": "error",
|
|
45
|
+
"zod-mini/consistent-schema-var-name": "error",
|
|
46
|
+
"zod-mini/no-any-schema": "error",
|
|
47
|
+
"zod-mini/no-empty-custom-schema": "error",
|
|
48
|
+
"zod-mini/prefer-meta": "error",
|
|
49
|
+
"zod-mini/require-brand-type-parameter": "error",
|
|
50
|
+
"zod-mini/require-error-message": "error"
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
var src_default = {
|
|
54
|
+
...eslintPluginZodMini,
|
|
55
|
+
configs: { recommended: recommendedConfig }
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* why `satisfies`?
|
|
59
|
+
* @see https://github.com/marcalexiei/eslint-plugin-zod/issues/49
|
|
60
|
+
*/
|
|
61
|
+
//#endregion
|
|
62
|
+
export { src_default as default };
|
package/dist/meta.cjs
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
require("./_virtual/_rolldown/runtime.cjs");
|
|
2
|
+
let node_fs = require("node:fs");
|
|
3
|
+
//#region src/meta.ts
|
|
4
|
+
const { name: PLUGIN_NAME, version: PLUGIN_VERSION, homepage } = JSON.parse((0, node_fs.readFileSync)(new URL("../package.json", require("url").pathToFileURL(__filename).href), "utf8"));
|
|
5
|
+
const PLUGIN_HOMEPAGE = homepage.replace(/#[^#]*$/, "");
|
|
6
|
+
function getRuleURL(ruleID) {
|
|
7
|
+
return `${PLUGIN_HOMEPAGE}/blob/v${PLUGIN_VERSION}/docs/rules/${ruleID}.md`;
|
|
8
|
+
}
|
|
9
|
+
//#endregion
|
|
10
|
+
exports.PLUGIN_NAME = PLUGIN_NAME;
|
|
11
|
+
exports.PLUGIN_VERSION = PLUGIN_VERSION;
|
|
12
|
+
exports.getRuleURL = getRuleURL;
|
package/dist/meta.mjs
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
//#region src/meta.ts
|
|
3
|
+
const { name: PLUGIN_NAME, version: PLUGIN_VERSION, homepage } = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8"));
|
|
4
|
+
const PLUGIN_HOMEPAGE = homepage.replace(/#[^#]*$/, "");
|
|
5
|
+
function getRuleURL(ruleID) {
|
|
6
|
+
return `${PLUGIN_HOMEPAGE}/blob/v${PLUGIN_VERSION}/docs/rules/${ruleID}.md`;
|
|
7
|
+
}
|
|
8
|
+
//#endregion
|
|
9
|
+
export { PLUGIN_NAME, PLUGIN_VERSION, getRuleURL };
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
require("../_virtual/_rolldown/runtime.cjs");
|
|
2
|
+
const require_create_plugin_rule = require("../utils/create-plugin-rule.cjs");
|
|
3
|
+
let _eslint_zod_utils = require("@eslint-zod/utils");
|
|
4
|
+
//#region src/rules/consistent-import-source.ts
|
|
5
|
+
const consistentImportSource = require_create_plugin_rule.createZodMiniPluginRule({
|
|
6
|
+
name: "consistent-import-source",
|
|
7
|
+
meta: {
|
|
8
|
+
hasSuggestions: true,
|
|
9
|
+
type: "suggestion",
|
|
10
|
+
docs: {
|
|
11
|
+
zodImportAllowedSource: "zod-mini",
|
|
12
|
+
description: "Enforce consistent source from Zod Mini imports"
|
|
13
|
+
},
|
|
14
|
+
messages: {
|
|
15
|
+
sourceNotAllowed: "\"{{source}}\" is not allowed. Available values are: {{sources}}",
|
|
16
|
+
replaceSource: "Replace \"{{invalid}}\" with \"{{valid}}\""
|
|
17
|
+
},
|
|
18
|
+
schema: [{
|
|
19
|
+
type: "object",
|
|
20
|
+
properties: { sources: {
|
|
21
|
+
type: "array",
|
|
22
|
+
description: "An array of allowed Zod import sources.",
|
|
23
|
+
items: {
|
|
24
|
+
type: "string",
|
|
25
|
+
enum: [..._eslint_zod_utils.ZOD_IMPORT_SOURCES]
|
|
26
|
+
},
|
|
27
|
+
minItems: 1,
|
|
28
|
+
uniqueItems: true
|
|
29
|
+
} },
|
|
30
|
+
additionalProperties: false
|
|
31
|
+
}]
|
|
32
|
+
},
|
|
33
|
+
defaultOptions: [{ sources: ["zod/mini"] }],
|
|
34
|
+
create(context, [{ sources }]) {
|
|
35
|
+
return { ImportDeclaration(node) {
|
|
36
|
+
const sourceValue = node.source.value;
|
|
37
|
+
if (!sourceValue.startsWith("zod")) return;
|
|
38
|
+
if (sources.includes(sourceValue)) return;
|
|
39
|
+
context.report({
|
|
40
|
+
node,
|
|
41
|
+
messageId: "sourceNotAllowed",
|
|
42
|
+
data: {
|
|
43
|
+
source: sourceValue,
|
|
44
|
+
sources: sources.map((s) => `"${s}"`).join(", ")
|
|
45
|
+
},
|
|
46
|
+
suggest: sources.map((it) => ({
|
|
47
|
+
messageId: "replaceSource",
|
|
48
|
+
data: {
|
|
49
|
+
valid: it,
|
|
50
|
+
invalid: sourceValue
|
|
51
|
+
},
|
|
52
|
+
fix(fixer) {
|
|
53
|
+
return fixer.replaceText(node.source, node.source.raw.replace(sourceValue, it));
|
|
54
|
+
}
|
|
55
|
+
}))
|
|
56
|
+
});
|
|
57
|
+
} };
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
//#endregion
|
|
61
|
+
exports.consistentImportSource = consistentImportSource;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { createZodMiniPluginRule } from "../utils/create-plugin-rule.mjs";
|
|
2
|
+
import { ZOD_IMPORT_SOURCES } from "@eslint-zod/utils";
|
|
3
|
+
//#region src/rules/consistent-import-source.ts
|
|
4
|
+
const consistentImportSource = createZodMiniPluginRule({
|
|
5
|
+
name: "consistent-import-source",
|
|
6
|
+
meta: {
|
|
7
|
+
hasSuggestions: true,
|
|
8
|
+
type: "suggestion",
|
|
9
|
+
docs: {
|
|
10
|
+
zodImportAllowedSource: "zod-mini",
|
|
11
|
+
description: "Enforce consistent source from Zod Mini imports"
|
|
12
|
+
},
|
|
13
|
+
messages: {
|
|
14
|
+
sourceNotAllowed: "\"{{source}}\" is not allowed. Available values are: {{sources}}",
|
|
15
|
+
replaceSource: "Replace \"{{invalid}}\" with \"{{valid}}\""
|
|
16
|
+
},
|
|
17
|
+
schema: [{
|
|
18
|
+
type: "object",
|
|
19
|
+
properties: { sources: {
|
|
20
|
+
type: "array",
|
|
21
|
+
description: "An array of allowed Zod import sources.",
|
|
22
|
+
items: {
|
|
23
|
+
type: "string",
|
|
24
|
+
enum: [...ZOD_IMPORT_SOURCES]
|
|
25
|
+
},
|
|
26
|
+
minItems: 1,
|
|
27
|
+
uniqueItems: true
|
|
28
|
+
} },
|
|
29
|
+
additionalProperties: false
|
|
30
|
+
}]
|
|
31
|
+
},
|
|
32
|
+
defaultOptions: [{ sources: ["zod/mini"] }],
|
|
33
|
+
create(context, [{ sources }]) {
|
|
34
|
+
return { ImportDeclaration(node) {
|
|
35
|
+
const sourceValue = node.source.value;
|
|
36
|
+
if (!sourceValue.startsWith("zod")) return;
|
|
37
|
+
if (sources.includes(sourceValue)) return;
|
|
38
|
+
context.report({
|
|
39
|
+
node,
|
|
40
|
+
messageId: "sourceNotAllowed",
|
|
41
|
+
data: {
|
|
42
|
+
source: sourceValue,
|
|
43
|
+
sources: sources.map((s) => `"${s}"`).join(", ")
|
|
44
|
+
},
|
|
45
|
+
suggest: sources.map((it) => ({
|
|
46
|
+
messageId: "replaceSource",
|
|
47
|
+
data: {
|
|
48
|
+
valid: it,
|
|
49
|
+
invalid: sourceValue
|
|
50
|
+
},
|
|
51
|
+
fix(fixer) {
|
|
52
|
+
return fixer.replaceText(node.source, node.source.raw.replace(sourceValue, it));
|
|
53
|
+
}
|
|
54
|
+
}))
|
|
55
|
+
});
|
|
56
|
+
} };
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
//#endregion
|
|
60
|
+
export { consistentImportSource };
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
require("../_virtual/_rolldown/runtime.cjs");
|
|
2
|
+
const require_create_plugin_rule = require("../utils/create-plugin-rule.cjs");
|
|
3
|
+
let _eslint_zod_utils = require("@eslint-zod/utils");
|
|
4
|
+
let _typescript_eslint_utils = require("@typescript-eslint/utils");
|
|
5
|
+
//#region src/rules/consistent-import.ts
|
|
6
|
+
const IMPORT_SYNTAXES = ["namespace", "named"];
|
|
7
|
+
/**
|
|
8
|
+
* Determines whether the first import in a group is valid for a given import
|
|
9
|
+
* syntax (`named` or `namespace`), taking into account whether the group
|
|
10
|
+
* contains only type imports.
|
|
11
|
+
*
|
|
12
|
+
* Rules enforced:
|
|
13
|
+
* - For `named` syntax:
|
|
14
|
+
* - The first import must have exactly one specifier
|
|
15
|
+
* - That specifier must be a named import of identifier `z`
|
|
16
|
+
* - For `namespace` syntax:
|
|
17
|
+
* - The first import must have exactly one namespace specifier
|
|
18
|
+
* - If the group contains only type imports, the first import must explicitly
|
|
19
|
+
* be declared as `import type`
|
|
20
|
+
*
|
|
21
|
+
* @param group - Metadata describing the import group
|
|
22
|
+
* @param syntax - Expected import syntax for the group
|
|
23
|
+
* @returns `true` if the first import matches the expected syntax and type rules
|
|
24
|
+
*/
|
|
25
|
+
function isGroupFirstImportKindValidForSyntax(group, syntax) {
|
|
26
|
+
const { hasOnlyTypeImports, nodes } = group;
|
|
27
|
+
const [firstImportNode] = nodes;
|
|
28
|
+
const { specifiers, importKind } = firstImportNode;
|
|
29
|
+
if (specifiers.length !== 1) return false;
|
|
30
|
+
const [specifier] = specifiers;
|
|
31
|
+
if (!(syntax === "named" ? specifier.type === _typescript_eslint_utils.AST_NODE_TYPES.ImportSpecifier && specifier.imported.type === _typescript_eslint_utils.AST_NODE_TYPES.Identifier && specifier.imported.name === "z" : specifier.type === _typescript_eslint_utils.AST_NODE_TYPES.ImportNamespaceSpecifier)) return false;
|
|
32
|
+
if (hasOnlyTypeImports) return importKind === "type";
|
|
33
|
+
return true;
|
|
34
|
+
}
|
|
35
|
+
function shouldIdentifierBeRenamed(node) {
|
|
36
|
+
if (node.parent.type === _typescript_eslint_utils.AST_NODE_TYPES.ImportSpecifier) return false;
|
|
37
|
+
if (node.parent.type === _typescript_eslint_utils.AST_NODE_TYPES.MemberExpression && node.parent.object.type === _typescript_eslint_utils.AST_NODE_TYPES.Identifier && node.parent.object.name !== node.name) return false;
|
|
38
|
+
return true;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* From a given specifiers retrieve the most significant to use when creating an alias import
|
|
42
|
+
*/
|
|
43
|
+
function getNamespaceAliasNameFrom(node) {
|
|
44
|
+
if (node.type === _typescript_eslint_utils.AST_NODE_TYPES.ImportDefaultSpecifier || node.type === _typescript_eslint_utils.AST_NODE_TYPES.ImportNamespaceSpecifier) return node.local.name;
|
|
45
|
+
if (node.imported.type === _typescript_eslint_utils.AST_NODE_TYPES.Identifier && node.imported.name === "z") return node.local.name;
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
const consistentImport = require_create_plugin_rule.createZodMiniPluginRule({
|
|
49
|
+
name: "consistent-import",
|
|
50
|
+
meta: {
|
|
51
|
+
type: "problem",
|
|
52
|
+
docs: {
|
|
53
|
+
zodImportAllowedSource: "zod-mini",
|
|
54
|
+
description: "Enforce a consistent import style for Zod Mini"
|
|
55
|
+
},
|
|
56
|
+
fixable: "code",
|
|
57
|
+
messages: {
|
|
58
|
+
changeImportSyntax: "Use a {{syntax}} import for Zod Mini.",
|
|
59
|
+
removeDuplicate: "Remove duplicate Zod Mini import; Zod Mini is already imported.",
|
|
60
|
+
convertUsage: "Update Zod Mini usage to match the {{syntax}} import syntax."
|
|
61
|
+
},
|
|
62
|
+
schema: [{
|
|
63
|
+
type: "object",
|
|
64
|
+
properties: { syntax: {
|
|
65
|
+
description: "Specifies the import syntax to use for Zod Mini.",
|
|
66
|
+
type: "string",
|
|
67
|
+
enum: IMPORT_SYNTAXES
|
|
68
|
+
} },
|
|
69
|
+
additionalProperties: false
|
|
70
|
+
}]
|
|
71
|
+
},
|
|
72
|
+
defaultOptions: [{ syntax: "namespace" }],
|
|
73
|
+
create(context, [options]) {
|
|
74
|
+
const { syntax } = options;
|
|
75
|
+
const { sourceCode } = context;
|
|
76
|
+
const importGroups = {};
|
|
77
|
+
return {
|
|
78
|
+
ImportDeclaration(node) {
|
|
79
|
+
const { source, importKind } = node;
|
|
80
|
+
if (!(0, _eslint_zod_utils.isZodImportSource)(source.value, "zod-mini")) return;
|
|
81
|
+
if (!importGroups[source.value]) importGroups[source.value] = {
|
|
82
|
+
hasOnlyTypeImports: true,
|
|
83
|
+
nodes: []
|
|
84
|
+
};
|
|
85
|
+
if (importGroups[source.value].hasOnlyTypeImports && importKind === "value") importGroups[source.value].hasOnlyTypeImports = false;
|
|
86
|
+
importGroups[source.value].nodes.push(node);
|
|
87
|
+
},
|
|
88
|
+
"Program:exit": function() {
|
|
89
|
+
let namespaceAliasNameIndex = 0;
|
|
90
|
+
for (const importGroup of Object.values(importGroups)) {
|
|
91
|
+
const { hasOnlyTypeImports, nodes } = importGroup;
|
|
92
|
+
const [firstImportNode, ...othersImportNodes] = nodes;
|
|
93
|
+
/**
|
|
94
|
+
* Variable to track all specifiers that later are used by {@link getDeclaredVariables}
|
|
95
|
+
* to add the namespace prefix
|
|
96
|
+
*/
|
|
97
|
+
const nodesWithVariablesToUpdate = [];
|
|
98
|
+
let namespaceAliasName = null;
|
|
99
|
+
for (const specifier of nodes.flatMap((it) => it.specifiers)) {
|
|
100
|
+
if (!namespaceAliasName) {
|
|
101
|
+
namespaceAliasName = getNamespaceAliasNameFrom(specifier);
|
|
102
|
+
if (namespaceAliasName) continue;
|
|
103
|
+
}
|
|
104
|
+
nodesWithVariablesToUpdate.push(specifier);
|
|
105
|
+
}
|
|
106
|
+
if (!namespaceAliasName) {
|
|
107
|
+
namespaceAliasName = "z";
|
|
108
|
+
if (namespaceAliasNameIndex > 0) {
|
|
109
|
+
namespaceAliasName = `z${namespaceAliasNameIndex}`;
|
|
110
|
+
namespaceAliasNameIndex += 1;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
if (!isGroupFirstImportKindValidForSyntax(importGroup, syntax)) context.report({
|
|
114
|
+
node: firstImportNode,
|
|
115
|
+
messageId: "changeImportSyntax",
|
|
116
|
+
data: { syntax },
|
|
117
|
+
fix(fixer) {
|
|
118
|
+
const importTypeKeyword = hasOnlyTypeImports ? "type " : "";
|
|
119
|
+
let importSpecifier;
|
|
120
|
+
if (syntax === "named") if (namespaceAliasName === "z") importSpecifier = "{ z }";
|
|
121
|
+
else importSpecifier = `{ z as ${namespaceAliasName} }`;
|
|
122
|
+
else importSpecifier = `* as ${namespaceAliasName}`;
|
|
123
|
+
const newImportText = `import ${importTypeKeyword}${importSpecifier} from ${firstImportNode.source.raw};`;
|
|
124
|
+
return fixer.replaceText(firstImportNode, newImportText);
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
const allReferences = nodesWithVariablesToUpdate.flatMap((it) => sourceCode.getDeclaredVariables(it)).flatMap((it) => it.references);
|
|
128
|
+
for (const ref of allReferences) {
|
|
129
|
+
const { identifier } = ref;
|
|
130
|
+
if (shouldIdentifierBeRenamed(identifier)) context.report({
|
|
131
|
+
node: identifier,
|
|
132
|
+
messageId: "convertUsage",
|
|
133
|
+
data: { syntax },
|
|
134
|
+
fix(fixer) {
|
|
135
|
+
const newId = `${namespaceAliasName}.${identifier.name}`;
|
|
136
|
+
return fixer.replaceText(identifier, newId);
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
for (const extraImport of othersImportNodes) context.report({
|
|
141
|
+
node: extraImport,
|
|
142
|
+
messageId: "removeDuplicate",
|
|
143
|
+
fix(fixer) {
|
|
144
|
+
return fixer.removeRange(extraImport.range);
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
//#endregion
|
|
153
|
+
exports.consistentImport = consistentImport;
|