@sanity/schema-lint 0.0.1 → 0.0.3
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/dist/index.cjs +640 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +133 -0
- package/dist/testing.cjs +18530 -0
- package/dist/testing.cjs.map +1 -0
- package/dist/testing.d.cts +81 -0
- package/dist/types-C3OVyCP6.d.cts +121 -0
- package/package.json +7 -5
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { S as SchemaType, a as SchemaRule } from './types-C3OVyCP6.cjs';
|
|
2
|
+
import '@sanity/lint-core';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* A valid test case - schema that should produce no findings
|
|
6
|
+
*/
|
|
7
|
+
interface ValidSchemaTestCase {
|
|
8
|
+
/** The schema to test */
|
|
9
|
+
schema: SchemaType;
|
|
10
|
+
/** Optional name for the test */
|
|
11
|
+
name?: string;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Expected error in an invalid test case
|
|
15
|
+
*/
|
|
16
|
+
interface ExpectedSchemaError {
|
|
17
|
+
/** Expected rule ID (defaults to the rule being tested) */
|
|
18
|
+
ruleId?: string;
|
|
19
|
+
/** Expected message (string for exact match, RegExp for pattern) */
|
|
20
|
+
message?: string | RegExp;
|
|
21
|
+
/** Expected severity */
|
|
22
|
+
severity?: 'error' | 'warning' | 'info';
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* An invalid test case - schema that should produce findings
|
|
26
|
+
*/
|
|
27
|
+
interface InvalidSchemaTestCase {
|
|
28
|
+
/** The schema to test */
|
|
29
|
+
schema: SchemaType;
|
|
30
|
+
/** Optional name for the test */
|
|
31
|
+
name?: string;
|
|
32
|
+
/** Expected errors */
|
|
33
|
+
errors: ExpectedSchemaError[];
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Test suite for a schema rule
|
|
37
|
+
*/
|
|
38
|
+
interface SchemaRuleTests {
|
|
39
|
+
/** Schemas that should produce no findings */
|
|
40
|
+
valid: (SchemaType | ValidSchemaTestCase)[];
|
|
41
|
+
/** Schemas that should produce findings */
|
|
42
|
+
invalid: InvalidSchemaTestCase[];
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Helper to create a minimal valid schema for testing
|
|
46
|
+
*/
|
|
47
|
+
declare function createSchema(overrides?: Partial<SchemaType>): SchemaType;
|
|
48
|
+
/**
|
|
49
|
+
* Test utility for schema lint rules, inspired by ESLint's RuleTester
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```typescript
|
|
53
|
+
* import { SchemaRuleTester, createSchema } from '@sanity/schema-lint/testing'
|
|
54
|
+
* import { missingIcon } from '../missing-icon'
|
|
55
|
+
*
|
|
56
|
+
* const tester = new SchemaRuleTester()
|
|
57
|
+
*
|
|
58
|
+
* tester.run('missing-icon', missingIcon, {
|
|
59
|
+
* valid: [
|
|
60
|
+
* createSchema({ hasIcon: true }),
|
|
61
|
+
* ],
|
|
62
|
+
* invalid: [
|
|
63
|
+
* {
|
|
64
|
+
* schema: createSchema({ hasIcon: false }),
|
|
65
|
+
* errors: [{ ruleId: 'missing-icon' }]
|
|
66
|
+
* }
|
|
67
|
+
* ]
|
|
68
|
+
* })
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
71
|
+
declare class SchemaRuleTester {
|
|
72
|
+
/**
|
|
73
|
+
* Run tests for a schema rule
|
|
74
|
+
* @param ruleName - Name for the test suite
|
|
75
|
+
* @param rule - The rule to test
|
|
76
|
+
* @param tests - Valid and invalid test cases
|
|
77
|
+
*/
|
|
78
|
+
run(ruleName: string, rule: SchemaRule, tests: SchemaRuleTests): void;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export { type ExpectedSchemaError, type InvalidSchemaTestCase, SchemaRuleTester, type SchemaRuleTests, type ValidSchemaTestCase, createSchema };
|
|
@@ -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
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sanity/schema-lint",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"description": "Schema linting engine and rules for Sanity Lint",
|
|
5
5
|
"author": "Sanity.io <hello@sanity.io>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -13,20 +13,22 @@
|
|
|
13
13
|
"exports": {
|
|
14
14
|
".": {
|
|
15
15
|
"types": "./dist/index.d.ts",
|
|
16
|
-
"import": "./dist/index.js"
|
|
16
|
+
"import": "./dist/index.js",
|
|
17
|
+
"require": "./dist/index.cjs"
|
|
17
18
|
},
|
|
18
19
|
"./testing": {
|
|
19
20
|
"types": "./dist/testing.d.ts",
|
|
20
|
-
"import": "./dist/testing.js"
|
|
21
|
+
"import": "./dist/testing.js",
|
|
22
|
+
"require": "./dist/testing.cjs"
|
|
21
23
|
}
|
|
22
24
|
},
|
|
23
|
-
"main": "./dist/index.
|
|
25
|
+
"main": "./dist/index.cjs",
|
|
24
26
|
"types": "./dist/index.d.ts",
|
|
25
27
|
"files": [
|
|
26
28
|
"dist"
|
|
27
29
|
],
|
|
28
30
|
"dependencies": {
|
|
29
|
-
"@sanity/lint-core": "0.0.
|
|
31
|
+
"@sanity/lint-core": "0.0.3"
|
|
30
32
|
},
|
|
31
33
|
"devDependencies": {
|
|
32
34
|
"tsup": "^8.3.5",
|