@@ -6,29 +6,24 @@ import {
66 inferQueryResult ,
77} from "../inferQueryResult.js" ;
88import type { RuleOptions } from "../ruleOptions.js" ;
9- import { getQueryValue , stringifyNode } from "../utils.js" ;
9+ import { getQueryValue , makeRuleListener , stringifyNode } from "../utils.js" ;
1010
1111type ColumnInfoWithUserType = ColumnInfo & { userTSTypeAnnotation ?: string } ;
1212
1313export function createTypedResultRule ( options : RuleOptions ) {
1414 return ESLintUtils . RuleCreator . withoutDocs ( {
1515 create ( context ) {
16- return {
17- 'CallExpression[callee.type=MemberExpression][callee.property.name="prepare"][arguments.length=1]' (
18- node : Omit < TSESTree . CallExpression , "arguments" | "callee" > & {
19- arguments : [ TSESTree . CallExpression [ "arguments" ] [ 0 ] ] ;
20- callee : TSESTree . MemberExpression ;
21- } ,
22- ) {
16+ return makeRuleListener ( {
17+ handleQuery ( { queryNode, callee, typeArguments, rootNode } ) {
2318 const val = getQueryValue (
24- node . arguments [ 0 ] ,
25- context . sourceCode . getScope ( node . arguments [ 0 ] ) ,
19+ queryNode ,
20+ context . sourceCode . getScope ( queryNode ) ,
2621 ) ;
2722 if ( typeof val ?. value !== "string" ) {
2823 return ;
2924 }
3025
31- const databaseName = stringifyNode ( node . callee . object ) ;
26+ const databaseName = stringifyNode ( callee . object ) ;
3227 if ( ! databaseName ) {
3328 return ;
3429 }
@@ -46,7 +41,6 @@ export function createTypedResultRule(options: RuleOptions) {
4641 return ;
4742 }
4843
49- const typeArguments = node . typeArguments ;
5044 if ( columns . length === 0 ) {
5145 const inputNode = typeArguments ?. params [ 0 ] ;
5246 const resultNode = typeArguments ?. params [ 1 ] ;
@@ -69,10 +63,10 @@ export function createTypedResultRule(options: RuleOptions) {
6963 if ( ! typeArguments ) {
7064 context . report ( {
7165 messageId : "missingResultType" ,
72- node,
66+ node : rootNode ,
7367 * fix ( fixer ) {
7468 yield fixer . insertTextAfter (
75- node . callee ,
69+ callee ,
7670 `<[], ${ columnsToObjectLiteralText ( columns ) } >` ,
7771 ) ;
7872 } ,
@@ -172,7 +166,7 @@ export function createTypedResultRule(options: RuleOptions) {
172166 return ;
173167 }
174168 } ,
175- } ;
169+ } ) ;
176170 } ,
177171 meta : {
178172 messages : {
0 commit comments