import * as path from 'path' ; import type { TSESTree , TSESLint } from '@typescript-eslint/experimental-utils' ; import { RuleModule } from '@typescript-eslint/experimental-utils/dist/ts-eslint' ; import { isRequiredParserServices } from '../../src/utils/parser-services' ; import { RuleTester } from '../rule-tester' ; const rule = { meta : { type : 'problem' , messages : { missingTypeInformation : 'Missing type information' , availableTypeInformation : 'Available type information' , } , schema : [ ] , } , create ( context ) { return { Program : ( node ) => { const services = context . parserServices ; const hasTypeInformation = isRequiredParserServices ( services ) ; const message = hasTypeInformation ? 'availableTypeInformation' : 'missingTypeInformation' ; context . report ( { messageId : message , node , } ) ; } , } ; } , } ; const typeAgnosticRuleTester = new RuleTester ( { parser : '@typescript-eslint/parser' , } ) ; typeAgnosticRuleTester . run ( 'Type information is missing with default configuration' , rule , { valid : [ ] , invalid : [ { code : `console.log('Hello, world!');` , errors : [ { messageId : 'missingTypeInformation' , } , ] , } , ] , } ) ; const partiallyTypeAwareRuleTester = new RuleTester ( { parser : '@typescript-eslint/parser' , } ) ; partiallyTypeAwareRuleTester . run ( 'Type information is missing with typescript-eslint parser only' , rule , { valid : [ ] , invalid : [ { code : `console.log('Hello, world!');` , errors : [ { messageId : 'missingTypeInformation' , } , ] , } , ] , } ) ; const typeAwareRuleTester = new RuleTester ( { parser : '@typescript-eslint/parser' , parserOptions : { project : path . resolve ( `${ __dirname }/../resources/tsconfig.json` ) } , } ) ; typeAwareRuleTester . run ( 'Type information is available with typescript-eslint parser and tsconfig' , rule , { valid : [ ] , invalid : [ { code : `console.log('Hello, world!');` , filename : path . resolve ( `${ __dirname }/../resources/file.ts` ) , errors : [ { messageId : 'availableTypeInformation' , } , ] , } , ] , } ) ;