11/**
22 * Check that all new/modified functions in the current git diff use async/await.
3- * Fails with exit code 1 if any additions introduce callback-style functions or .then() chains .
3+ * Fails with exit code 1 if any additions introduce callback-style functions.
44 *
55 * Usage: node scripts/check-diff-async.mjs
66 * In CI: runs against the current PR diff (files changed vs base branch)
77 */
88import { execSync } from 'node:child_process' ;
99import { Project , SyntaxKind } from 'ts-morph' ;
1010
11- const CALLBACK_PARAM_PATTERN = / ^ ( c b | c a l l b a c k | n e x t | d o n e | e r r ) $ / i;
11+ const CALLBACK_PARAM_PATTERN = / ^ ( c b | c a l l b a c k | n e x t | d o n e ) $ / i;
1212
1313function getChangedJsFiles ( ) {
1414 const base = process . env . GITHUB_BASE_REF
@@ -112,20 +112,6 @@ for (const sourceFile of project.getSourceFiles()) {
112112 } ) ;
113113 }
114114 }
115-
116- const propertyAccesses = sourceFile . getDescendantsOfKind ( SyntaxKind . PropertyAccessExpression ) ;
117- for ( const access of propertyAccesses ) {
118- if ( access . getName ( ) !== 'then' ) continue ;
119- const line = access . getStartLineNumber ( ) ;
120- if ( addedLines . has ( line ) ) {
121- violations . push ( {
122- file : filePath ,
123- line,
124- type : 'then-chain' ,
125- detail : 'use await instead of .then()' ,
126- } ) ;
127- }
128- }
129115}
130116
131117if ( violations . length === 0 ) {
@@ -137,6 +123,6 @@ console.error(`✗ Found ${violations.length} async/await violation(s) in the di
137123for ( const v of violations ) {
138124 console . error ( ` ${ v . file } :${ v . line } [${ v . type } ] ${ v . detail } ` ) ;
139125}
140- console . error ( '\nNew code must use async/await instead of callbacks or .then() chains .' ) ;
126+ console . error ( '\nNew code must use async/await instead of callbacks.' ) ;
141127console . error ( 'See the async/await migration guide in CONTRIBUTING.md for help.' ) ;
142128process . exit ( 1 ) ;
0 commit comments