@sanity/schema-lint 0.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/LICENSE +21 -0
- package/README.md +131 -0
- package/dist/chunk-7D4SUZUM.js +38 -0
- package/dist/chunk-7D4SUZUM.js.map +1 -0
- package/dist/index.d.ts +133 -0
- package/dist/index.js +600 -0
- package/dist/index.js.map +1 -0
- package/dist/magic-string.es-OB3VKCKR.js +1309 -0
- package/dist/magic-string.es-OB3VKCKR.js.map +1 -0
- package/dist/testing.d.ts +81 -0
- package/dist/testing.js +17171 -0
- package/dist/testing.js.map +1 -0
- package/dist/types-C3OVyCP6.d.ts +121 -0
- package/package.json +51 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024-present Sanity.io
|
|
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,131 @@
|
|
|
1
|
+
# @sanity/schema-lint
|
|
2
|
+
|
|
3
|
+
Sanity schema linter for catching common issues and enforcing best practices.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @sanity/schema-lint
|
|
9
|
+
# or
|
|
10
|
+
pnpm add @sanity/schema-lint
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
### Programmatic API
|
|
16
|
+
|
|
17
|
+
```typescript
|
|
18
|
+
import { lint } from '@sanity/schema-lint'
|
|
19
|
+
|
|
20
|
+
// Lint a schema type definition
|
|
21
|
+
const result = lint({
|
|
22
|
+
name: 'post',
|
|
23
|
+
type: 'document',
|
|
24
|
+
fields: [{ name: 'title', type: 'string' }],
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
for (const finding of result.findings) {
|
|
28
|
+
console.log(`${finding.ruleId}: ${finding.message}`)
|
|
29
|
+
}
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
### Lint Multiple Schemas
|
|
33
|
+
|
|
34
|
+
```typescript
|
|
35
|
+
import { lintSchemas } from '@sanity/schema-lint'
|
|
36
|
+
|
|
37
|
+
const schemas = [
|
|
38
|
+
{ name: 'post', type: 'document', fields: [...] },
|
|
39
|
+
{ name: 'author', type: 'document', fields: [...] },
|
|
40
|
+
]
|
|
41
|
+
|
|
42
|
+
const results = lintSchemas(schemas)
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### With Configuration
|
|
46
|
+
|
|
47
|
+
```typescript
|
|
48
|
+
import { lint } from '@sanity/schema-lint'
|
|
49
|
+
|
|
50
|
+
const result = lint(schema, {
|
|
51
|
+
config: {
|
|
52
|
+
rules: {
|
|
53
|
+
'missing-description': false, // Disable rule
|
|
54
|
+
'missing-icon': { enabled: true, severity: 'warning' },
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
})
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Rules
|
|
61
|
+
|
|
62
|
+
### Core Rules
|
|
63
|
+
|
|
64
|
+
| Rule | Severity | Description |
|
|
65
|
+
| ------------------------- | -------- | ---------------------------------------------- |
|
|
66
|
+
| `missing-define-type` | warning | Schema should use `defineType()` |
|
|
67
|
+
| `missing-define-field` | warning | Fields should use `defineField()` |
|
|
68
|
+
| `missing-icon` | warning | Document types should have an icon |
|
|
69
|
+
| `missing-title` | info | Types should have a title |
|
|
70
|
+
| `missing-description` | info | Types should have a description |
|
|
71
|
+
| `presentation-field-name` | warning | Avoid field names that clash with presentation |
|
|
72
|
+
|
|
73
|
+
### Field Rules
|
|
74
|
+
|
|
75
|
+
| Rule | Severity | Description |
|
|
76
|
+
| ----------------------------- | -------- | ------------------------------------------ |
|
|
77
|
+
| `boolean-instead-of-list` | info | Consider list instead of boolean |
|
|
78
|
+
| `missing-slug-source` | warning | Slug fields should have a source |
|
|
79
|
+
| `missing-required-validation` | info | Consider adding required validation |
|
|
80
|
+
| `reserved-field-name` | error | Field name conflicts with Sanity internals |
|
|
81
|
+
|
|
82
|
+
### Array & Reference Rules
|
|
83
|
+
|
|
84
|
+
| Rule | Severity | Description |
|
|
85
|
+
| --------------------------- | -------- | -------------------------------------------- |
|
|
86
|
+
| `array-missing-constraints` | warning | Arrays should have min/max constraints |
|
|
87
|
+
| `heading-level-in-schema` | info | Heading levels belong in content, not schema |
|
|
88
|
+
| `unnecessary-reference` | info | Reference could be simplified |
|
|
89
|
+
|
|
90
|
+
## API Reference
|
|
91
|
+
|
|
92
|
+
### `lint(schema: SchemaType, options?: LintOptions): LintResult`
|
|
93
|
+
|
|
94
|
+
Lint a single schema type definition.
|
|
95
|
+
|
|
96
|
+
```typescript
|
|
97
|
+
interface LintOptions {
|
|
98
|
+
config?: SchemaLinterConfig
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
interface LintResult {
|
|
102
|
+
schema: SchemaType
|
|
103
|
+
findings: Finding[]
|
|
104
|
+
}
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
### `lintSchemas(schemas: SchemaType[], options?: LintOptions): LintResult[]`
|
|
108
|
+
|
|
109
|
+
Lint multiple schema type definitions.
|
|
110
|
+
|
|
111
|
+
### Rules Array
|
|
112
|
+
|
|
113
|
+
```typescript
|
|
114
|
+
import { rules } from '@sanity/schema-lint'
|
|
115
|
+
|
|
116
|
+
// All 13 rules
|
|
117
|
+
console.log(rules.map((r) => r.id))
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
### Individual Rule Imports
|
|
121
|
+
|
|
122
|
+
```typescript
|
|
123
|
+
import { missingIcon, reservedFieldName } from '@sanity/schema-lint'
|
|
124
|
+
|
|
125
|
+
// Use individual rules
|
|
126
|
+
const customRules = [missingIcon, reservedFieldName]
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
## License
|
|
130
|
+
|
|
131
|
+
MIT
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
8
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
9
|
+
}) : x)(function(x) {
|
|
10
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
11
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
12
|
+
});
|
|
13
|
+
var __commonJS = (cb, mod) => function __require2() {
|
|
14
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
15
|
+
};
|
|
16
|
+
var __copyProps = (to, from, except, desc) => {
|
|
17
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
18
|
+
for (let key of __getOwnPropNames(from))
|
|
19
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
20
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
21
|
+
}
|
|
22
|
+
return to;
|
|
23
|
+
};
|
|
24
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
25
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
26
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
27
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
28
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
29
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
30
|
+
mod
|
|
31
|
+
));
|
|
32
|
+
|
|
33
|
+
export {
|
|
34
|
+
__require,
|
|
35
|
+
__commonJS,
|
|
36
|
+
__toESM
|
|
37
|
+
};
|
|
38
|
+
//# sourceMappingURL=chunk-7D4SUZUM.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { S as SchemaType, a as SchemaRule, b as SchemaLinterConfig } from './types-C3OVyCP6.js';
|
|
2
|
+
export { c as SchemaField, e as SchemaRuleConfig, d as SchemaRuleContext } from './types-C3OVyCP6.js';
|
|
3
|
+
import { Finding } from '@sanity/lint-core';
|
|
4
|
+
|
|
5
|
+
interface LintOptions {
|
|
6
|
+
/** Specific rules to run (if not provided, runs all) */
|
|
7
|
+
rules?: SchemaRule[];
|
|
8
|
+
/** Configuration for rules */
|
|
9
|
+
config?: SchemaLinterConfig;
|
|
10
|
+
/** File path for context */
|
|
11
|
+
filePath?: string;
|
|
12
|
+
}
|
|
13
|
+
interface LintResult {
|
|
14
|
+
/** The findings from all rules */
|
|
15
|
+
findings: Finding[];
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Lint a schema type definition
|
|
19
|
+
*
|
|
20
|
+
* @param schema - The schema to lint
|
|
21
|
+
* @param allRules - All available rules
|
|
22
|
+
* @param options - Lint options
|
|
23
|
+
* @returns Lint result with findings
|
|
24
|
+
*/
|
|
25
|
+
declare function lint(schema: SchemaType, allRules: SchemaRule[], options?: LintOptions): LintResult;
|
|
26
|
+
/**
|
|
27
|
+
* Lint multiple schema types
|
|
28
|
+
*/
|
|
29
|
+
declare function lintSchemas(schemas: SchemaType[], allRules: SchemaRule[], options?: LintOptions): LintResult;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Rule: missing-define-type
|
|
33
|
+
*
|
|
34
|
+
* Schema types should be wrapped with defineType() for proper type inference
|
|
35
|
+
* and Studio integration.
|
|
36
|
+
*/
|
|
37
|
+
declare const missingDefineType: SchemaRule;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Rule: missing-define-field
|
|
41
|
+
*
|
|
42
|
+
* Fields should be wrapped with defineField() for proper type inference.
|
|
43
|
+
*/
|
|
44
|
+
declare const missingDefineField: SchemaRule;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Rule: missing-icon
|
|
48
|
+
*
|
|
49
|
+
* Document and object types should have an icon for better Studio UX.
|
|
50
|
+
*/
|
|
51
|
+
declare const missingIcon: SchemaRule;
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Rule: missing-title
|
|
55
|
+
*
|
|
56
|
+
* Schema types should have a human-readable title.
|
|
57
|
+
*/
|
|
58
|
+
declare const missingTitle: SchemaRule;
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Rule: missing-description
|
|
62
|
+
*
|
|
63
|
+
* Fields should have descriptions to help content editors.
|
|
64
|
+
*/
|
|
65
|
+
declare const missingDescription: SchemaRule;
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Rule: presentation-field-name
|
|
69
|
+
*
|
|
70
|
+
* Field names should be semantic, not presentation-focused.
|
|
71
|
+
*/
|
|
72
|
+
declare const presentationFieldName: SchemaRule;
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Rule: boolean-instead-of-list
|
|
76
|
+
*
|
|
77
|
+
* Some boolean fields might be better represented as a string field
|
|
78
|
+
* with options.list for future expandability.
|
|
79
|
+
*/
|
|
80
|
+
declare const booleanInsteadOfList: SchemaRule;
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Rule: missing-slug-source
|
|
84
|
+
*
|
|
85
|
+
* Slug fields should have options.source for auto-generation.
|
|
86
|
+
*/
|
|
87
|
+
declare const missingSlugSource: SchemaRule;
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Rule: missing-required-validation
|
|
91
|
+
*
|
|
92
|
+
* Critical fields like title, name, and slug should have validation rules.
|
|
93
|
+
*/
|
|
94
|
+
declare const missingRequiredValidation: SchemaRule;
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Rule: reserved-field-name
|
|
98
|
+
*
|
|
99
|
+
* Field names starting with underscore are reserved by Sanity.
|
|
100
|
+
*/
|
|
101
|
+
declare const reservedFieldName: SchemaRule;
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Rule: array-missing-constraints
|
|
105
|
+
*
|
|
106
|
+
* Array fields should have constraints (min, max, unique) to prevent
|
|
107
|
+
* unbounded data and ensure data quality.
|
|
108
|
+
*/
|
|
109
|
+
declare const arrayMissingConstraints: SchemaRule;
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Rule: heading-level-in-schema
|
|
113
|
+
*
|
|
114
|
+
* Heading levels (h1, h2, etc.) should be computed dynamically in components,
|
|
115
|
+
* not stored in the schema.
|
|
116
|
+
*/
|
|
117
|
+
declare const headingLevelInSchema: SchemaRule;
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Rule: unnecessary-reference
|
|
121
|
+
*
|
|
122
|
+
* Warns about reference fields that might be better as embedded objects.
|
|
123
|
+
* References are great for shared content, but embedded objects are simpler
|
|
124
|
+
* for content that's specific to a single document type.
|
|
125
|
+
*/
|
|
126
|
+
declare const unnecessaryReference: SchemaRule;
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* All available schema lint rules (13 total)
|
|
130
|
+
*/
|
|
131
|
+
declare const rules: SchemaRule[];
|
|
132
|
+
|
|
133
|
+
export { type LintOptions, type LintResult, SchemaLinterConfig, SchemaRule, SchemaType, arrayMissingConstraints, booleanInsteadOfList, headingLevelInSchema, lint, lintSchemas, missingDefineField, missingDefineType, missingDescription, missingIcon, missingRequiredValidation, missingSlugSource, missingTitle, presentationFieldName, reservedFieldName, rules, unnecessaryReference };
|