@geoql/doctor-rule-core 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,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Vinayak Kulkarni
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,53 @@
1
+ # @geoql/doctor-rule-core
2
+
3
+ Linter-neutral rule cores shared by:
4
+
5
+ - `@geoql/oxlint-plugin-vue-doctor`
6
+ - `@geoql/oxlint-plugin-nuxt-doctor`
7
+ - the future ESLint plugin (parity item #4)
8
+
9
+ ## What lives here
10
+
11
+ Pure detection logic for rules that operate on the **ESTree / JavaScript AST**:
12
+
13
+ - rule metadata (`id`, `category`, `severity`, `recommended`, `meta`)
14
+ - the visitor spec returned by `create(context)`
15
+ - the optional `fix(node) => string | null` transform
16
+ - shared helpers such as `defineRule` and the auto-imported symbol sets
17
+
18
+ ## What does NOT live here
19
+
20
+ Template-AST rules (e.g. `v-for-has-key`) operate on the `@vue/compiler-sfc`
21
+ template AST, which has a completely different node shape and traversal model.
22
+ They remain in `@geoql/doctor-core` alongside the hybrid engine that runs them.
23
+
24
+ ## Adapter contract
25
+
26
+ A linter adapter should consume each `CoreRule` and wire it into its own
27
+ linter API. The core shape is intentionally identical to the ESLint / oxlint
28
+ JS-plugin contract:
29
+
30
+ ```ts
31
+ export interface CoreRule {
32
+ readonly id: string;
33
+ readonly category: RuleCategory;
34
+ readonly severity: 'error' | 'warn' | 'info';
35
+ readonly recommended: boolean;
36
+ readonly meta?: RuleMeta;
37
+ readonly create: (context: RuleContext) => Record<string, RuleVisitor>;
38
+ readonly fix?: (node: AstNode) => string | null;
39
+ }
40
+ ```
41
+
42
+ For oxlint, the adapter is a thin identity wrapper because the shape already
43
+ matches oxlint's `Rule`. For ESLint, the adapter will map the same `create`
44
+ visitor object into ESLint's `context.report()` API.
45
+
46
+ ## Adding a new rule
47
+
48
+ 1. Add the rule file under `src/rules/vue/` or `src/rules/nuxt/`.
49
+ 2. Export it from the matching `src/rules/vue/index.ts` or
50
+ `src/rules/nuxt/index.ts`.
51
+ 3. Add the rule to `RULE_REGISTRY` in `@geoql/doctor-core`.
52
+ 4. Add the rule id to the matching allowlist in
53
+ `@geoql/doctor-core/src/oxlint/generate-config.ts`.
@@ -0,0 +1,158 @@
1
+ //#region src/types.d.ts
2
+ type Severity = 'error' | 'warn' | 'info';
3
+ type RuleCategory = 'ai-slop' | 'reactivity' | 'composition' | 'performance' | 'template' | 'template-perf' | 'build-quality' | 'deps' | 'dead-code' | 'sfc' | 'vue-builtin' | 'structure' | 'modules-deps' | 'nitro' | 'seo' | 'cloudflare' | 'server-routes' | 'hydration' | 'data-fetching' | 'security' | 'design';
4
+ interface SourceLocation {
5
+ start: {
6
+ line: number;
7
+ column: number;
8
+ };
9
+ end: {
10
+ line: number;
11
+ column: number;
12
+ };
13
+ }
14
+ interface AstNode {
15
+ type: string;
16
+ loc?: SourceLocation;
17
+ [key: string]: unknown;
18
+ }
19
+ interface Fix {
20
+ range: [number, number];
21
+ text: string;
22
+ node?: AstNode;
23
+ }
24
+ interface Fixer {
25
+ replaceText: (node: AstNode, text: string) => Fix;
26
+ }
27
+ type FixFn = (fixer: Fixer) => Fix;
28
+ interface ReportDescriptor {
29
+ node: AstNode;
30
+ message: string;
31
+ fix?: FixFn;
32
+ }
33
+ interface RuleContext {
34
+ report: (descriptor: ReportDescriptor) => void;
35
+ getFilename?: () => string | undefined;
36
+ settings?: Record<string, unknown>;
37
+ /** Capability tokens detected for the project (e.g. 'auto-imports:vue'). */
38
+ capabilities?: Set<string>;
39
+ }
40
+ type RuleVisitor = (node: AstNode) => void;
41
+ interface RuleMeta {
42
+ name?: string;
43
+ fixable?: 'code' | 'whitespace';
44
+ }
45
+ interface Rule {
46
+ meta?: RuleMeta;
47
+ create: (context: RuleContext) => Record<string, RuleVisitor>;
48
+ fix?: (node: AstNode) => string | null;
49
+ }
50
+ interface Plugin {
51
+ meta: {
52
+ name: string;
53
+ };
54
+ rules: Record<string, Rule>;
55
+ }
56
+ interface CoreRule {
57
+ readonly id: string;
58
+ readonly category: RuleCategory;
59
+ readonly severity: Severity;
60
+ readonly recommended: boolean;
61
+ readonly meta?: RuleMeta;
62
+ readonly create: (context: RuleContext) => Record<string, RuleVisitor>;
63
+ readonly fix?: (node: AstNode) => string | null;
64
+ }
65
+ //#endregion
66
+ //#region src/define-rule.d.ts
67
+ declare function defineRule(rule: Rule): Rule;
68
+ //#endregion
69
+ //#region src/shared/auto-imported-symbols.d.ts
70
+ declare const VUE_AUTO_IMPORTED: ReadonlySet<string>;
71
+ declare const NUXT_AUTO_IMPORTED: ReadonlySet<string>;
72
+ //#endregion
73
+ //#region src/rules/nuxt/index.d.ts
74
+ declare const NUXT_RULES: readonly CoreRule[];
75
+ //#endregion
76
+ //#region src/rules/vue/index.d.ts
77
+ declare const VUE_RULES: readonly CoreRule[];
78
+ //#endregion
79
+ //#region src/rules/nuxt/hydration/clientOnly-for-browser-apis.d.ts
80
+ declare const clientOnlyForBrowserApis: Rule;
81
+ //#endregion
82
+ //#region src/rules/nuxt/hydration/no-document-in-setup.d.ts
83
+ declare const noDocumentInSetup: Rule;
84
+ //#endregion
85
+ //#region src/rules/nuxt/server-routes/createError-on-failure.d.ts
86
+ declare const createErrorOnFailure: Rule;
87
+ //#endregion
88
+ //#region src/rules/nuxt/server-routes/defineEventHandler-typed.d.ts
89
+ declare const defineEventHandlerTyped: Rule;
90
+ //#endregion
91
+ //#region src/rules/nuxt/server-routes/validate-body-with-h3-v2.d.ts
92
+ declare const validateBodyWithH3V2: Rule;
93
+ //#endregion
94
+ //#region src/rules/nuxt/data-fetching/useAsyncData-key-required-in-loop.d.ts
95
+ declare const useAsyncDataKeyRequiredInLoop: Rule;
96
+ //#endregion
97
+ //#region src/rules/nuxt/ai-slop/no-explicit-imports-of-auto-imported.d.ts
98
+ declare const noExplicitImportsOfAutoImported: Rule;
99
+ //#endregion
100
+ //#region src/rules/nuxt/ai-slop/no-fetch-in-setup.d.ts
101
+ declare const noFetchInSetup: Rule;
102
+ //#endregion
103
+ //#region src/rules/nuxt/ai-slop/no-process-client-server.d.ts
104
+ declare const noProcessClientServer: Rule;
105
+ //#endregion
106
+ //#region src/rules/nuxt/ai-slop/no-useState-for-server-data.d.ts
107
+ declare const noUseStateForServerData: Rule;
108
+ //#endregion
109
+ //#region src/rules/vue/composition/defineProps-typed.d.ts
110
+ declare const definePropsTyped: Rule;
111
+ //#endregion
112
+ //#region src/rules/vue/composition/prefer-script-setup-for-new-files.d.ts
113
+ declare const preferScriptSetupForNewFiles: Rule;
114
+ //#endregion
115
+ //#region src/rules/vue/performance/prefer-defineAsyncComponent-on-route.d.ts
116
+ declare const preferDefineAsyncComponentOnRoute: Rule;
117
+ //#endregion
118
+ //#region src/rules/vue/reactivity/prefer-readonly-for-injected.d.ts
119
+ declare const preferReadonlyForInjected: Rule;
120
+ //#endregion
121
+ //#region src/rules/vue/reactivity/prefer-shallowRef-for-large-data.d.ts
122
+ declare const preferShallowRefForLargeData: Rule;
123
+ //#endregion
124
+ //#region src/rules/vue/reactivity/watch-without-cleanup.d.ts
125
+ declare const watchWithoutCleanup: Rule;
126
+ //#endregion
127
+ //#region src/rules/vue/ai-slop/no-destructure-props-without-toRefs.d.ts
128
+ declare const noDestructurePropsWithoutToRefs: Rule;
129
+ //#endregion
130
+ //#region src/rules/vue/ai-slop/no-destructure-reactive-without-toRefs.d.ts
131
+ declare const noDestructureReactiveWithoutToRefs: Rule;
132
+ //#endregion
133
+ //#region src/rules/vue/ai-slop/no-em-dash-in-string.d.ts
134
+ declare const noEmDashInString: Rule;
135
+ //#endregion
136
+ //#region src/rules/vue/ai-slop/no-imports-from-vue-when-auto-imported.d.ts
137
+ declare const noImportsFromVueWhenAutoImported: Rule;
138
+ //#endregion
139
+ //#region src/rules/vue/ai-slop/no-non-null-assertion-on-ref-value.d.ts
140
+ declare const noNonNullAssertionOnRefValue: Rule;
141
+ //#endregion
142
+ //#region src/rules/vue/security/no-auth-token-in-web-storage.d.ts
143
+ declare const noAuthTokenInWebStorage: Rule;
144
+ //#endregion
145
+ //#region src/rules/vue/security/no-eval-like.d.ts
146
+ declare const noEvalLike: Rule;
147
+ //#endregion
148
+ //#region src/rules/vue/security/no-inner-html.d.ts
149
+ declare const noInnerHtml: Rule;
150
+ //#endregion
151
+ //#region src/rules/vue/security/no-secrets-in-source.d.ts
152
+ declare const noSecretsInSource: Rule;
153
+ //#endregion
154
+ //#region src/rules/nuxt/security/no-user-input-in-fetch-url.d.ts
155
+ declare const noUserInputInFetchUrl: Rule;
156
+ //#endregion
157
+ export { type AstNode, type CoreRule, type Fix, type FixFn, type Fixer, NUXT_AUTO_IMPORTED, NUXT_RULES, type Plugin, type ReportDescriptor, type Rule, type RuleCategory, type RuleContext, type RuleMeta, type RuleVisitor, type Severity, type SourceLocation, VUE_AUTO_IMPORTED, VUE_RULES, clientOnlyForBrowserApis, createErrorOnFailure, defineEventHandlerTyped, definePropsTyped, defineRule, noAuthTokenInWebStorage, noDestructurePropsWithoutToRefs, noDestructureReactiveWithoutToRefs, noDocumentInSetup, noEmDashInString, noEvalLike, noExplicitImportsOfAutoImported, noFetchInSetup, noImportsFromVueWhenAutoImported, noInnerHtml, noNonNullAssertionOnRefValue, noProcessClientServer, noSecretsInSource, noUseStateForServerData, noUserInputInFetchUrl, preferDefineAsyncComponentOnRoute, preferReadonlyForInjected, preferScriptSetupForNewFiles, preferShallowRefForLargeData, useAsyncDataKeyRequiredInLoop, validateBodyWithH3V2, watchWithoutCleanup };
158
+ //# sourceMappingURL=index.d.ts.map