@sanity/groq-lint 0.0.1 → 0.0.2
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/cli.js +1026 -6
- package/dist/cli.js.map +1 -1
- package/dist/{chunk-5C74HJYX.js → index.cjs} +86 -32
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +103 -0
- package/dist/index.js +1023 -9
- package/dist/index.js.map +1 -1
- package/dist/schema.cjs +87 -0
- package/dist/schema.cjs.map +1 -0
- package/dist/schema.d.cts +61 -0
- package/package.json +7 -5
- package/dist/chunk-5C74HJYX.js.map +0 -1
- package/dist/cli.d.ts +0 -1
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { SchemaType } from 'groq-js';
|
|
2
|
+
import { LinterConfig, Finding, Rule } from '@sanity/lint-core';
|
|
3
|
+
export { Category, Finding, LinterConfig, Rule, RuleConfig, SchemaType, Severity, Suggestion, formatFindings, formatFindingsJson, summarizeFindings } from '@sanity/lint-core';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Result of linting a query
|
|
7
|
+
*/
|
|
8
|
+
interface LintResult {
|
|
9
|
+
/** The query that was linted */
|
|
10
|
+
query: string;
|
|
11
|
+
/** Findings from the lint rules */
|
|
12
|
+
findings: Finding[];
|
|
13
|
+
/** Whether parsing failed */
|
|
14
|
+
parseError?: string;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Options for linting
|
|
18
|
+
*/
|
|
19
|
+
interface LintOptions {
|
|
20
|
+
/** Linter configuration */
|
|
21
|
+
config?: LinterConfig;
|
|
22
|
+
/** Schema for schema-aware rules */
|
|
23
|
+
schema?: SchemaType;
|
|
24
|
+
/** Force use of TypeScript rules even when WASM is available */
|
|
25
|
+
forceTs?: boolean;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Initialize the WASM linter for better performance
|
|
29
|
+
*
|
|
30
|
+
* Call this once at application startup. The linter will automatically
|
|
31
|
+
* fall back to TypeScript rules if WASM is not available.
|
|
32
|
+
*
|
|
33
|
+
* @returns Promise that resolves to true if WASM is available
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```typescript
|
|
37
|
+
* import { initLinter, lint } from '@sanity/groq-lint'
|
|
38
|
+
*
|
|
39
|
+
* // Optional: Initialize WASM for better performance
|
|
40
|
+
* await initLinter()
|
|
41
|
+
*
|
|
42
|
+
* // Now lint() will use WASM for pure GROQ rules
|
|
43
|
+
* const result = lint('*[_type == "post"]{ author-> }')
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
declare function initLinter(): Promise<boolean>;
|
|
47
|
+
/**
|
|
48
|
+
* Lint a GROQ query
|
|
49
|
+
*
|
|
50
|
+
* Uses WASM for pure GROQ rules (if available) and TypeScript for schema-aware rules.
|
|
51
|
+
* Call `initLinter()` first to enable WASM support.
|
|
52
|
+
*
|
|
53
|
+
* @param query - The GROQ query string to lint
|
|
54
|
+
* @param options - Optional configuration and schema
|
|
55
|
+
* @returns Lint result with findings
|
|
56
|
+
*/
|
|
57
|
+
declare function lint(query: string, options?: LintOptions): LintResult;
|
|
58
|
+
/**
|
|
59
|
+
* Lint multiple queries
|
|
60
|
+
*
|
|
61
|
+
* @param queries - Array of queries to lint
|
|
62
|
+
* @param options - Optional configuration and schema
|
|
63
|
+
* @returns Array of lint results
|
|
64
|
+
*/
|
|
65
|
+
declare function lintMany(queries: string[], options?: LintOptions): LintResult[];
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* WASM-based linter for pure GROQ rules
|
|
69
|
+
*
|
|
70
|
+
* Uses @sanity/groq-wasm for high-performance linting of GROQ queries.
|
|
71
|
+
* Falls back gracefully if WASM is not available.
|
|
72
|
+
*/
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Rules available in the WASM linter (from Rust groq-lint)
|
|
76
|
+
*/
|
|
77
|
+
declare const WASM_RULES: Set<string>;
|
|
78
|
+
/**
|
|
79
|
+
* Check if WASM linter is available
|
|
80
|
+
*/
|
|
81
|
+
declare function isWasmAvailable(): boolean;
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Rule: join-in-filter
|
|
85
|
+
*
|
|
86
|
+
* Detects dereference operators (->) inside filter constraints.
|
|
87
|
+
* This is a performance anti-pattern because it prevents query optimization.
|
|
88
|
+
*
|
|
89
|
+
* Bad: *[author->name == "Bob"]
|
|
90
|
+
* Good: *[_type == "post" && author._ref == $authorId]
|
|
91
|
+
*/
|
|
92
|
+
declare const joinInFilter: Rule;
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* All available lint rules
|
|
96
|
+
*/
|
|
97
|
+
declare const rules: Rule[];
|
|
98
|
+
/**
|
|
99
|
+
* Rules indexed by ID for quick lookup
|
|
100
|
+
*/
|
|
101
|
+
declare const rulesById: Record<string, Rule>;
|
|
102
|
+
|
|
103
|
+
export { type LintOptions, type LintResult, WASM_RULES, initLinter, isWasmAvailable, joinInFilter, lint, lintMany, rules, rulesById };
|