@prisma-next/eslint-plugin 0.3.0-dev.4 → 0.3.0-dev.40

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.
@@ -0,0 +1,26 @@
1
+ import { ESLintUtils } from "@typescript-eslint/utils";
2
+
3
+ //#region src/rules/lint-build-call.d.ts
4
+ type MessageIds = 'unboundedQuery' | 'maxLimitExceeded';
5
+ interface RuleOptions {
6
+ /** Enforce limit() calls on SELECT queries to prevent unbounded queries */
7
+ requireLimit?: boolean;
8
+ /** Maximum allowed limit value */
9
+ maxLimit?: number;
10
+ }
11
+ type Options = [RuleOptions];
12
+ declare const lintBuildCall: ESLintUtils.RuleModule<MessageIds, Options, unknown, ESLintUtils.RuleListener>;
13
+ //#endregion
14
+ //#region src/index.d.ts
15
+ interface ESLintPlugin {
16
+ meta: {
17
+ name: string;
18
+ version: string;
19
+ };
20
+ rules: Record<string, any>;
21
+ configs: Record<string, any>;
22
+ }
23
+ declare const plugin: ESLintPlugin;
24
+ //#endregion
25
+ export { type ESLintPlugin, plugin as default, plugin, lintBuildCall };
26
+ //# sourceMappingURL=index.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../src/rules/lint-build-call.ts","../src/index.ts"],"sourcesContent":[],"mappings":";;;KAkBK,UAAA;UAEK,WAAA;EAFL;EAEK,YAAA,CAAA,EAAW,OAAA;EAOhB;EAGQ,QAAA,CAAA,EAAA,MAsGX;;KAzGG,OAAA,GAGqB,CAHV,WAGU,CAAA;AAAA,cAAb,aAAa,EAAA,WAAA,CAAA,UAAA,CAAA,UAAA,EAAA,OAAA,EAAA,OAAA,EAAA,WAAA,CAAA,YAAA,CAAA;;;UCVhB,YAAA;;IDFL,IAAA,EAAA,MAAU;IAEL,OAAA,EAAA,MAAW;EAOhB,CAAA;EAGQ,KAAA,ECJJ,MDII,CAAA,MAsGX,EAAA,GAAA,CAAA;EAtGwB,OAAA,ECFf,MDEe,CAAA,MAAA,EAAA,GAAA,CAAA;;cCEpB,MDFoB,ECEZ,YDFY"}
package/dist/index.mjs ADDED
@@ -0,0 +1,199 @@
1
+ import { ESLintUtils } from "@typescript-eslint/utils";
2
+
3
+ //#region package.json
4
+ var name = "@prisma-next/eslint-plugin";
5
+ var version = "0.3.0-dev.40";
6
+
7
+ //#endregion
8
+ //#region src/utils.ts
9
+ const PRISMA_NEXT_SQL_PACKAGES = ["@prisma-next/sql-lane", "packages/2-sql/4-lanes/sql-lane"];
10
+ const PLAN_TYPE_PATTERNS = [/^SqlQueryPlan$/];
11
+ /**
12
+ * Get TypeScript services from ESLint context
13
+ */
14
+ function getTypeScriptServices(context) {
15
+ try {
16
+ const parserServices = ESLintUtils.getParserServices(context, false);
17
+ if (!parserServices?.program) return null;
18
+ return {
19
+ program: parserServices.program,
20
+ checker: parserServices.program.getTypeChecker(),
21
+ esTreeNodeToTSNodeMap: parserServices.esTreeNodeToTSNodeMap,
22
+ tsNodeToESTreeNodeMap: parserServices.tsNodeToESTreeNodeMap
23
+ };
24
+ } catch {
25
+ return null;
26
+ }
27
+ }
28
+ /**
29
+ * Check if a call expression is a method call with a specific name
30
+ */
31
+ function isMethodCall(node, methodName) {
32
+ return node.callee.type === "MemberExpression" && node.callee.property.type === "Identifier" && node.callee.property.name === methodName;
33
+ }
34
+ /**
35
+ * Check if a call expression is a query builder build() call
36
+ * Uses type information to verify it's actually our query builder's build method
37
+ */
38
+ function isPrismaNextQueryBuildCall(node, services) {
39
+ if (!isMethodCall(node, "build") || node.arguments.length > 1 || !services) return false;
40
+ if (node.callee.type !== "MemberExpression") return false;
41
+ const objectType = getTypeOfNode(node.callee.object, services);
42
+ if (!objectType) return false;
43
+ if (!isTypeFromPackages(objectType, PRISMA_NEXT_SQL_PACKAGES)) return false;
44
+ const returnType = getTypeOfNode(node, services);
45
+ return returnType ? isPrismaNextQueryPlanType(returnType) : false;
46
+ }
47
+ /**
48
+ * Get the TypeScript type of an ESTree node
49
+ */
50
+ function getTypeOfNode(node, services) {
51
+ try {
52
+ const tsNode = services.esTreeNodeToTSNodeMap.get(node);
53
+ return tsNode ? services.checker.getTypeAtLocation(tsNode) : null;
54
+ } catch {
55
+ return null;
56
+ }
57
+ }
58
+ /**
59
+ * Check if type is a Prisma Next query plan type by name and origin
60
+ */
61
+ function isPrismaNextQueryPlanType(type) {
62
+ return PLAN_TYPE_PATTERNS.some((pattern) => pattern.test(type.symbol.name));
63
+ }
64
+ /**
65
+ * Extract call chain from a call expression
66
+ * Returns array of method names called in sequence
67
+ */
68
+ function extractCallChain(node) {
69
+ const chain = [];
70
+ function traverse(current) {
71
+ switch (current.type) {
72
+ case "CallExpression":
73
+ if (current.callee.type === "MemberExpression") {
74
+ traverse(current.callee.object);
75
+ if (current.callee.property.type === "Identifier") chain.push({
76
+ method: current.callee.property.name,
77
+ args: current.arguments
78
+ });
79
+ }
80
+ break;
81
+ case "MemberExpression":
82
+ traverse(current.object);
83
+ break;
84
+ case "Identifier": break;
85
+ }
86
+ }
87
+ traverse(node);
88
+ return chain;
89
+ }
90
+ /**
91
+ * Helper to check if a type originates from specific packages
92
+ */
93
+ function isTypeFromPackages(type, packages) {
94
+ const fileName = type.getSymbol()?.valueDeclaration?.getSourceFile().fileName;
95
+ return fileName ? packages.some((pkg) => fileName.includes(`${pkg}/`)) : false;
96
+ }
97
+
98
+ //#endregion
99
+ //#region src/rules/lint-build-call.ts
100
+ const DEFAULT_OPTIONS = {
101
+ requireLimit: true,
102
+ maxLimit: 1e3,
103
+ requiredFields: []
104
+ };
105
+ const SELECT_QUERY_METHODS = ["select", "from"];
106
+ const lintBuildCall = ESLintUtils.RuleCreator.withoutDocs({
107
+ meta: {
108
+ type: "problem",
109
+ docs: { description: "Validate query builder build() calls using TypeScript type information" },
110
+ schema: [{
111
+ type: "object",
112
+ properties: {
113
+ requireLimit: {
114
+ type: "boolean",
115
+ description: "Enforce limit() calls on SELECT queries"
116
+ },
117
+ maxLimit: {
118
+ type: "number",
119
+ description: "Maximum allowed limit value",
120
+ minimum: 1
121
+ }
122
+ },
123
+ additionalProperties: false
124
+ }],
125
+ messages: {
126
+ unboundedQuery: "Query build() call may result in unbounded query. Consider adding .limit() to prevent fetching too many rows.",
127
+ maxLimitExceeded: "Query build() call has a limit() value that exceeds the maximum allowed of {{maxLimit}}."
128
+ }
129
+ },
130
+ defaultOptions: [DEFAULT_OPTIONS],
131
+ create(context, [options]) {
132
+ const services = getTypeScriptServices(context);
133
+ if (!services) throw new Error("TypeScript services are required for lint-build-call rule. Please ensure you are using @typescript-eslint/parser.");
134
+ return { CallExpression(node) {
135
+ if (!isPrismaNextQueryBuildCall(node, services)) return;
136
+ lintQuery(node, extractCallChain(node));
137
+ } };
138
+ function lintQuery(node, callChain) {
139
+ if (isSelectQuery(callChain)) {
140
+ checkUnboundedQuery(node, callChain);
141
+ checkLimitExceedsMax(node, callChain);
142
+ }
143
+ }
144
+ function isSelectQuery(callChain) {
145
+ return SELECT_QUERY_METHODS.some((method) => callChain.some((call) => call.method === method));
146
+ }
147
+ function checkUnboundedQuery(node, callChain) {
148
+ if (options.requireLimit && !callChain.some((call) => call.method === "limit")) reportUnboundedQuery(node);
149
+ }
150
+ function checkLimitExceedsMax(node, callChain) {
151
+ if (!options.maxLimit) return;
152
+ const limitArg = callChain.find((call) => call.method === "limit")?.args.pop();
153
+ const literalValue = limitArg ? extractNumericLiteral(limitArg) : void 0;
154
+ if (literalValue !== void 0 && literalValue > options.maxLimit) reportLimitExceeded(node);
155
+ }
156
+ function extractNumericLiteral(arg) {
157
+ if (arg?.type === "Literal" && "value" in arg && typeof arg.value === "number") return arg.value;
158
+ }
159
+ function reportUnboundedQuery(node) {
160
+ context.report({
161
+ node,
162
+ messageId: "unboundedQuery"
163
+ });
164
+ }
165
+ function reportLimitExceeded(node) {
166
+ context.report({
167
+ node,
168
+ messageId: "maxLimitExceeded",
169
+ data: { maxLimit: options.maxLimit?.toString() ?? "undefined" }
170
+ });
171
+ }
172
+ }
173
+ });
174
+
175
+ //#endregion
176
+ //#region src/index.ts
177
+ const PLUGIN_META = {
178
+ name,
179
+ version
180
+ };
181
+ const RULES = { "lint-build-call": lintBuildCall };
182
+ const RULE_CONFIG = { "@prisma-next/lint-build-call": "error" };
183
+ const plugin = {
184
+ meta: PLUGIN_META,
185
+ rules: RULES,
186
+ configs: { recommended: {
187
+ plugins: ["@prisma-next"],
188
+ rules: RULE_CONFIG
189
+ } }
190
+ };
191
+ plugin.configs["flat/recommended"] = {
192
+ plugins: { "@prisma-next": plugin },
193
+ rules: RULE_CONFIG
194
+ };
195
+ var src_default = plugin;
196
+
197
+ //#endregion
198
+ export { src_default as default, lintBuildCall, plugin };
199
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","names":["chain: BuilderCall[]","plugin: ESLintPlugin"],"sources":["../package.json","../src/utils.ts","../src/rules/lint-build-call.ts","../src/index.ts"],"sourcesContent":["","import type { TSESTree } from '@typescript-eslint/types';\nimport type { ParserServices } from '@typescript-eslint/utils';\nimport { ESLintUtils } from '@typescript-eslint/utils';\nimport type * as ts from 'typescript';\n\nconst PRISMA_NEXT_SQL_PACKAGES = [\n '@prisma-next/sql-lane',\n 'packages/2-sql/4-lanes/sql-lane',\n] as const;\n\nconst PLAN_TYPE_PATTERNS = [/^SqlQueryPlan$/] as const;\n\nexport type BuilderCall = { method: string; args: TSESTree.CallExpressionArgument[] };\n\n// Types\nexport interface TypeScriptServices {\n program: ts.Program;\n checker: ts.TypeChecker;\n esTreeNodeToTSNodeMap: ParserServices['esTreeNodeToTSNodeMap'];\n tsNodeToESTreeNodeMap: ParserServices['tsNodeToESTreeNodeMap'];\n}\n\n/**\n * Get TypeScript services from ESLint context\n */\nexport function getTypeScriptServices(\n context: Parameters<typeof ESLintUtils.getParserServices>[0],\n): TypeScriptServices | null {\n try {\n const parserServices = ESLintUtils.getParserServices(context, false);\n\n if (!parserServices?.program) {\n return null;\n }\n\n return {\n program: parserServices.program,\n checker: parserServices.program.getTypeChecker(),\n esTreeNodeToTSNodeMap: parserServices.esTreeNodeToTSNodeMap,\n tsNodeToESTreeNodeMap: parserServices.tsNodeToESTreeNodeMap,\n };\n } catch {\n return null;\n }\n}\n\n/**\n * Check if a call expression is a method call with a specific name\n */\nexport function isMethodCall(node: TSESTree.CallExpression, methodName: string): boolean {\n return (\n node.callee.type === 'MemberExpression' &&\n node.callee.property.type === 'Identifier' &&\n node.callee.property.name === methodName\n );\n}\n\n/**\n * Check if a call expression is a query builder build() call\n * Uses type information to verify it's actually our query builder's build method\n */\nexport function isPrismaNextQueryBuildCall(\n node: TSESTree.CallExpression,\n services?: TypeScriptServices | null,\n): boolean {\n if (!isMethodCall(node, 'build') || node.arguments.length > 1 || !services) {\n return false;\n }\n\n if (node.callee.type !== 'MemberExpression') {\n return false;\n }\n\n const objectType = getTypeOfNode(node.callee.object, services);\n if (!objectType) {\n return false;\n }\n\n if (!isTypeFromPackages(objectType, PRISMA_NEXT_SQL_PACKAGES)) {\n return false;\n }\n\n const returnType = getTypeOfNode(node, services);\n return returnType ? isPrismaNextQueryPlanType(returnType) : false;\n}\n\n/**\n * Get the TypeScript type of an ESTree node\n */\nexport function getTypeOfNode(node: TSESTree.Node, services: TypeScriptServices): ts.Type | null {\n try {\n const tsNode = services.esTreeNodeToTSNodeMap.get(node);\n return tsNode ? services.checker.getTypeAtLocation(tsNode) : null;\n } catch {\n return null;\n }\n}\n\n/**\n * Check if a type has a specific property\n */\nexport function typeHasProperty(\n type: ts.Type,\n propertyName: string,\n checker: ts.TypeChecker,\n): boolean {\n try {\n const properties = checker.getPropertiesOfType(type);\n return properties.some((prop) => prop.getName() === propertyName);\n } catch {\n return false;\n }\n}\n\n/**\n * Check if type is a Prisma Next query plan type by name and origin\n */\nexport function isPrismaNextQueryPlanType(type: ts.Type): boolean {\n return PLAN_TYPE_PATTERNS.some((pattern) => pattern.test(type.symbol.name));\n}\n\n/**\n * Extract call chain from a call expression\n * Returns array of method names called in sequence\n */\nexport function extractCallChain(node: TSESTree.CallExpression): BuilderCall[] {\n const chain: BuilderCall[] = [];\n\n function traverse(current: TSESTree.Node): void {\n switch (current.type) {\n case 'CallExpression':\n if (current.callee.type === 'MemberExpression') {\n traverse(current.callee.object);\n if (current.callee.property.type === 'Identifier') {\n chain.push({ method: current.callee.property.name, args: current.arguments });\n }\n }\n break;\n\n case 'MemberExpression':\n traverse(current.object);\n break;\n\n case 'Identifier':\n break;\n }\n }\n\n traverse(node);\n return chain;\n}\n\n/**\n * Helper to check if a type originates from specific packages\n */\nfunction isTypeFromPackages(type: ts.Type, packages: readonly string[]): boolean {\n const fileName = type.getSymbol()?.valueDeclaration?.getSourceFile().fileName;\n return fileName ? packages.some((pkg) => fileName.includes(`${pkg}/`)) : false;\n}\n","import type { TSESTree } from '@typescript-eslint/types';\nimport { ESLintUtils } from '@typescript-eslint/utils';\nimport {\n type BuilderCall,\n extractCallChain,\n getTypeScriptServices,\n isPrismaNextQueryBuildCall,\n} from '../utils';\n\nconst DEFAULT_OPTIONS = {\n requireLimit: true,\n maxLimit: 1000,\n requiredFields: [],\n};\n\nconst SELECT_QUERY_METHODS = ['select', 'from'] as const;\n\n// Types\ntype MessageIds = 'unboundedQuery' | 'maxLimitExceeded';\n\ninterface RuleOptions {\n /** Enforce limit() calls on SELECT queries to prevent unbounded queries */\n requireLimit?: boolean;\n /** Maximum allowed limit value */\n maxLimit?: number;\n}\n\ntype Options = [RuleOptions];\n\n// Rule implementation\nexport const lintBuildCall = ESLintUtils.RuleCreator.withoutDocs<Options, MessageIds>({\n meta: {\n type: 'problem',\n docs: {\n description: 'Validate query builder build() calls using TypeScript type information',\n },\n schema: [\n {\n type: 'object',\n properties: {\n requireLimit: {\n type: 'boolean',\n description: 'Enforce limit() calls on SELECT queries',\n },\n maxLimit: {\n type: 'number',\n description: 'Maximum allowed limit value',\n minimum: 1,\n },\n },\n additionalProperties: false,\n },\n ],\n messages: {\n unboundedQuery:\n 'Query build() call may result in unbounded query. Consider adding .limit() to prevent fetching too many rows.',\n maxLimitExceeded:\n 'Query build() call has a limit() value that exceeds the maximum allowed of {{maxLimit}}.',\n },\n },\n defaultOptions: [DEFAULT_OPTIONS],\n create(context, [options]) {\n const services = getTypeScriptServices(context);\n\n if (!services) {\n throw new Error(\n 'TypeScript services are required for lint-build-call rule. Please ensure you are using @typescript-eslint/parser.',\n );\n }\n\n return {\n CallExpression(node: TSESTree.CallExpression) {\n if (!isPrismaNextQueryBuildCall(node, services)) {\n return;\n }\n lintQuery(node, extractCallChain(node));\n },\n };\n\n function lintQuery(node: TSESTree.CallExpression, callChain: BuilderCall[]) {\n if (isSelectQuery(callChain)) {\n checkUnboundedQuery(node, callChain);\n checkLimitExceedsMax(node, callChain);\n }\n }\n\n function isSelectQuery(callChain: BuilderCall[]): boolean {\n return SELECT_QUERY_METHODS.some((method) =>\n callChain.some((call) => call.method === method),\n );\n }\n\n function checkUnboundedQuery(node: TSESTree.CallExpression, callChain: BuilderCall[]) {\n if (options.requireLimit && !callChain.some((call) => call.method === 'limit')) {\n reportUnboundedQuery(node);\n }\n }\n\n function checkLimitExceedsMax(node: TSESTree.CallExpression, callChain: BuilderCall[]) {\n if (!options.maxLimit) return;\n\n const limitArg = callChain.find((call) => call.method === 'limit')?.args.pop();\n const literalValue = limitArg ? extractNumericLiteral(limitArg) : undefined;\n if (literalValue !== undefined && literalValue > options.maxLimit) {\n reportLimitExceeded(node);\n }\n }\n\n function extractNumericLiteral(\n arg: TSESTree.Expression | TSESTree.SpreadElement,\n ): number | undefined {\n if (arg?.type === 'Literal' && 'value' in arg && typeof arg.value === 'number') {\n return arg.value;\n }\n return;\n }\n\n function reportUnboundedQuery(node: TSESTree.CallExpression) {\n context.report({\n node,\n messageId: 'unboundedQuery',\n });\n }\n\n function reportLimitExceeded(node: TSESTree.CallExpression) {\n context.report({\n node,\n messageId: 'maxLimitExceeded',\n data: { maxLimit: options.maxLimit?.toString() ?? 'undefined' },\n });\n }\n },\n});\n","import { name, version } from '../package.json';\nimport { lintBuildCall } from './rules/lint-build-call';\n\n// Plugin metadata\nconst PLUGIN_META = {\n name,\n version,\n};\n\n// Rule definitions\nconst RULES = {\n 'lint-build-call': lintBuildCall,\n};\n\n// Configuration presets\nconst RULE_CONFIG = {\n '@prisma-next/lint-build-call': 'error',\n};\n\n// Plugin interface\ninterface ESLintPlugin {\n meta: {\n name: string;\n version: string;\n };\n // biome-ignore lint/suspicious/noExplicitAny: Required for ESLint plugin interface compatibility\n rules: Record<string, any>;\n // biome-ignore lint/suspicious/noExplicitAny: Required for ESLint plugin interface compatibility\n configs: Record<string, any>;\n}\n\n// Plugin implementation\nconst plugin: ESLintPlugin = {\n meta: PLUGIN_META,\n rules: RULES,\n configs: {\n recommended: {\n plugins: ['@prisma-next'],\n rules: RULE_CONFIG,\n },\n },\n};\n\n// Add flat config after plugin is defined to avoid circular reference\nplugin.configs['flat/recommended'] = {\n plugins: {\n '@prisma-next': plugin,\n },\n rules: RULE_CONFIG,\n};\n\n// Exports\nexport default plugin;\nexport { lintBuildCall };\nexport { plugin };\nexport type { ESLintPlugin };\n"],"mappings":";;;;;;;;ACKA,MAAM,2BAA2B,CAC/B,yBACA,kCACD;AAED,MAAM,qBAAqB,CAAC,iBAAiB;;;;AAe7C,SAAgB,sBACd,SAC2B;AAC3B,KAAI;EACF,MAAM,iBAAiB,YAAY,kBAAkB,SAAS,MAAM;AAEpE,MAAI,CAAC,gBAAgB,QACnB,QAAO;AAGT,SAAO;GACL,SAAS,eAAe;GACxB,SAAS,eAAe,QAAQ,gBAAgB;GAChD,uBAAuB,eAAe;GACtC,uBAAuB,eAAe;GACvC;SACK;AACN,SAAO;;;;;;AAOX,SAAgB,aAAa,MAA+B,YAA6B;AACvF,QACE,KAAK,OAAO,SAAS,sBACrB,KAAK,OAAO,SAAS,SAAS,gBAC9B,KAAK,OAAO,SAAS,SAAS;;;;;;AAQlC,SAAgB,2BACd,MACA,UACS;AACT,KAAI,CAAC,aAAa,MAAM,QAAQ,IA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,KAAK,SAAS,aAAa,WAAW,OAAO,OAAO,IAAI,UAAU,SACpE,QAAO,IAAI;;EAKf,SAAS,qBAAqB,MAA+B;AAC3D,WAAQ,OAAO;IACb;IACA,WAAW;IACZ,CAAC;;EAGJ,SAAS,oBAAoB,MAA+B;AAC1D,WAAQ,OAAO;IACb;IACA,WAAW;IACX,MAAM,EAAE,UAAU,QAAQ,UAAU,UAAU,IAAI,aAAa;IAChE,CAAC;;;CAGP,CAAC;;;;AChIF,MAAM,cAAc;CAClB;CACA;CACD;AAGD,MAAM,QAAQ,EACZ,mBAAmB,eACpB;AAGD,MAAM,cAAc,EAClB,gCAAgC,SACjC;AAeD,MAAMC,SAAuB;CAC3B,MAAM;CACN,OAAO;CACP,SAAS,EACP,aAAa;EACX,SAAS,CAAC,eAAe;EACzB,OAAO;EACR,EACF;CACF;AAGD,OAAO,QAAQ,sBAAsB;CACnC,SAAS,EACP,gBAAgB,QACjB;CACD,OAAO;CACR;AAGD,kBAAe"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prisma-next/eslint-plugin",
3
- "version": "0.3.0-dev.4",
3
+ "version": "0.3.0-dev.40",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
6
  "description": "ESLint plugin for Prisma Next query builder type checking and linting",
@@ -12,44 +12,54 @@
12
12
  "query-builder"
13
13
  ],
14
14
  "files": [
15
- "dist"
15
+ "dist",
16
+ "src"
16
17
  ],
17
- "main": "./dist/index.js",
18
+ "main": "./dist/index.mjs",
19
+ "types": "./dist/index.d.mts",
18
20
  "exports": {
19
- ".": "./dist/index.js"
21
+ ".": "./dist/index.mjs",
22
+ "./package.json": "./package.json"
20
23
  },
21
24
  "dependencies": {
22
25
  "@typescript-eslint/types": "^8.0.0",
23
26
  "@typescript-eslint/utils": "^8.0.0"
24
27
  },
25
28
  "devDependencies": {
26
- "@typescript-eslint/parser": "^8.0.0",
27
29
  "@types/eslint": "^9.0.0",
28
30
  "@types/node": "24.10.4",
29
- "@vitest/coverage-v8": "4.0.16",
31
+ "@typescript-eslint/parser": "^8.0.0",
30
32
  "eslint": "^9.0.0",
31
- "tsup": "8.5.1",
33
+ "tsdown": "0.18.4",
32
34
  "typescript": "5.9.3",
33
- "vitest": "4.0.16",
34
- "@prisma-next/sql-contract": "0.3.0-dev.4",
35
- "@prisma-next/sql-contract-ts": "0.3.0-dev.4",
36
- "@prisma-next/sql-lane": "0.3.0-dev.4",
37
- "@prisma-next/sql-relational-core": "0.3.0-dev.4",
38
- "@prisma-next/sql-runtime": "0.3.0-dev.4"
35
+ "vitest": "4.0.17",
36
+ "@prisma-next/sql-contract": "0.3.0-dev.40",
37
+ "@prisma-next/sql-contract-ts": "0.3.0-dev.40",
38
+ "@prisma-next/sql-lane": "0.3.0-dev.40",
39
+ "@prisma-next/sql-relational-core": "0.3.0-dev.40",
40
+ "@prisma-next/sql-runtime": "0.3.0-dev.40",
41
+ "@prisma-next/tsconfig": "0.0.0",
42
+ "@prisma-next/tsdown": "0.0.0"
39
43
  },
40
44
  "peerDependencies": {
41
45
  "@typescript-eslint/parser": "^8.0.0",
42
46
  "eslint": "^9.0.0",
43
47
  "typescript": "*"
44
48
  },
49
+ "module": "./dist/index.mjs",
50
+ "repository": {
51
+ "type": "git",
52
+ "url": "https://github.com/prisma/prisma-next.git",
53
+ "directory": "packages/1-framework/3-tooling/eslint-plugin"
54
+ },
45
55
  "scripts": {
46
- "build": "tsup --config tsup.config.ts && tsc --emitDeclarationOnly",
56
+ "build": "tsdown",
47
57
  "test": "vitest run",
48
58
  "test:coverage": "vitest run --coverage",
49
59
  "typecheck": "tsc --noEmit",
50
- "lint": "biome check . --config-path ../../../../biome.json --error-on-warnings",
51
- "lint:fix": "biome check --write . --config-path ../../../../biome.json",
52
- "lint:fix:unsafe": "biome check --write --unsafe . --config-path ../../../../biome.json",
53
- "clean": "node ../../../../scripts/clean.mjs"
60
+ "lint": "biome check . --error-on-warnings",
61
+ "lint:fix": "biome check --write .",
62
+ "lint:fix:unsafe": "biome check --write --unsafe .",
63
+ "clean": "rm -rf dist dist-tsc dist-tsc-prod coverage .tmp-output"
54
64
  }
55
65
  }
package/src/index.ts ADDED
@@ -0,0 +1,56 @@
1
+ import { name, version } from '../package.json';
2
+ import { lintBuildCall } from './rules/lint-build-call';
3
+
4
+ // Plugin metadata
5
+ const PLUGIN_META = {
6
+ name,
7
+ version,
8
+ };
9
+
10
+ // Rule definitions
11
+ const RULES = {
12
+ 'lint-build-call': lintBuildCall,
13
+ };
14
+
15
+ // Configuration presets
16
+ const RULE_CONFIG = {
17
+ '@prisma-next/lint-build-call': 'error',
18
+ };
19
+
20
+ // Plugin interface
21
+ interface ESLintPlugin {
22
+ meta: {
23
+ name: string;
24
+ version: string;
25
+ };
26
+ // biome-ignore lint/suspicious/noExplicitAny: Required for ESLint plugin interface compatibility
27
+ rules: Record<string, any>;
28
+ // biome-ignore lint/suspicious/noExplicitAny: Required for ESLint plugin interface compatibility
29
+ configs: Record<string, any>;
30
+ }
31
+
32
+ // Plugin implementation
33
+ const plugin: ESLintPlugin = {
34
+ meta: PLUGIN_META,
35
+ rules: RULES,
36
+ configs: {
37
+ recommended: {
38
+ plugins: ['@prisma-next'],
39
+ rules: RULE_CONFIG,
40
+ },
41
+ },
42
+ };
43
+
44
+ // Add flat config after plugin is defined to avoid circular reference
45
+ plugin.configs['flat/recommended'] = {
46
+ plugins: {
47
+ '@prisma-next': plugin,
48
+ },
49
+ rules: RULE_CONFIG,
50
+ };
51
+
52
+ // Exports
53
+ export default plugin;
54
+ export { lintBuildCall };
55
+ export { plugin };
56
+ export type { ESLintPlugin };
@@ -0,0 +1,133 @@
1
+ import type { TSESTree } from '@typescript-eslint/types';
2
+ import { ESLintUtils } from '@typescript-eslint/utils';
3
+ import {
4
+ type BuilderCall,
5
+ extractCallChain,
6
+ getTypeScriptServices,
7
+ isPrismaNextQueryBuildCall,
8
+ } from '../utils';
9
+
10
+ const DEFAULT_OPTIONS = {
11
+ requireLimit: true,
12
+ maxLimit: 1000,
13
+ requiredFields: [],
14
+ };
15
+
16
+ const SELECT_QUERY_METHODS = ['select', 'from'] as const;
17
+
18
+ // Types
19
+ type MessageIds = 'unboundedQuery' | 'maxLimitExceeded';
20
+
21
+ interface RuleOptions {
22
+ /** Enforce limit() calls on SELECT queries to prevent unbounded queries */
23
+ requireLimit?: boolean;
24
+ /** Maximum allowed limit value */
25
+ maxLimit?: number;
26
+ }
27
+
28
+ type Options = [RuleOptions];
29
+
30
+ // Rule implementation
31
+ export const lintBuildCall = ESLintUtils.RuleCreator.withoutDocs<Options, MessageIds>({
32
+ meta: {
33
+ type: 'problem',
34
+ docs: {
35
+ description: 'Validate query builder build() calls using TypeScript type information',
36
+ },
37
+ schema: [
38
+ {
39
+ type: 'object',
40
+ properties: {
41
+ requireLimit: {
42
+ type: 'boolean',
43
+ description: 'Enforce limit() calls on SELECT queries',
44
+ },
45
+ maxLimit: {
46
+ type: 'number',
47
+ description: 'Maximum allowed limit value',
48
+ minimum: 1,
49
+ },
50
+ },
51
+ additionalProperties: false,
52
+ },
53
+ ],
54
+ messages: {
55
+ unboundedQuery:
56
+ 'Query build() call may result in unbounded query. Consider adding .limit() to prevent fetching too many rows.',
57
+ maxLimitExceeded:
58
+ 'Query build() call has a limit() value that exceeds the maximum allowed of {{maxLimit}}.',
59
+ },
60
+ },
61
+ defaultOptions: [DEFAULT_OPTIONS],
62
+ create(context, [options]) {
63
+ const services = getTypeScriptServices(context);
64
+
65
+ if (!services) {
66
+ throw new Error(
67
+ 'TypeScript services are required for lint-build-call rule. Please ensure you are using @typescript-eslint/parser.',
68
+ );
69
+ }
70
+
71
+ return {
72
+ CallExpression(node: TSESTree.CallExpression) {
73
+ if (!isPrismaNextQueryBuildCall(node, services)) {
74
+ return;
75
+ }
76
+ lintQuery(node, extractCallChain(node));
77
+ },
78
+ };
79
+
80
+ function lintQuery(node: TSESTree.CallExpression, callChain: BuilderCall[]) {
81
+ if (isSelectQuery(callChain)) {
82
+ checkUnboundedQuery(node, callChain);
83
+ checkLimitExceedsMax(node, callChain);
84
+ }
85
+ }
86
+
87
+ function isSelectQuery(callChain: BuilderCall[]): boolean {
88
+ return SELECT_QUERY_METHODS.some((method) =>
89
+ callChain.some((call) => call.method === method),
90
+ );
91
+ }
92
+
93
+ function checkUnboundedQuery(node: TSESTree.CallExpression, callChain: BuilderCall[]) {
94
+ if (options.requireLimit && !callChain.some((call) => call.method === 'limit')) {
95
+ reportUnboundedQuery(node);
96
+ }
97
+ }
98
+
99
+ function checkLimitExceedsMax(node: TSESTree.CallExpression, callChain: BuilderCall[]) {
100
+ if (!options.maxLimit) return;
101
+
102
+ const limitArg = callChain.find((call) => call.method === 'limit')?.args.pop();
103
+ const literalValue = limitArg ? extractNumericLiteral(limitArg) : undefined;
104
+ if (literalValue !== undefined && literalValue > options.maxLimit) {
105
+ reportLimitExceeded(node);
106
+ }
107
+ }
108
+
109
+ function extractNumericLiteral(
110
+ arg: TSESTree.Expression | TSESTree.SpreadElement,
111
+ ): number | undefined {
112
+ if (arg?.type === 'Literal' && 'value' in arg && typeof arg.value === 'number') {
113
+ return arg.value;
114
+ }
115
+ return;
116
+ }
117
+
118
+ function reportUnboundedQuery(node: TSESTree.CallExpression) {
119
+ context.report({
120
+ node,
121
+ messageId: 'unboundedQuery',
122
+ });
123
+ }
124
+
125
+ function reportLimitExceeded(node: TSESTree.CallExpression) {
126
+ context.report({
127
+ node,
128
+ messageId: 'maxLimitExceeded',
129
+ data: { maxLimit: options.maxLimit?.toString() ?? 'undefined' },
130
+ });
131
+ }
132
+ },
133
+ });
package/src/utils.ts ADDED
@@ -0,0 +1,159 @@
1
+ import type { TSESTree } from '@typescript-eslint/types';
2
+ import type { ParserServices } from '@typescript-eslint/utils';
3
+ import { ESLintUtils } from '@typescript-eslint/utils';
4
+ import type * as ts from 'typescript';
5
+
6
+ const PRISMA_NEXT_SQL_PACKAGES = [
7
+ '@prisma-next/sql-lane',
8
+ 'packages/2-sql/4-lanes/sql-lane',
9
+ ] as const;
10
+
11
+ const PLAN_TYPE_PATTERNS = [/^SqlQueryPlan$/] as const;
12
+
13
+ export type BuilderCall = { method: string; args: TSESTree.CallExpressionArgument[] };
14
+
15
+ // Types
16
+ export interface TypeScriptServices {
17
+ program: ts.Program;
18
+ checker: ts.TypeChecker;
19
+ esTreeNodeToTSNodeMap: ParserServices['esTreeNodeToTSNodeMap'];
20
+ tsNodeToESTreeNodeMap: ParserServices['tsNodeToESTreeNodeMap'];
21
+ }
22
+
23
+ /**
24
+ * Get TypeScript services from ESLint context
25
+ */
26
+ export function getTypeScriptServices(
27
+ context: Parameters<typeof ESLintUtils.getParserServices>[0],
28
+ ): TypeScriptServices | null {
29
+ try {
30
+ const parserServices = ESLintUtils.getParserServices(context, false);
31
+
32
+ if (!parserServices?.program) {
33
+ return null;
34
+ }
35
+
36
+ return {
37
+ program: parserServices.program,
38
+ checker: parserServices.program.getTypeChecker(),
39
+ esTreeNodeToTSNodeMap: parserServices.esTreeNodeToTSNodeMap,
40
+ tsNodeToESTreeNodeMap: parserServices.tsNodeToESTreeNodeMap,
41
+ };
42
+ } catch {
43
+ return null;
44
+ }
45
+ }
46
+
47
+ /**
48
+ * Check if a call expression is a method call with a specific name
49
+ */
50
+ export function isMethodCall(node: TSESTree.CallExpression, methodName: string): boolean {
51
+ return (
52
+ node.callee.type === 'MemberExpression' &&
53
+ node.callee.property.type === 'Identifier' &&
54
+ node.callee.property.name === methodName
55
+ );
56
+ }
57
+
58
+ /**
59
+ * Check if a call expression is a query builder build() call
60
+ * Uses type information to verify it's actually our query builder's build method
61
+ */
62
+ export function isPrismaNextQueryBuildCall(
63
+ node: TSESTree.CallExpression,
64
+ services?: TypeScriptServices | null,
65
+ ): boolean {
66
+ if (!isMethodCall(node, 'build') || node.arguments.length > 1 || !services) {
67
+ return false;
68
+ }
69
+
70
+ if (node.callee.type !== 'MemberExpression') {
71
+ return false;
72
+ }
73
+
74
+ const objectType = getTypeOfNode(node.callee.object, services);
75
+ if (!objectType) {
76
+ return false;
77
+ }
78
+
79
+ if (!isTypeFromPackages(objectType, PRISMA_NEXT_SQL_PACKAGES)) {
80
+ return false;
81
+ }
82
+
83
+ const returnType = getTypeOfNode(node, services);
84
+ return returnType ? isPrismaNextQueryPlanType(returnType) : false;
85
+ }
86
+
87
+ /**
88
+ * Get the TypeScript type of an ESTree node
89
+ */
90
+ export function getTypeOfNode(node: TSESTree.Node, services: TypeScriptServices): ts.Type | null {
91
+ try {
92
+ const tsNode = services.esTreeNodeToTSNodeMap.get(node);
93
+ return tsNode ? services.checker.getTypeAtLocation(tsNode) : null;
94
+ } catch {
95
+ return null;
96
+ }
97
+ }
98
+
99
+ /**
100
+ * Check if a type has a specific property
101
+ */
102
+ export function typeHasProperty(
103
+ type: ts.Type,
104
+ propertyName: string,
105
+ checker: ts.TypeChecker,
106
+ ): boolean {
107
+ try {
108
+ const properties = checker.getPropertiesOfType(type);
109
+ return properties.some((prop) => prop.getName() === propertyName);
110
+ } catch {
111
+ return false;
112
+ }
113
+ }
114
+
115
+ /**
116
+ * Check if type is a Prisma Next query plan type by name and origin
117
+ */
118
+ export function isPrismaNextQueryPlanType(type: ts.Type): boolean {
119
+ return PLAN_TYPE_PATTERNS.some((pattern) => pattern.test(type.symbol.name));
120
+ }
121
+
122
+ /**
123
+ * Extract call chain from a call expression
124
+ * Returns array of method names called in sequence
125
+ */
126
+ export function extractCallChain(node: TSESTree.CallExpression): BuilderCall[] {
127
+ const chain: BuilderCall[] = [];
128
+
129
+ function traverse(current: TSESTree.Node): void {
130
+ switch (current.type) {
131
+ case 'CallExpression':
132
+ if (current.callee.type === 'MemberExpression') {
133
+ traverse(current.callee.object);
134
+ if (current.callee.property.type === 'Identifier') {
135
+ chain.push({ method: current.callee.property.name, args: current.arguments });
136
+ }
137
+ }
138
+ break;
139
+
140
+ case 'MemberExpression':
141
+ traverse(current.object);
142
+ break;
143
+
144
+ case 'Identifier':
145
+ break;
146
+ }
147
+ }
148
+
149
+ traverse(node);
150
+ return chain;
151
+ }
152
+
153
+ /**
154
+ * Helper to check if a type originates from specific packages
155
+ */
156
+ function isTypeFromPackages(type: ts.Type, packages: readonly string[]): boolean {
157
+ const fileName = type.getSymbol()?.valueDeclaration?.getSourceFile().fileName;
158
+ return fileName ? packages.some((pkg) => fileName.includes(`${pkg}/`)) : false;
159
+ }
package/dist/index.d.ts DELETED
@@ -1,15 +0,0 @@
1
- import { lintBuildCall } from './rules/lint-build-call';
2
- interface ESLintPlugin {
3
- meta: {
4
- name: string;
5
- version: string;
6
- };
7
- rules: Record<string, any>;
8
- configs: Record<string, any>;
9
- }
10
- declare const plugin: ESLintPlugin;
11
- export default plugin;
12
- export { lintBuildCall };
13
- export { plugin };
14
- export type { ESLintPlugin };
15
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAmBxD,UAAU,YAAY;IACpB,IAAI,EAAE;QACJ,IAAI,EAAE,MAAM,CAAC;QACb,OAAO,EAAE,MAAM,CAAC;KACjB,CAAC;IAEF,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAE3B,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAC9B;AAGD,QAAA,MAAM,MAAM,EAAE,YASb,CAAC;AAWF,eAAe,MAAM,CAAC;AACtB,OAAO,EAAE,aAAa,EAAE,CAAC;AACzB,OAAO,EAAE,MAAM,EAAE,CAAC;AAClB,YAAY,EAAE,YAAY,EAAE,CAAC"}
package/dist/index.js DELETED
@@ -1,219 +0,0 @@
1
- // package.json
2
- var name = "@prisma-next/eslint-plugin";
3
- var version = "0.3.0-dev.4";
4
-
5
- // src/rules/lint-build-call.ts
6
- import { ESLintUtils as ESLintUtils2 } from "@typescript-eslint/utils";
7
-
8
- // src/utils.ts
9
- import { ESLintUtils } from "@typescript-eslint/utils";
10
- var PRISMA_NEXT_SQL_PACKAGES = [
11
- "@prisma-next/sql-lane",
12
- "packages/2-sql/4-lanes/sql-lane"
13
- ];
14
- var PLAN_TYPE_PATTERNS = [/^SqlQueryPlan$/];
15
- function getTypeScriptServices(context) {
16
- try {
17
- const parserServices = ESLintUtils.getParserServices(context, false);
18
- if (!parserServices?.program) {
19
- return null;
20
- }
21
- return {
22
- program: parserServices.program,
23
- checker: parserServices.program.getTypeChecker(),
24
- esTreeNodeToTSNodeMap: parserServices.esTreeNodeToTSNodeMap,
25
- tsNodeToESTreeNodeMap: parserServices.tsNodeToESTreeNodeMap
26
- };
27
- } catch {
28
- return null;
29
- }
30
- }
31
- function isMethodCall(node, methodName) {
32
- return node.callee.type === "MemberExpression" && node.callee.property.type === "Identifier" && node.callee.property.name === methodName;
33
- }
34
- function isPrismaNextQueryBuildCall(node, services) {
35
- if (!isMethodCall(node, "build") || node.arguments.length > 1 || !services) {
36
- return false;
37
- }
38
- if (node.callee.type !== "MemberExpression") {
39
- return false;
40
- }
41
- const objectType = getTypeOfNode(node.callee.object, services);
42
- if (!objectType) {
43
- return false;
44
- }
45
- if (!isTypeFromPackages(objectType, PRISMA_NEXT_SQL_PACKAGES)) {
46
- return false;
47
- }
48
- const returnType = getTypeOfNode(node, services);
49
- return returnType ? isPrismaNextQueryPlanType(returnType) : false;
50
- }
51
- function getTypeOfNode(node, services) {
52
- try {
53
- const tsNode = services.esTreeNodeToTSNodeMap.get(node);
54
- return tsNode ? services.checker.getTypeAtLocation(tsNode) : null;
55
- } catch {
56
- return null;
57
- }
58
- }
59
- function isPrismaNextQueryPlanType(type) {
60
- return PLAN_TYPE_PATTERNS.some((pattern) => pattern.test(type.symbol.name));
61
- }
62
- function extractCallChain(node) {
63
- const chain = [];
64
- function traverse(current) {
65
- switch (current.type) {
66
- case "CallExpression":
67
- if (current.callee.type === "MemberExpression") {
68
- traverse(current.callee.object);
69
- if (current.callee.property.type === "Identifier") {
70
- chain.push({ method: current.callee.property.name, args: current.arguments });
71
- }
72
- }
73
- break;
74
- case "MemberExpression":
75
- traverse(current.object);
76
- break;
77
- case "Identifier":
78
- break;
79
- }
80
- }
81
- traverse(node);
82
- return chain;
83
- }
84
- function isTypeFromPackages(type, packages) {
85
- const fileName = type.getSymbol()?.valueDeclaration?.getSourceFile().fileName;
86
- return fileName ? packages.some((pkg) => fileName.includes(`${pkg}/`)) : false;
87
- }
88
-
89
- // src/rules/lint-build-call.ts
90
- var DEFAULT_OPTIONS = {
91
- requireLimit: true,
92
- maxLimit: 1e3,
93
- requiredFields: []
94
- };
95
- var SELECT_QUERY_METHODS = ["select", "from"];
96
- var lintBuildCall = ESLintUtils2.RuleCreator.withoutDocs({
97
- meta: {
98
- type: "problem",
99
- docs: {
100
- description: "Validate query builder build() calls using TypeScript type information"
101
- },
102
- schema: [
103
- {
104
- type: "object",
105
- properties: {
106
- requireLimit: {
107
- type: "boolean",
108
- description: "Enforce limit() calls on SELECT queries"
109
- },
110
- maxLimit: {
111
- type: "number",
112
- description: "Maximum allowed limit value",
113
- minimum: 1
114
- }
115
- },
116
- additionalProperties: false
117
- }
118
- ],
119
- messages: {
120
- unboundedQuery: "Query build() call may result in unbounded query. Consider adding .limit() to prevent fetching too many rows.",
121
- maxLimitExceeded: "Query build() call has a limit() value that exceeds the maximum allowed of {{maxLimit}}."
122
- }
123
- },
124
- defaultOptions: [DEFAULT_OPTIONS],
125
- create(context, [options]) {
126
- const services = getTypeScriptServices(context);
127
- if (!services) {
128
- throw new Error(
129
- "TypeScript services are required for lint-build-call rule. Please ensure you are using @typescript-eslint/parser."
130
- );
131
- }
132
- return {
133
- CallExpression(node) {
134
- if (!isPrismaNextQueryBuildCall(node, services)) {
135
- return;
136
- }
137
- lintQuery(node, extractCallChain(node));
138
- }
139
- };
140
- function lintQuery(node, callChain) {
141
- if (isSelectQuery(callChain)) {
142
- checkUnboundedQuery(node, callChain);
143
- checkLimitExceedsMax(node, callChain);
144
- }
145
- }
146
- function isSelectQuery(callChain) {
147
- return SELECT_QUERY_METHODS.some(
148
- (method) => callChain.some((call) => call.method === method)
149
- );
150
- }
151
- function checkUnboundedQuery(node, callChain) {
152
- if (options.requireLimit && !callChain.some((call) => call.method === "limit")) {
153
- reportUnboundedQuery(node);
154
- }
155
- }
156
- function checkLimitExceedsMax(node, callChain) {
157
- if (!options.maxLimit) return;
158
- const limitArg = callChain.find((call) => call.method === "limit")?.args.pop();
159
- const literalValue = limitArg ? extractNumericLiteral(limitArg) : void 0;
160
- if (literalValue !== void 0 && literalValue > options.maxLimit) {
161
- reportLimitExceeded(node);
162
- }
163
- }
164
- function extractNumericLiteral(arg) {
165
- if (arg?.type === "Literal" && "value" in arg && typeof arg.value === "number") {
166
- return arg.value;
167
- }
168
- return;
169
- }
170
- function reportUnboundedQuery(node) {
171
- context.report({
172
- node,
173
- messageId: "unboundedQuery"
174
- });
175
- }
176
- function reportLimitExceeded(node) {
177
- context.report({
178
- node,
179
- messageId: "maxLimitExceeded",
180
- data: { maxLimit: options.maxLimit?.toString() ?? "undefined" }
181
- });
182
- }
183
- }
184
- });
185
-
186
- // src/index.ts
187
- var PLUGIN_META = {
188
- name,
189
- version
190
- };
191
- var RULES = {
192
- "lint-build-call": lintBuildCall
193
- };
194
- var RULE_CONFIG = {
195
- "@prisma-next/lint-build-call": "error"
196
- };
197
- var plugin = {
198
- meta: PLUGIN_META,
199
- rules: RULES,
200
- configs: {
201
- recommended: {
202
- plugins: ["@prisma-next"],
203
- rules: RULE_CONFIG
204
- }
205
- }
206
- };
207
- plugin.configs["flat/recommended"] = {
208
- plugins: {
209
- "@prisma-next": plugin
210
- },
211
- rules: RULE_CONFIG
212
- };
213
- var index_default = plugin;
214
- export {
215
- index_default as default,
216
- lintBuildCall,
217
- plugin
218
- };
219
- //# sourceMappingURL=index.js.map
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../package.json","../src/rules/lint-build-call.ts","../src/utils.ts","../src/index.ts"],"sourcesContent":["{\n \"name\": \"@prisma-next/eslint-plugin\",\n \"version\": \"0.3.0-dev.4\",\n \"type\": \"module\",\n \"sideEffects\": false,\n \"description\": \"ESLint plugin for Prisma Next query builder type checking and linting\",\n \"keywords\": [\n \"eslint\",\n \"eslintplugin\",\n \"typescript\",\n \"prisma-next\",\n \"query-builder\"\n ],\n \"files\": [\n \"dist\"\n ],\n \"main\": \"./dist/index.js\",\n \"exports\": {\n \".\": \"./dist/index.js\"\n },\n \"scripts\": {\n \"build\": \"tsup --config tsup.config.ts && tsc --emitDeclarationOnly\",\n \"test\": \"vitest run\",\n \"test:coverage\": \"vitest run --coverage\",\n \"typecheck\": \"tsc --noEmit\",\n \"lint\": \"biome check . --config-path ../../../../biome.json --error-on-warnings\",\n \"lint:fix\": \"biome check --write . --config-path ../../../../biome.json\",\n \"lint:fix:unsafe\": \"biome check --write --unsafe . --config-path ../../../../biome.json\",\n \"clean\": \"node ../../../../scripts/clean.mjs\"\n },\n \"dependencies\": {\n \"@typescript-eslint/types\": \"^8.0.0\",\n \"@typescript-eslint/utils\": \"^8.0.0\"\n },\n \"devDependencies\": {\n \"@prisma-next/sql-contract\": \"workspace:*\",\n \"@prisma-next/sql-contract-ts\": \"workspace:*\",\n \"@prisma-next/sql-lane\": \"workspace:*\",\n \"@prisma-next/sql-relational-core\": \"workspace:*\",\n \"@prisma-next/sql-runtime\": \"workspace:*\",\n \"@typescript-eslint/parser\": \"^8.0.0\",\n \"@types/eslint\": \"^9.0.0\",\n \"@types/node\": \"catalog:\",\n \"@vitest/coverage-v8\": \"catalog:\",\n \"eslint\": \"^9.0.0\",\n \"tsup\": \"catalog:\",\n \"typescript\": \"catalog:\",\n \"vitest\": \"catalog:\"\n },\n \"peerDependencies\": {\n \"@typescript-eslint/parser\": \"^8.0.0\",\n \"eslint\": \"^9.0.0\",\n \"typescript\": \"*\"\n }\n}\n","import type { TSESTree } from '@typescript-eslint/types';\nimport { ESLintUtils } from '@typescript-eslint/utils';\nimport {\n type BuilderCall,\n extractCallChain,\n getTypeScriptServices,\n isPrismaNextQueryBuildCall,\n} from '../utils';\n\nconst DEFAULT_OPTIONS = {\n requireLimit: true,\n maxLimit: 1000,\n requiredFields: [],\n};\n\nconst SELECT_QUERY_METHODS = ['select', 'from'] as const;\n\n// Types\ntype MessageIds = 'unboundedQuery' | 'maxLimitExceeded';\n\ninterface RuleOptions {\n /** Enforce limit() calls on SELECT queries to prevent unbounded queries */\n requireLimit?: boolean;\n /** Maximum allowed limit value */\n maxLimit?: number;\n}\n\ntype Options = [RuleOptions];\n\n// Rule implementation\nexport const lintBuildCall = ESLintUtils.RuleCreator.withoutDocs<Options, MessageIds>({\n meta: {\n type: 'problem',\n docs: {\n description: 'Validate query builder build() calls using TypeScript type information',\n },\n schema: [\n {\n type: 'object',\n properties: {\n requireLimit: {\n type: 'boolean',\n description: 'Enforce limit() calls on SELECT queries',\n },\n maxLimit: {\n type: 'number',\n description: 'Maximum allowed limit value',\n minimum: 1,\n },\n },\n additionalProperties: false,\n },\n ],\n messages: {\n unboundedQuery:\n 'Query build() call may result in unbounded query. Consider adding .limit() to prevent fetching too many rows.',\n maxLimitExceeded:\n 'Query build() call has a limit() value that exceeds the maximum allowed of {{maxLimit}}.',\n },\n },\n defaultOptions: [DEFAULT_OPTIONS],\n create(context, [options]) {\n const services = getTypeScriptServices(context);\n\n if (!services) {\n throw new Error(\n 'TypeScript services are required for lint-build-call rule. Please ensure you are using @typescript-eslint/parser.',\n );\n }\n\n return {\n CallExpression(node: TSESTree.CallExpression) {\n if (!isPrismaNextQueryBuildCall(node, services)) {\n return;\n }\n lintQuery(node, extractCallChain(node));\n },\n };\n\n function lintQuery(node: TSESTree.CallExpression, callChain: BuilderCall[]) {\n if (isSelectQuery(callChain)) {\n checkUnboundedQuery(node, callChain);\n checkLimitExceedsMax(node, callChain);\n }\n }\n\n function isSelectQuery(callChain: BuilderCall[]): boolean {\n return SELECT_QUERY_METHODS.some((method) =>\n callChain.some((call) => call.method === method),\n );\n }\n\n function checkUnboundedQuery(node: TSESTree.CallExpression, callChain: BuilderCall[]) {\n if (options.requireLimit && !callChain.some((call) => call.method === 'limit')) {\n reportUnboundedQuery(node);\n }\n }\n\n function checkLimitExceedsMax(node: TSESTree.CallExpression, callChain: BuilderCall[]) {\n if (!options.maxLimit) return;\n\n const limitArg = callChain.find((call) => call.method === 'limit')?.args.pop();\n const literalValue = limitArg ? extractNumericLiteral(limitArg) : undefined;\n if (literalValue !== undefined && literalValue > options.maxLimit) {\n reportLimitExceeded(node);\n }\n }\n\n function extractNumericLiteral(\n arg: TSESTree.Expression | TSESTree.SpreadElement,\n ): number | undefined {\n if (arg?.type === 'Literal' && 'value' in arg && typeof arg.value === 'number') {\n return arg.value;\n }\n return;\n }\n\n function reportUnboundedQuery(node: TSESTree.CallExpression) {\n context.report({\n node,\n messageId: 'unboundedQuery',\n });\n }\n\n function reportLimitExceeded(node: TSESTree.CallExpression) {\n context.report({\n node,\n messageId: 'maxLimitExceeded',\n data: { maxLimit: options.maxLimit?.toString() ?? 'undefined' },\n });\n }\n },\n});\n","import type { TSESTree } from '@typescript-eslint/types';\nimport type { ParserServices } from '@typescript-eslint/utils';\nimport { ESLintUtils } from '@typescript-eslint/utils';\nimport type * as ts from 'typescript';\n\nconst PRISMA_NEXT_SQL_PACKAGES = [\n '@prisma-next/sql-lane',\n 'packages/2-sql/4-lanes/sql-lane',\n] as const;\n\nconst PLAN_TYPE_PATTERNS = [/^SqlQueryPlan$/] as const;\n\nexport type BuilderCall = { method: string; args: TSESTree.CallExpressionArgument[] };\n\n// Types\nexport interface TypeScriptServices {\n program: ts.Program;\n checker: ts.TypeChecker;\n esTreeNodeToTSNodeMap: ParserServices['esTreeNodeToTSNodeMap'];\n tsNodeToESTreeNodeMap: ParserServices['tsNodeToESTreeNodeMap'];\n}\n\n/**\n * Get TypeScript services from ESLint context\n */\nexport function getTypeScriptServices(\n context: Parameters<typeof ESLintUtils.getParserServices>[0],\n): TypeScriptServices | null {\n try {\n const parserServices = ESLintUtils.getParserServices(context, false);\n\n if (!parserServices?.program) {\n return null;\n }\n\n return {\n program: parserServices.program,\n checker: parserServices.program.getTypeChecker(),\n esTreeNodeToTSNodeMap: parserServices.esTreeNodeToTSNodeMap,\n tsNodeToESTreeNodeMap: parserServices.tsNodeToESTreeNodeMap,\n };\n } catch {\n return null;\n }\n}\n\n/**\n * Check if a call expression is a method call with a specific name\n */\nexport function isMethodCall(node: TSESTree.CallExpression, methodName: string): boolean {\n return (\n node.callee.type === 'MemberExpression' &&\n node.callee.property.type === 'Identifier' &&\n node.callee.property.name === methodName\n );\n}\n\n/**\n * Check if a call expression is a query builder build() call\n * Uses type information to verify it's actually our query builder's build method\n */\nexport function isPrismaNextQueryBuildCall(\n node: TSESTree.CallExpression,\n services?: TypeScriptServices | null,\n): boolean {\n if (!isMethodCall(node, 'build') || node.arguments.length > 1 || !services) {\n return false;\n }\n\n if (node.callee.type !== 'MemberExpression') {\n return false;\n }\n\n const objectType = getTypeOfNode(node.callee.object, services);\n if (!objectType) {\n return false;\n }\n\n if (!isTypeFromPackages(objectType, PRISMA_NEXT_SQL_PACKAGES)) {\n return false;\n }\n\n const returnType = getTypeOfNode(node, services);\n return returnType ? isPrismaNextQueryPlanType(returnType) : false;\n}\n\n/**\n * Get the TypeScript type of an ESTree node\n */\nexport function getTypeOfNode(node: TSESTree.Node, services: TypeScriptServices): ts.Type | null {\n try {\n const tsNode = services.esTreeNodeToTSNodeMap.get(node);\n return tsNode ? services.checker.getTypeAtLocation(tsNode) : null;\n } catch {\n return null;\n }\n}\n\n/**\n * Check if a type has a specific property\n */\nexport function typeHasProperty(\n type: ts.Type,\n propertyName: string,\n checker: ts.TypeChecker,\n): boolean {\n try {\n const properties = checker.getPropertiesOfType(type);\n return properties.some((prop) => prop.getName() === propertyName);\n } catch {\n return false;\n }\n}\n\n/**\n * Check if type is a Prisma Next query plan type by name and origin\n */\nexport function isPrismaNextQueryPlanType(type: ts.Type): boolean {\n return PLAN_TYPE_PATTERNS.some((pattern) => pattern.test(type.symbol.name));\n}\n\n/**\n * Extract call chain from a call expression\n * Returns array of method names called in sequence\n */\nexport function extractCallChain(node: TSESTree.CallExpression): BuilderCall[] {\n const chain: BuilderCall[] = [];\n\n function traverse(current: TSESTree.Node): void {\n switch (current.type) {\n case 'CallExpression':\n if (current.callee.type === 'MemberExpression') {\n traverse(current.callee.object);\n if (current.callee.property.type === 'Identifier') {\n chain.push({ method: current.callee.property.name, args: current.arguments });\n }\n }\n break;\n\n case 'MemberExpression':\n traverse(current.object);\n break;\n\n case 'Identifier':\n break;\n }\n }\n\n traverse(node);\n return chain;\n}\n\n/**\n * Helper to check if a type originates from specific packages\n */\nfunction isTypeFromPackages(type: ts.Type, packages: readonly string[]): boolean {\n const fileName = type.getSymbol()?.valueDeclaration?.getSourceFile().fileName;\n return fileName ? packages.some((pkg) => fileName.includes(`${pkg}/`)) : false;\n}\n","import { name, version } from '../package.json';\nimport { lintBuildCall } from './rules/lint-build-call';\n\n// Plugin metadata\nconst PLUGIN_META = {\n name,\n version,\n};\n\n// Rule definitions\nconst RULES = {\n 'lint-build-call': lintBuildCall,\n};\n\n// Configuration presets\nconst RULE_CONFIG = {\n '@prisma-next/lint-build-call': 'error',\n};\n\n// Plugin interface\ninterface ESLintPlugin {\n meta: {\n name: string;\n version: string;\n };\n // biome-ignore lint/suspicious/noExplicitAny: Required for ESLint plugin interface compatibility\n rules: Record<string, any>;\n // biome-ignore lint/suspicious/noExplicitAny: Required for ESLint plugin interface compatibility\n configs: Record<string, any>;\n}\n\n// Plugin implementation\nconst plugin: ESLintPlugin = {\n meta: PLUGIN_META,\n rules: RULES,\n configs: {\n recommended: {\n plugins: ['@prisma-next'],\n rules: RULE_CONFIG,\n },\n },\n};\n\n// Add flat config after plugin is defined to avoid circular reference\nplugin.configs['flat/recommended'] = {\n plugins: {\n '@prisma-next': plugin,\n },\n rules: RULE_CONFIG,\n};\n\n// Exports\nexport default plugin;\nexport { lintBuildCall };\nexport { plug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AAAA,IACF;AAEA,aAAS,sBACP,KACoB;AACpB,UAAI,KAAK,SAAS,aAAa,WAAW,OAAO,OAAO,IAAI,UAAU,UAAU;AAC9E,eAAO,IAAI;AAAA,MACb;AACA;AAAA,IACF;AAEA,aAAS,qBAAqB,MAA+B;AAC3D,cAAQ,OAAO;AAAA,QACb;AAAA,QACA,WAAW;AAAA,MACb,CAAC;AAAA,IACH;AAEA,aAAS,oBAAoB,MAA+B;AAC1D,cAAQ,OAAO;AAAA,QACb;AAAA,QACA,WAAW;AAAA,QACX,MAAM,EAAE,UAAU,QAAQ,UAAU,SAAS,KAAK,YAAY;AAAA,MAChE,CAAC;AAAA,IACH;AAAA,EACF;AACF,CAAC;;;AEhID,IAAM,cAAc;AAAA,EAClB;AAAA,EACA;AACF;AAGA,IAAM,QAAQ;AAAA,EACZ,mBAAmB;AACrB;AAGA,IAAM,cAAc;AAAA,EAClB,gCAAgC;AAClC;AAeA,IAAM,SAAuB;AAAA,EAC3B,MAAM;AAAA,EACN,OAAO;AAAA,EACP,SAAS;AAAA,IACP,aAAa;AAAA,MACX,SAAS,CAAC,cAAc;AAAA,MACxB,OAAO;AAAA,IACT;AAAA,EACF;AACF;AAGA,OAAO,QAAQ,kBAAkB,IAAI;AAAA,EACnC,SAAS;AAAA,IACP,gBAAgB;AAAA,EAClB;AAAA,EACA,OAAO;AACT;AAGA,IAAO,gBAAQ;","names":["ESLintUtils","ESLintUtils"]}
@@ -1,12 +0,0 @@
1
- import { ESLintUtils } from '@typescript-eslint/utils';
2
- type MessageIds = 'unboundedQuery' | 'maxLimitExceeded';
3
- interface RuleOptions {
4
- /** Enforce limit() calls on SELECT queries to prevent unbounded queries */
5
- requireLimit?: boolean;
6
- /** Maximum allowed limit value */
7
- maxLimit?: number;
8
- }
9
- type Options = [RuleOptions];
10
- export declare const lintBuildCall: ESLintUtils.RuleModule<MessageIds, Options, unknown, ESLintUtils.RuleListener>;
11
- export {};
12
- //# sourceMappingURL=lint-build-call.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"lint-build-call.d.ts","sourceRoot":"","sources":["../../src/rules/lint-build-call.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAiBvD,KAAK,UAAU,GAAG,gBAAgB,GAAG,kBAAkB,CAAC;AAExD,UAAU,WAAW;IACnB,2EAA2E;IAC3E,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,kCAAkC;IAClC,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,KAAK,OAAO,GAAG,CAAC,WAAW,CAAC,CAAC;AAG7B,eAAO,MAAM,aAAa,gFAsGxB,CAAC"}
package/dist/utils.d.ts DELETED
@@ -1,45 +0,0 @@
1
- import type { TSESTree } from '@typescript-eslint/types';
2
- import type { ParserServices } from '@typescript-eslint/utils';
3
- import { ESLintUtils } from '@typescript-eslint/utils';
4
- import type * as ts from 'typescript';
5
- export type BuilderCall = {
6
- method: string;
7
- args: TSESTree.CallExpressionArgument[];
8
- };
9
- export interface TypeScriptServices {
10
- program: ts.Program;
11
- checker: ts.TypeChecker;
12
- esTreeNodeToTSNodeMap: ParserServices['esTreeNodeToTSNodeMap'];
13
- tsNodeToESTreeNodeMap: ParserServices['tsNodeToESTreeNodeMap'];
14
- }
15
- /**
16
- * Get TypeScript services from ESLint context
17
- */
18
- export declare function getTypeScriptServices(context: Parameters<typeof ESLintUtils.getParserServices>[0]): TypeScriptServices | null;
19
- /**
20
- * Check if a call expression is a method call with a specific name
21
- */
22
- export declare function isMethodCall(node: TSESTree.CallExpression, methodName: string): boolean;
23
- /**
24
- * Check if a call expression is a query builder build() call
25
- * Uses type information to verify it's actually our query builder's build method
26
- */
27
- export declare function isPrismaNextQueryBuildCall(node: TSESTree.CallExpression, services?: TypeScriptServices | null): boolean;
28
- /**
29
- * Get the TypeScript type of an ESTree node
30
- */
31
- export declare function getTypeOfNode(node: TSESTree.Node, services: TypeScriptServices): ts.Type | null;
32
- /**
33
- * Check if a type has a specific property
34
- */
35
- export declare function typeHasProperty(type: ts.Type, propertyName: string, checker: ts.TypeChecker): boolean;
36
- /**
37
- * Check if type is a Prisma Next query plan type by name and origin
38
- */
39
- export declare function isPrismaNextQueryPlanType(type: ts.Type): boolean;
40
- /**
41
- * Extract call chain from a call expression
42
- * Returns array of method names called in sequence
43
- */
44
- export declare function extractCallChain(node: TSESTree.CallExpression): BuilderCall[];
45
- //# sourceMappingURL=utils.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,KAAK,KAAK,EAAE,MAAM,YAAY,CAAC;AAStC,MAAM,MAAM,WAAW,GAAG;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,QAAQ,CAAC,sBAAsB,EAAE,CAAA;CAAE,CAAC;AAGtF,MAAM,WAAW,kBAAkB;IACjC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC;IACpB,OAAO,EAAE,EAAE,CAAC,WAAW,CAAC;IACxB,qBAAqB,EAAE,cAAc,CAAC,uBAAuB,CAAC,CAAC;IAC/D,qBAAqB,EAAE,cAAc,CAAC,uBAAuB,CAAC,CAAC;CAChE;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CACnC,OAAO,EAAE,UAAU,CAAC,OAAO,WAAW,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,GAC3D,kBAAkB,GAAG,IAAI,CAiB3B;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,QAAQ,CAAC,cAAc,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAMvF;AAED;;;GAGG;AACH,wBAAgB,0BAA0B,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