@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
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { SourceSpan, Severity, Category, Finding } from '@sanity/lint-core';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Represents a field in a Sanity schema
|
|
5
|
+
*/
|
|
6
|
+
interface SchemaField {
|
|
7
|
+
/** Field name */
|
|
8
|
+
name: string;
|
|
9
|
+
/** Field type (string, number, reference, array, etc.) */
|
|
10
|
+
type: string;
|
|
11
|
+
/** Human-readable title */
|
|
12
|
+
title?: string;
|
|
13
|
+
/** Field description */
|
|
14
|
+
description?: string;
|
|
15
|
+
/** Whether the field has validation rules */
|
|
16
|
+
hasValidation?: boolean;
|
|
17
|
+
/** Whether the field is deprecated */
|
|
18
|
+
deprecated?: boolean | string;
|
|
19
|
+
/** Whether the field is hidden */
|
|
20
|
+
hidden?: boolean;
|
|
21
|
+
/** Whether the field is readOnly */
|
|
22
|
+
readOnly?: boolean;
|
|
23
|
+
/** Field options (e.g., source for slug, list for string) */
|
|
24
|
+
options?: {
|
|
25
|
+
source?: string;
|
|
26
|
+
list?: unknown[];
|
|
27
|
+
hotspot?: boolean;
|
|
28
|
+
layout?: string;
|
|
29
|
+
[key: string]: unknown;
|
|
30
|
+
};
|
|
31
|
+
/** For array fields, the types allowed in the array */
|
|
32
|
+
of?: SchemaField[];
|
|
33
|
+
/** For reference fields, the types that can be referenced */
|
|
34
|
+
to?: {
|
|
35
|
+
type: string;
|
|
36
|
+
}[];
|
|
37
|
+
/** Location in source for error reporting */
|
|
38
|
+
span?: SourceSpan;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Represents a Sanity schema type definition
|
|
42
|
+
*/
|
|
43
|
+
interface SchemaType {
|
|
44
|
+
/** Type name (e.g., 'post', 'author') */
|
|
45
|
+
name: string;
|
|
46
|
+
/** Schema type (document, object, array, etc.) */
|
|
47
|
+
type: string;
|
|
48
|
+
/** Human-readable title */
|
|
49
|
+
title?: string;
|
|
50
|
+
/** Type description */
|
|
51
|
+
description?: string;
|
|
52
|
+
/** Whether the type has an icon defined */
|
|
53
|
+
hasIcon?: boolean;
|
|
54
|
+
/** Whether the type has a preview configuration */
|
|
55
|
+
hasPreview?: boolean;
|
|
56
|
+
/** Fields defined on this type */
|
|
57
|
+
fields?: SchemaField[];
|
|
58
|
+
/** Groups for organizing fields in the Studio */
|
|
59
|
+
groups?: {
|
|
60
|
+
name: string;
|
|
61
|
+
title?: string;
|
|
62
|
+
}[];
|
|
63
|
+
/** Location in source for error reporting */
|
|
64
|
+
span?: SourceSpan;
|
|
65
|
+
/** Whether defineType() was used */
|
|
66
|
+
usesDefineType?: boolean;
|
|
67
|
+
/** Whether defineField() was used for all fields */
|
|
68
|
+
usesDefineField?: boolean;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Context provided to schema rules during checking
|
|
72
|
+
*/
|
|
73
|
+
interface SchemaRuleContext {
|
|
74
|
+
/** The file path being linted */
|
|
75
|
+
filePath: string;
|
|
76
|
+
/** Report a finding */
|
|
77
|
+
report: (finding: Omit<Finding, 'ruleId'>) => void;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* A schema lint rule definition
|
|
81
|
+
*/
|
|
82
|
+
interface SchemaRule {
|
|
83
|
+
/** Unique identifier (kebab-case) */
|
|
84
|
+
id: string;
|
|
85
|
+
/** Human-readable name */
|
|
86
|
+
name: string;
|
|
87
|
+
/** Description of what the rule checks */
|
|
88
|
+
description: string;
|
|
89
|
+
/** Default severity */
|
|
90
|
+
severity: Severity;
|
|
91
|
+
/** Rule category */
|
|
92
|
+
category: Category;
|
|
93
|
+
/** Rule IDs that this rule supersedes */
|
|
94
|
+
supersedes?: string[];
|
|
95
|
+
/**
|
|
96
|
+
* Check the schema for violations
|
|
97
|
+
* @param schema - The parsed schema type
|
|
98
|
+
* @param context - Context with file info and report function
|
|
99
|
+
*/
|
|
100
|
+
check: (schema: SchemaType, context: SchemaRuleContext) => void;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Configuration for a schema rule
|
|
104
|
+
*/
|
|
105
|
+
interface SchemaRuleConfig {
|
|
106
|
+
/** Whether the rule is enabled */
|
|
107
|
+
enabled?: boolean;
|
|
108
|
+
/** Override severity */
|
|
109
|
+
severity?: Severity;
|
|
110
|
+
/** Rule-specific options */
|
|
111
|
+
options?: Record<string, unknown>;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Schema linter configuration
|
|
115
|
+
*/
|
|
116
|
+
interface SchemaLinterConfig {
|
|
117
|
+
/** Rule configurations keyed by rule ID */
|
|
118
|
+
rules?: Record<string, SchemaRuleConfig | boolean>;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export type { SchemaType as S, SchemaRule as a, SchemaLinterConfig as b, SchemaField as c, SchemaRuleContext as d, SchemaRuleConfig as e };
|
package/package.json
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@sanity/schema-lint",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Schema linting engine and rules for Sanity Lint",
|
|
5
|
+
"author": "Sanity.io <hello@sanity.io>",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/sanity-io/sanity-lint.git",
|
|
10
|
+
"directory": "packages/schema-lint"
|
|
11
|
+
},
|
|
12
|
+
"type": "module",
|
|
13
|
+
"exports": {
|
|
14
|
+
".": {
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"import": "./dist/index.js"
|
|
17
|
+
},
|
|
18
|
+
"./testing": {
|
|
19
|
+
"types": "./dist/testing.d.ts",
|
|
20
|
+
"import": "./dist/testing.js"
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
"main": "./dist/index.js",
|
|
24
|
+
"types": "./dist/index.d.ts",
|
|
25
|
+
"files": [
|
|
26
|
+
"dist"
|
|
27
|
+
],
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"@sanity/lint-core": "0.0.1"
|
|
30
|
+
},
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"tsup": "^8.3.5",
|
|
33
|
+
"typescript": "^5.7.2",
|
|
34
|
+
"vitest": "^2.1.8"
|
|
35
|
+
},
|
|
36
|
+
"keywords": [
|
|
37
|
+
"sanity",
|
|
38
|
+
"schema",
|
|
39
|
+
"lint",
|
|
40
|
+
"linter"
|
|
41
|
+
],
|
|
42
|
+
"publishConfig": {
|
|
43
|
+
"access": "public"
|
|
44
|
+
},
|
|
45
|
+
"scripts": {
|
|
46
|
+
"build": "tsup",
|
|
47
|
+
"dev": "tsup --watch",
|
|
48
|
+
"typecheck": "tsc --noEmit",
|
|
49
|
+
"clean": "rm -rf dist"
|
|
50
|
+
}
|
|
51
|
+
}
|