import { JSDocTagInfo } from '@tsd/typescript' ; import { Diagnostic } from '../../interfaces' ; import { Handler } from './handler' ; import { makeDiagnostic , tsutils } from '../../utils' ; interface Options { filter ( tags ) : boolean ; message ( signature ) : string ; } const expectDeprecatedHelper = ( options ) : Handler => { return ( checker , nodes ) => { const diagnostics = [ ] ; if ( ! nodes ) { return diagnostics ; } for ( const node of nodes ) { const argument = node . arguments [ 0 ] ; const tags = tsutils . resolveJSDocTags ( checker , argument ) ; if ( ! tags || ! options . filter ( tags ) ) { continue ; } const message = tsutils . expressionToString ( checker , argument ) ; diagnostics . push ( makeDiagnostic ( node , options . message ( message ?? '?' ) ) ) ; } return diagnostics ; } ; } ; param checker param nodes return export const expectDeprecated = expectDeprecatedHelper ( { filter : tags => ! tags . has ( 'deprecated' ) , message : signature => `Expected \`${ signature }\` to be marked as \`@deprecated\`` } ) ; param checker param nodes return export const expectNotDeprecated = expectDeprecatedHelper ( { filter : tags => tags . has ( 'deprecated' ) , message : signature => `Expected \`${ signature }\` to not be marked as \`@deprecated\`` } ) ;