eslint-plugin-zod 1.0.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,24 @@
1
+ Copyright (c) 2022, Gajus Kuizinas (https://gajus.com/)
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without
5
+ modification, are permitted provided that the following conditions are met:
6
+ * Redistributions of source code must retain the above copyright
7
+ notice, this list of conditions and the following disclaimer.
8
+ * Redistributions in binary form must reproduce the above copyright
9
+ notice, this list of conditions and the following disclaimer in the
10
+ documentation and/or other materials provided with the distribution.
11
+ * Neither the name of the Gajus Kuizinas (https://gajus.com/) nor the
12
+ names of its contributors may be used to endorse or promote products
13
+ derived from this software without specific prior written permission.
14
+
15
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18
+ DISCLAIMED. IN NO EVENT SHALL GAJUS KUIZINAS BE LIABLE FOR ANY
19
+ DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22
+ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package/README.md ADDED
@@ -0,0 +1,70 @@
1
+ <a name="user-content-eslint-plugin-zod"></a>
2
+ <a name="eslint-plugin-zod"></a>
3
+ # eslint-plugin-zod
4
+
5
+ [![Canonical Code Style](https://img.shields.io/badge/code%20style-canonical-blue.svg?style=flat-square)](https://github.com/gajus/canonical)
6
+ [![NPM version](http://img.shields.io/npm/v/eslint-plugin-zod.svg?style=flat-square)](https://www.npmjs.org/package/eslint-plugin-zod)
7
+ [![Twitter Follow](https://img.shields.io/twitter/follow/kuizinas.svg?style=social&label=Follow)](https://twitter.com/kuizinas)
8
+
9
+ [Zod](https://github.com/colinhacks/zod) linting rules for ESLint.
10
+
11
+ * [eslint-plugin-zod](#user-content-eslint-plugin-zod)
12
+ * [Installation](#user-content-eslint-plugin-zod-installation)
13
+ * [Configuration](#user-content-eslint-plugin-zod-configuration)
14
+ * [Rules](#user-content-eslint-plugin-zod-rules)
15
+ * [`require-strict`](#user-content-eslint-plugin-zod-rules-require-strict)
16
+
17
+
18
+ <a name="user-content-eslint-plugin-zod-installation"></a>
19
+ <a name="eslint-plugin-zod-installation"></a>
20
+ ## Installation
21
+
22
+ 1. Install [ESLint](https://www.github.com/eslint/eslint).
23
+ 1. Install [`eslint-plugin-zod`](https://github.com/gajus/eslint-plugin-zod) plugin.
24
+
25
+ <!-- -->
26
+
27
+ ```sh
28
+ npm install eslint --save-dev
29
+ npm install eslint-plugin-zod --save-dev
30
+ ```
31
+
32
+ <a name="user-content-eslint-plugin-zod-configuration"></a>
33
+ <a name="eslint-plugin-zod-configuration"></a>
34
+ ## Configuration
35
+
36
+ 1. Add `plugins` section and specify `eslint-plugin-zod` as a plugin.
37
+ 1. Enable rules.
38
+
39
+ <!-- -->
40
+
41
+ ```json
42
+ {
43
+ "plugins": [
44
+ "zod"
45
+ ],
46
+ "rules": {
47
+ "zod/require-strict": [
48
+ 2,
49
+ ],
50
+ }
51
+ }
52
+
53
+ ```
54
+
55
+ <a name="user-content-eslint-plugin-zod-rules"></a>
56
+ <a name="eslint-plugin-zod-rules"></a>
57
+ ## Rules
58
+
59
+ <!-- Rules are sorted alphabetically. -->
60
+
61
+ <a name="user-content-eslint-plugin-zod-rules-require-strict"></a>
62
+ <a name="eslint-plugin-zod-rules-require-strict"></a>
63
+ ### <code>require-strict</code>
64
+
65
+ _The `--fix` option on the command line automatically fixes problems reported by this rule._
66
+
67
+ Requires that objects are initialized with `.strict()`.
68
+
69
+
70
+
@@ -0,0 +1,26 @@
1
+ declare const _default: {
2
+ rules: {
3
+ 'require-strict': {
4
+ create: (context: any) => {
5
+ CallExpression(node: any): void;
6
+ };
7
+ meta: {
8
+ docs: {
9
+ description: string;
10
+ url: string;
11
+ };
12
+ fixable: string;
13
+ schema: {
14
+ additionalProperties: boolean;
15
+ properties: {};
16
+ type: string;
17
+ }[];
18
+ type: string;
19
+ };
20
+ };
21
+ };
22
+ rulesConfig: {
23
+ 'require-strict': number;
24
+ };
25
+ };
26
+ export = _default;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ const requireStrict_1 = __importDefault(require("./rules/requireStrict"));
6
+ const rules = {
7
+ 'require-strict': requireStrict_1.default,
8
+ };
9
+ module.exports = {
10
+ rules,
11
+ rulesConfig: {
12
+ 'require-strict': 0,
13
+ },
14
+ };
@@ -0,0 +1,19 @@
1
+ declare const _default: {
2
+ create: (context: any) => {
3
+ CallExpression(node: any): void;
4
+ };
5
+ meta: {
6
+ docs: {
7
+ description: string;
8
+ url: string;
9
+ };
10
+ fixable: string;
11
+ schema: {
12
+ additionalProperties: boolean;
13
+ properties: {};
14
+ type: string;
15
+ }[];
16
+ type: string;
17
+ };
18
+ };
19
+ export = _default;
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ const create = (context) => {
3
+ return {
4
+ CallExpression(node) {
5
+ var _a;
6
+ if (node.callee.object.name !== 'z') {
7
+ return;
8
+ }
9
+ if (node.callee.property.name !== 'object') {
10
+ return;
11
+ }
12
+ if (((_a = node.parent.property) === null || _a === void 0 ? void 0 : _a.name) !== 'strict') {
13
+ context.report({
14
+ message: 'Add a strict() call to the schema.',
15
+ node,
16
+ });
17
+ }
18
+ },
19
+ };
20
+ };
21
+ module.exports = {
22
+ create,
23
+ meta: {
24
+ docs: {
25
+ description: 'Requires that objects are initialized with .strict().',
26
+ url: 'https://github.com/gajus/eslint-plugin-zod#eslint-plugin-zod-rules-require-strict',
27
+ },
28
+ fixable: 'code',
29
+ schema: [
30
+ {
31
+ additionalProperties: false,
32
+ properties: {},
33
+ type: 'object',
34
+ },
35
+ ],
36
+ type: 'problem',
37
+ },
38
+ };
package/package.json ADDED
@@ -0,0 +1,50 @@
1
+ {
2
+ "author": {
3
+ "email": "gajus@gajus.com",
4
+ "name": "Gajus Kuizinas",
5
+ "url": "http://gajus.com"
6
+ },
7
+ "description": "Zod linting rules for ESLint.",
8
+ "devDependencies": {
9
+ "@semantic-release/commit-analyzer": "^9.0.2",
10
+ "@semantic-release/github": "^8.0.6",
11
+ "@semantic-release/npm": "^9.0.1",
12
+ "@types/mocha": "^10.0.0",
13
+ "@types/node": "^18.11.9",
14
+ "eslint": "^8.27.0",
15
+ "eslint-config-canonical": "37.0.3",
16
+ "gitdown": "^3.1.5",
17
+ "glob": "^8.0.3",
18
+ "lodash": "^4.17.21",
19
+ "mocha": "^10.1.0",
20
+ "semantic-release": "^19.0.5",
21
+ "tsx": "^3.12.1",
22
+ "typescript": "^4.9.3"
23
+ },
24
+ "engines": {
25
+ "node": ">=12"
26
+ },
27
+ "keywords": [
28
+ "eslint",
29
+ "plugin",
30
+ "zod"
31
+ ],
32
+ "license": "BSD-3-Clause",
33
+ "main": "./dist/src/index.js",
34
+ "name": "eslint-plugin-zod",
35
+ "peerDependencies": {
36
+ "eslint": ">=8.1.0"
37
+ },
38
+ "repository": {
39
+ "type": "git",
40
+ "url": "https://github.com/gajus/eslint-plugin-zod"
41
+ },
42
+ "scripts": {
43
+ "build": "npm run documentation && tsc",
44
+ "documentation": "gitdown ./.README/README.md --output-file ./README.md && npm run documentation-add-assertions",
45
+ "documentation-add-assertions": "tsx ./bin/readmeAssertions",
46
+ "lint": "eslint ./src ./test && tsc --noEmit",
47
+ "test": "mocha --require tsx test/**/*"
48
+ },
49
+ "version": "1.0.0"
50
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,28 @@
1
+ {
2
+ "compilerOptions": {
3
+ "allowSyntheticDefaultImports": true,
4
+ "declaration": true,
5
+ "esModuleInterop": true,
6
+ "module": "commonjs",
7
+ "lib": [
8
+ "es2021"
9
+ ],
10
+ "moduleResolution": "node",
11
+ "noImplicitAny": false,
12
+ "noImplicitReturns": true,
13
+ "useUnknownInCatchVariables": false,
14
+ "outDir": "dist",
15
+ "skipLibCheck": true,
16
+ "strict": true,
17
+ "target": "es2018"
18
+ },
19
+ "exclude": [
20
+ "dist",
21
+ "node_modules"
22
+ ],
23
+ "include": [
24
+ "bin",
25
+ "src",
26
+ "test"
27
+ ]
28
+ }