eslint-plugin-valibot 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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026
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,138 @@
1
+ # eslint-plugin-valibot
2
+
3
+ [ESLint](https://eslint.org/) rules for safer, more maintainable [Valibot](https://valibot.dev/) usage.
4
+
5
+ `eslint-plugin-valibot` helps catch common schema mistakes and patterns that make Valibot code harder to maintain.
6
+
7
+ The plugin ships with both flat-config and legacy-config presets, plus individual rules that you can enable as needed.
8
+
9
+ ## Rules
10
+
11
+ <!-- begin auto-generated rules list -->
12
+
13
+ πŸ’Ό Configurations enabled in.\
14
+ ⚠️ Configurations set to warn in.\
15
+ βœ… Set in the `recommended` configuration.\
16
+ πŸ”’ Set in the `strict` configuration.\
17
+ 🎨 Set in the `stylistic` configuration.\
18
+ πŸ”§ Automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/user-guide/command-line-interface#--fix).
19
+
20
+ | NameΒ Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β  | Description | πŸ’Ό | ⚠️ | πŸ”§ |
21
+ | :----------------------------------------------------------------------------------------- | :------------------------------------------------------------------------------------------------ | :--- | :--- | :- |
22
+ | [consistent-import](docs/rules/consistent-import.md) | Enforce a consistent Valibot import style using either namespace or named imports. | | 🎨 | |
23
+ | [consistent-schema-convention](docs/rules/consistent-schema-convention.md) | Enforce a consistent Valibot schema naming convention for exported schemas and inferred types. | | 🎨 | |
24
+ | [no-any-schema](docs/rules/no-any-schema.md) | Disallow Valibot any() schemas. | | πŸ”’ | |
25
+ | [no-duplicate-pipe-actions](docs/rules/no-duplicate-pipe-actions.md) | Disallow duplicate Valibot actions inside the same pipe() call. | | βœ… πŸ”’ | πŸ”§ |
26
+ | [no-empty-pipe](docs/rules/no-empty-pipe.md) | Disallow empty pipe() calls or pipe() calls with a single argument. | βœ… πŸ”’ | | πŸ”§ |
27
+ | [no-instanceof-builtins](docs/rules/no-instanceof-builtins.md) | Prefer primitive schema functions over instance(Constructor) for built-in types. | βœ… πŸ”’ | | πŸ”§ |
28
+ | [no-loose-object](docs/rules/no-loose-object.md) | Disallow disallowed Valibot object schema constructors such as looseObject(). | | πŸ”’ | |
29
+ | [no-recreated-schemas](docs/rules/no-recreated-schemas.md) | Disallow recreating static Valibot schemas inside function scope. | | πŸ”’ | |
30
+ | [no-redundant-schema-wrappers](docs/rules/no-redundant-schema-wrappers.md) | Disallow redundant nested Valibot schema wrappers. | βœ… πŸ”’ | | πŸ”§ |
31
+ | [no-schema-as-type](docs/rules/no-schema-as-type.md) | Disallow using a Valibot schema value itself as a TypeScript type. | πŸ”’ | | |
32
+ | [no-transform-in-record-key](docs/rules/no-transform-in-record-key.md) | Disallow transforms in record() key schemas, which can silently mutate keys and cause collisions. | βœ… πŸ”’ | | |
33
+ | [no-unguarded-parse](docs/rules/no-unguarded-parse.md) | Require Valibot parse() and assert() calls to be wrapped in try/catch. | βœ… πŸ”’ | | |
34
+ | [no-unknown-schema](docs/rules/no-unknown-schema.md) | Disallow Valibot unknown() schemas. | | πŸ”’ | |
35
+ | [prefer-nullable-over-union-null](docs/rules/prefer-nullable-over-union-null.md) | Prefer nullable() over union([schema, null()]) when they are equivalent. | | βœ… πŸ”’ | πŸ”§ |
36
+ | [prefer-nullish](docs/rules/prefer-nullish.md) | Prefer nullish() over nested optional() and nullable() wrappers. | | βœ… πŸ”’ | πŸ”§ |
37
+ | [prefer-optional-over-union-undefined](docs/rules/prefer-optional-over-union-undefined.md) | Prefer optional() over union([schema, undefined()]) when they are equivalent. | | βœ… πŸ”’ | πŸ”§ |
38
+ | [prefer-picklist](docs/rules/prefer-picklist.md) | Prefer picklist() over union() when the union only contains literal string schemas. | | 🎨 | πŸ”§ |
39
+ | [prefer-variant](docs/rules/prefer-variant.md) | Prefer variant() over union() when object schemas share an obvious discriminant key. | | 🎨 | πŸ”§ |
40
+ | [require-issue-messages](docs/rules/require-issue-messages.md) | Require explicit custom issue messages on Valibot schemas and issue-producing actions. | | πŸ”’ | |
41
+
42
+ <!-- end auto-generated rules list -->
43
+
44
+ Every rule has its own documentation page under [docs/rules](docs/rules).
45
+
46
+ ## Installation
47
+
48
+ ```sh
49
+ pnpm add -D eslint-plugin-valibot
50
+ ```
51
+
52
+ It is designed for `eslint@^9 || ^10` and `valibot@^1`.
53
+
54
+ ## Flat Config
55
+
56
+ ```js
57
+ import { defineConfig } from 'eslint/config';
58
+ import js from '@eslint/js';
59
+ import valibot from 'eslint-plugin-valibot';
60
+
61
+ export default defineConfig(
62
+ js.configs.recommended,
63
+ ...valibot.flatConfigs.recommended,
64
+ );
65
+ ```
66
+
67
+ Use `valibot.flatConfigs.strict` for the stricter preset, or append `...valibot.flatConfigs.stylistic` if you also want the naming-style rule.
68
+
69
+ ## Legacy Config
70
+
71
+ ```js
72
+ module.exports = {
73
+ extends: ['plugin:valibot/recommended'],
74
+ };
75
+ ```
76
+
77
+ Available legacy presets are:
78
+
79
+ - `plugin:valibot/recommended`
80
+ - `plugin:valibot/strict`
81
+ - `plugin:valibot/stylistic`
82
+
83
+ ## TypeScript Projects
84
+
85
+ If you lint TypeScript, compose this plugin with `typescript-eslint`. The `strict` preset includes `valibot/no-schema-as-type`, which only applies to TypeScript syntax.
86
+
87
+ ```js
88
+ import tseslint from 'typescript-eslint';
89
+ import valibot from 'eslint-plugin-valibot';
90
+
91
+ export default tseslint.config(
92
+ ...tseslint.configs.recommended,
93
+ ...valibot.flatConfigs.strict,
94
+ );
95
+ ```
96
+
97
+ ## Config Presets
98
+
99
+ | Preset | Intended use | Notes |
100
+ | :------------ | :----------------------------------------------------- | :------------------------------------------------------------------------- |
101
+ | `recommended` | Good default for most codebases | Focuses on common correctness and safety issues. |
102
+ | `strict` | Tighter policy for teams that want broader enforcement | Includes everything in `recommended` plus stricter schema usage checks. |
103
+ | `stylistic` | Naming consistency | Adds naming-convention rules without changing the problem-focused presets. |
104
+
105
+ See [docs/configs.md](docs/configs.md) for the exact rule list in each preset.
106
+
107
+ ## Individual Rules
108
+
109
+ If you prefer to enable rules one by one, register the plugin and configure only the rules you want:
110
+
111
+ ```js
112
+ import { defineConfig } from 'eslint/config';
113
+ import valibot from 'eslint-plugin-valibot';
114
+
115
+ export default defineConfig({
116
+ plugins: {
117
+ valibot,
118
+ },
119
+ rules: {
120
+ 'valibot/no-unguarded-parse': 'error',
121
+ 'valibot/prefer-nullish': 'warn',
122
+ },
123
+ });
124
+ ```
125
+
126
+ ## Examples
127
+
128
+ Working example setups live in this repository:
129
+
130
+ - [examples/flat](examples/flat)
131
+ - [examples/legacy](examples/legacy)
132
+ - [examples/typescript](examples/typescript)
133
+
134
+ The default flat and legacy examples use the `recommended` preset. The flat example directory also includes dedicated `strict` and `stylistic` config files for stricter or naming-focused setups.
135
+
136
+ ## Contributing
137
+
138
+ Contributor setup, checks, and rule authoring workflow live in [CONTRIBUTING.md](CONTRIBUTING.md).