@prisma-next/eslint-plugin 0.1.0-dev.6 → 0.1.0-dev.8

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.js CHANGED
@@ -1,6 +1,6 @@
1
1
  // package.json
2
2
  var name = "@prisma-next/eslint-plugin";
3
- var version = "0.1.0-dev.6";
3
+ var version = "0.1.0-dev.8";
4
4
 
5
5
  // src/rules/lint-build-call.ts
6
6
  import { ESLintUtils as ESLintUtils2 } from "@typescript-eslint/utils";
package/dist/index.js.map CHANGED
@@ -1 +1 @@
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.1.0-dev.6\",\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 \"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\": \"^20.0.0\",\n \"eslint\": \"^9.0.0\",\n \"tsup\": \"^8.3.0\",\n \"typescript\": \"^5.9.3\",\n \"vitest\": \"^2.1.1\"\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 = ['@prisma-next/sql-lane', 'packages/sql/lanes/sql-lane'] 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 { plugin };\nexport type { ESLintPlugin };\n"],"mappings":";AACE,WAAQ;AACR,cAAW;;;ACDb,SAAS,eAAAA,oBAAmB;;;ACC5B,SAAS,mBAAmB;AAG5B,IAAM,2BAA2B,CAAC,yBAAyB,6BAA6B;AAExF,IAAM,qBAAqB,CAAC,gBAAgB;AAerC,SAAS,sBACd,SAC2B;AAC3B,MAAI;AACF,UAAM,iBAAiB,YAAY,kBAAkB,SAAS,KAAK;AAEnE,QAAI,CAAC,gBAAgB,SAAS;AAC5B,aAAO;AAAA,IACT;AAEA,WAAO;AAAA,MACL,SAAS,eAAe;AAAA,MACxB,SAAS,eAAe,QAAQ,eAAe;AAAA,MAC/C,uBAAuB,eAAe;AAAA,MACtC,uBAAuB,eAAe;AAAA,IACxC;AAAA,EACF,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAKO,SAAS,aAAa,MAA+B,YAA6B;AACvF,SACE,KAAK,OAAO,SAAS,sBACrB,KAAK,OAAO,SAAS,SAAS,gBAC9B,KAAK,OAAO,SAAS,SAAS;AAElC;AAMO,SAAS,2BACd,MACA,UACS;AACT,MAAI,CAAC,aAAa,MAAM,OAAO,KAAK,KAAK,UAAU,SAAS,KAAK,CAAC,UAAU;AAC1E,WAAO;AAAA,EACT;AAEA,MAAI,KAAK,OAAO,SAAS,oBAAoB;AAC3C,WAAO;AAAA,EACT;AAEA,QAAM,aAAa,cAAc,KAAK,OAAO,QAAQ,QAAQ;AAC7D,MAAI,CAAC,YAAY;AACf,WAAO;A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ts","../src/utils.ts","../src/index.ts"],"sourcesContent":["{\n \"name\": \"@prisma-next/eslint-plugin\",\n \"version\": \"0.1.0-dev.8\",\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\": \"^20.0.0\",\n \"eslint\": \"^9.0.0\",\n \"tsup\": \"^8.3.0\",\n \"typescript\": \"^5.9.3\",\n \"vitest\": \"^2.1.1\"\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 = ['@prisma-next/sql-lane', 'packages/sql/lanes/sql-lane'] 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 { plugin };\nex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AEA,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"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prisma-next/eslint-plugin",
3
- "version": "0.1.0-dev.6",
3
+ "version": "0.1.0-dev.8",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
6
  "description": "ESLint plugin for Prisma Next query builder type checking and linting",
@@ -30,11 +30,11 @@
30
30
  "tsup": "^8.3.0",
31
31
  "typescript": "^5.9.3",
32
32
  "vitest": "^2.1.1",
33
- "@prisma-next/sql-contract-ts": "0.1.0-dev.6",
34
- "@prisma-next/sql-contract": "0.1.0-dev.6",
35
- "@prisma-next/sql-lane": "0.1.0-dev.6",
36
- "@prisma-next/sql-relational-core": "0.1.0-dev.6",
37
- "@prisma-next/sql-runtime": "0.1.0-dev.6"
33
+ "@prisma-next/sql-contract": "0.1.0-dev.8",
34
+ "@prisma-next/sql-contract-ts": "0.1.0-dev.8",
35
+ "@prisma-next/sql-lane": "0.1.0-dev.8",
36
+ "@prisma-next/sql-relational-core": "0.1.0-dev.8",
37
+ "@prisma-next/sql-runtime": "0.1.0-dev.8"
38
38
  },
39
39
  "peerDependencies": {
40
40
  "@typescript-eslint/parser": "^8.0.0",
@@ -47,6 +47,8 @@
47
47
  "test:coverage": "vitest run --coverage",
48
48
  "typecheck": "tsc --noEmit",
49
49
  "lint": "biome check . --config-path ../../../../biome.json --error-on-warnings",
50
+ "lint:fix": "biome check --write . --config-path ../../../../biome.json",
51
+ "lint:fix:unsafe": "biome check --write --unsafe . --config-path ../../../../biome.json",
50
52
  "clean": "node ../../../../scripts/clean.mjs"
51
53
  }
52
54
  }