@@ -34,6 +34,7 @@ export class ESLintEngine extends Engine {
3434 private readonly delegateV8Engine : Engine ;
3535 private userConfigInfoCache : Map < string , UserConfigInfo > = new Map ( ) ;
3636 private eslintContextCache : Map < string , ESLintContext > = new Map ( ) ;
37+ private haveWarnedAboutESLint8 : boolean = false ;
3738
3839 constructor ( engineConfig : ESLintEngineConfig , delegateV8Engine : Engine ) {
3940 super ( ) ;
@@ -60,14 +61,20 @@ export class ESLintEngine extends Engine {
6061 const userConfigInfo : UserConfigInfo = this . getUserConfigInfo ( describeOptions . workspace ) ;
6162 this . emitLogEvent ( LogLevel . Fine , `Detected the following state regarding the user's ESLint configuration: ${ userConfigInfo } ` ) ;
6263
63- if ( this . shouldDelegateToV8 ( userConfigInfo ) ) {
64+ if ( userConfigInfo . getState ( ) === UserConfigState . LEGACY_USER_CONFIG ) {
65+ this . warnAboutUsingESLint8IfNeeded ( userConfigInfo ) ;
6466 return this . delegateV8Engine . describeRules ( describeOptions ) ;
65- } else if ( userConfigInfo . getUserIgnoreFile ( ) ) {
66- this . emitLogEvent ( LogLevel . Warn , getMessage ( 'IgnoringLegacyIgnoreFile' , userConfigInfo . getUserIgnoreFile ( ) ! ) ) ;
6767 }
6868
69- if ( userConfigInfo . getUserConfigFile ( ) ) { // TODO: Remove this as soon as we allow user's to supply their own flat config file.
70- this . emitLogEvent ( LogLevel . Warn , getMessage ( 'IgnoringFlatConfigFile' , userConfigInfo . getUserConfigFile ( ) ! ) ) ;
69+ if ( userConfigInfo . getChosenUserConfigFile ( ) ) {
70+ this . emitLogEvent ( LogLevel . Debug , getMessage ( 'ApplyingFlatConfigFile' , userConfigInfo . getChosenUserConfigFile ( ) ! ) ) ;
71+ } else if ( userConfigInfo . getDiscoveredConfigFile ( ) ) {
72+ this . emitLogEvent ( LogLevel . Info , getMessage ( 'UnusedESLintConfigFile' ,
73+ makeRelativeTo ( process . cwd ( ) , userConfigInfo . getDiscoveredConfigFile ( ) ! ) ,
74+ makeRelativeTo ( this . engineConfig . config_root , userConfigInfo . getDiscoveredConfigFile ( ) ! ) ) ) ;
75+ }
76+ if ( userConfigInfo . getChosenUserIgnoreFile ( ) ) {
77+ this . emitLogEvent ( LogLevel . Warn , getMessage ( 'IgnoringLegacyIgnoreFile' , userConfigInfo . getChosenUserIgnoreFile ( ) ! ) ) ;
7178 }
7279
7380 this . emitDescribeRulesProgressEvent ( 10 ) ;
@@ -97,7 +104,8 @@ export class ESLintEngine extends Engine {
97104 async runRules ( ruleNames : string [ ] , runOptions : RunOptions ) : Promise < EngineRunResults > {
98105 this . emitRunRulesProgressEvent ( 0 ) ;
99106 const userConfigInfo : UserConfigInfo = this . getUserConfigInfo ( runOptions . workspace ) ;
100- if ( this . shouldDelegateToV8 ( userConfigInfo ) ) {
107+ if ( userConfigInfo . getState ( ) === UserConfigState . LEGACY_USER_CONFIG ) {
108+ this . warnAboutUsingESLint8IfNeeded ( userConfigInfo ) ;
101109 return this . delegateV8Engine . runRules ( ruleNames , runOptions ) ;
102110 }
103111
@@ -129,6 +137,14 @@ export class ESLintEngine extends Engine {
129137 return engineResults ;
130138 }
131139
140+ private warnAboutUsingESLint8IfNeeded ( userConfigInfo : UserConfigInfo ) : void {
141+ if ( userConfigInfo . getState ( ) === UserConfigState . LEGACY_USER_CONFIG && ! this . haveWarnedAboutESLint8 ) {
142+ this . emitLogEvent ( LogLevel . Warn , getMessage ( 'DetectedLegacyConfig' ,
143+ userConfigInfo . getChosenUserConfigFile ( ) ?? userConfigInfo . getChosenUserIgnoreFile ( ) ! ) ) ;
144+ this . haveWarnedAboutESLint8 = true ;
145+ }
146+ }
147+
132148 private toViolations ( eslintResults : ESLint . LintResult [ ] ) : Violation [ ] {
133149 const violations : Violation [ ] = [ ] ;
134150 for ( const eslintResult of eslintResults ) {
@@ -161,17 +177,14 @@ export class ESLintEngine extends Engine {
161177 return this . userConfigInfoCache . get ( cacheKey ) ! ;
162178 }
163179
164- private shouldDelegateToV8 ( userConfigInfo : UserConfigInfo ) : boolean {
165- return userConfigInfo . getState ( ) === UserConfigState . LEGACY_USER_CONFIG ;
166- }
167-
168180 private async getESLintContext ( workspace ?: Workspace ) : Promise < ESLintContext > {
169181 const cacheKey : string = workspace ?. getWorkspaceId ( ) ?? process . cwd ( ) ;
170182 if ( ! this . eslintContextCache . has ( cacheKey ) ) {
171183 const userConfigInfo : UserConfigInfo = this . getUserConfigInfo ( workspace ) ;
172184 const eslintWorkspace : ESLintWorkspace = ESLintWorkspace . from ( workspace ,
173- this . engineConfig . config_root , this . engineConfig . file_extensions , userConfigInfo . getUserConfigFile ( ) ) ;
174- const context : ESLintContext = await calculateESLintContext ( this . engineConfig , eslintWorkspace ) ;
185+ this . engineConfig . config_root , this . engineConfig . file_extensions , userConfigInfo . getChosenUserConfigFile ( ) ) ;
186+ const context : ESLintContext = await calculateESLintContext ( this . engineConfig , eslintWorkspace ,
187+ userConfigInfo . getChosenUserConfigFile ( ) ) ;
175188 this . eslintContextCache . set ( cacheKey , context ) ;
176189 }
177190 return this . eslintContextCache . get ( cacheKey ) ! ;
@@ -267,3 +280,11 @@ function normalizeEndValue(endValue: number | undefined): number | undefined {
267280 /* istanbul ignore next */
268281 return endValue && endValue > 0 ? endValue : undefined ;
269282}
283+
284+
285+ function makeRelativeTo ( absFolderPath : string , absFilePath : string ) : string {
286+ absFolderPath = absFolderPath . endsWith ( path . sep ) ?
287+ /* istanbul ignore next */ absFolderPath : absFolderPath + path . sep ;
288+ return absFilePath . startsWith ( absFolderPath ) ?
289+ absFilePath . slice ( absFolderPath . length ) : /* istanbul ignore next */ absFilePath ;
290+ }
0 commit comments