import { Root } from "postcss" ; import { missingRequiredKaizenImport } from "../messages" ; import { KaizenToken , Options , RuleDefinition } from "../types" ; import { addImport , getCurrentImports } from "../util/importUtils" ; import { walkKaizenTokens } from "../util/walkers" ; export const allUsedTokensMustBeImported = { name : "all-used-tokens-must-be-imported" , ruleFunction : ( stylesheetNode , options ) => { const foundKaizenTokens = new Map < string , KaizenToken > ( ) ; walkKaizenTokens ( stylesheetNode , ( { variable } ) => { foundKaizenTokens . set ( variable . name , variable . kaizenToken ) ; } ) ; const currentImports = getCurrentImports ( stylesheetNode ) ; const requiredImports = new Set ( Array . from ( foundKaizenTokens . values ( ) ) . map ( token => options . language === "less" ? token . lessModulePath : token . sassModulePath ) ) ; requiredImports . forEach ( path => { if ( ! currentImports . has ( path ) ) { if ( options . fix ) { addImport ( stylesheetNode , path ) ; } else { options . reporter ( { message : missingRequiredKaizenImport ( path ) , node : stylesheetNode , autofixAvailable : true , } ) ; } } } ) ; } , } ;