fileoverview import { normalizeString } from '@hint/utils-string' ; import { fileExtension as getFileExtension } from '@hint/utils-fs' ; import { ElementFound , IHint } from 'hint/dist/src/lib/types' ; import { HintContext } from 'hint/dist/src/lib/hint-context' ; import { Severity } from '@hint/utils-types' ; import meta from './meta' ; import { getMessage } from './i18n.import' ; export default class ManifestFileExtensionHint implements IHint { public static readonly meta = meta ; public constructor ( context ) { const standardManifestFileExtension = 'webmanifest' ; const validate = ( { element , resource } ) => { if ( normalizeString ( element . getAttribute ( 'rel' ) ) === 'manifest' ) { const href = element . resolveUrl ( element . getAttribute ( 'href' ) || '' ) ; const fileExtension = getFileExtension ( normalizeString ( href ) || '' ) ; if ( fileExtension !== standardManifestFileExtension ) { const message = getMessage ( 'shouldHaveFileExtension' , context . language , standardManifestFileExtension ) ; const severity = fileExtension === 'json' ? Severity . hint : Severity . warning ; context . report ( resource , message , { content : fileExtension , element , severity } ) ; } } } ; context . on ( 'element::link' , validate ) ; } }