fileoverview import { HintContext , IHint } from 'hint' ; import { debug as d } from '@hint/utils-debug' ; import { Severity } from '@hint/utils-types' ; import { WebpackConfigEvents , WebpackConfigParse } from '@hint/parser-webpack-config' ; import { BabelConfigEvents , BabelConfigParsed } from '@hint/parser-babel-config' ; import meta from './meta/modules-false-babel' ; import { getMessage } from './i18n.import' ; const debug = d ( __filename ) ; export default class WebpackConfigModulesFalseBabel implements IHint { public static readonly meta = meta ; public constructor ( context ) { let webpackEvent ; let babelEvent ; const webpackConfigReceived = ( webpackConfigEvent ) => { debug ( `'parse::end::webpack-config' received` ) ; webpackEvent = webpackConfigEvent ; } ; const babelConfigReceived = ( babelConfigEvent ) => { debug ( `'parse::end::babel-config' received` ) ; babelEvent = babelConfigEvent ; } ; const validate = ( ) => { if ( ! webpackEvent ) { debug ( `no 'parse::end::webpack-config' received` ) ; return ; } if ( ! babelEvent ) { debug ( `no 'parse::end::babel-config' received` ) ; return ; } const version = parseInt ( webpackEvent . version ) ; const presets = babelEvent . config . presets ; if ( version < 2 || ! presets || presets . length === 0 ) { return ; } const modulesFalse = ( presets as any [ ] [ ] ) . filter ( ( preset ) => { return preset . length > 1 && preset [ 1 ] . modules === false ; } ) ; if ( modulesFalse . length === 0 ) { context . report ( babelEvent . resource , getMessage ( 'babelModules' , context . language ) , { severity : Severity . error } ) ; } } ; context . on ( 'parse::end::webpack-config' , webpackConfigReceived ) ; context . on ( 'parse::end::babel-config' , babelConfigReceived ) ; context . on ( 'scan::end' , validate ) ; } }