import { CleanRegexRule , createRuleListener , getDocUrl } from "../rules-util" ; import { hasSomeDescendant } from "../ast-util" ; export default { meta : { type : "problem" , docs : { description : "Disallow quantifiers with a maximum of 0." , url : getDocUrl ( "no-zero-quantifier" ) , } , fixable : "code" , } , create ( context ) { return createRuleListener ( ( { visitAST , removeElement , reportElement } ) => { visitAST ( { onQuantifierEnter ( node ) { if ( node . max === 0 ) { let props ; if ( hasSomeDescendant ( node , n => n . type === "CapturingGroup" ) ) { props = reportElement ( node ) ; } else { props = removeElement ( node ) ; } context . report ( { message : "The quantifier and the quantified element can be removed." , ... props , } ) ; } } , } ) ; } ) ; } , } as CleanRegexRule ;