import type { TSESTree , TSESLint } from '@typescript-eslint/experimental-utils' ; import docsUrl from '../utils/docs-url' ; const rule = { meta : { messages : { smallSwitch : '"switch" statements should have at least 3 "case" clauses' , } , schema : [ ] , type : 'suggestion' , docs : { description : '"switch" statements should have at least 3 "case" clauses' , recommended : 'error' , url : docsUrl ( __filename ) , } , } , create ( context ) { return { SwitchStatement ( node ) { const switchStatement = node as TSESTree . SwitchStatement ; const { cases } = switchStatement ; const hasDefault = cases . some ( x => ! x . test ) ; if ( cases . length < 2 || ( cases . length === 2 && hasDefault ) ) { const firstToken = context . getSourceCode ( ) . getFirstToken ( node ) ; if ( firstToken ) { context . report ( { messageId : 'smallSwitch' , loc : firstToken . loc , } ) ; } } } , } ; } , } ; export = rule ;