77 * Licensed under the MIT license.
88 */
99
10- import { arrForEach , dumpObj , isString } from "@nevware21/ts-utils" ;
11- import { getGruntMultiTaskOptions , resolveValue , deepMerge , getTsConfigDetails , IGruntWrapperOptions , GruntWrapper } from "@nevware21/grunt-plugins-shared-utils" ;
10+ import { arrForEach , dumpObj , isIterable , isIterator , isString , iterForOf } from "@nevware21/ts-utils" ;
11+ import { getGruntMultiTaskOptions , resolveValue , deepMerge , getTsConfigDetails , IGruntWrapperOptions , GruntWrapper , resolveValueAsync , ITsOption } from "@nevware21/grunt-plugins-shared-utils" ;
1212import { ESLintRunner } from "./ESLintRunner" ;
1313import { IEslintTsPluginTaskOptions } from "./interfaces/IEslintTsPluginOptions" ;
1414import { Linter } from "eslint" ;
@@ -35,39 +35,70 @@ function _registerTask(inst: IGrunt, taskName: string) {
3535 grunt . logVerbose ( ( " Options: [" + dumpObj ( options ) + "]" ) . cyan ) ;
3636 grunt . logVerbose ( ( " Config : [" + dumpObj ( this . data ) + "]" ) . cyan ) ;
3737 }
38-
39- let tsconfig = resolveValue ( taskOptions . tsconfig , options . tsconfig ) ;
40- // eslint-disable-next-line security/detect-non-literal-fs-filename
41- if ( ! tsconfig || ! grunt . file . exists ( tsconfig ) ) {
42- grunt . logError ( "The TSConfig project file [" + tsconfig + "] does not exist" ) ;
43- return false ;
44- }
4538
46- const eslintOptions : IESLintRunnerOptions = {
47- format : resolveValue ( taskOptions . format , options . format , "codeframe" ) ,
48- logOutput : resolveValue ( taskOptions . logOutput , options . logOutput ) ,
49- fix : resolveValue ( taskOptions . fix , options . fix ) ,
50- suppressWarnings : resolveValue ( taskOptions . suppressWarnings , options . suppressWarnings ) ,
51- quiet : resolveValue ( taskOptions . quiet , options . quiet ) ,
52- outputFile : resolveValue ( taskOptions . outputFile , options . outputFile ) ,
53- disableOutputFixes : resolveValue ( taskOptions . disableOutputFixes , options . disableOutputFixes )
54- } ;
55-
56- const maxWarnings = resolveValue ( taskOptions . maxWarnings , options . maxWarnings ) ;
57- grunt . logDebug ( "grunt-eslint-typescript options: " + dumpObj ( eslintOptions , true ) ) ;
58-
59- let tsDetails = getTsConfigDetails ( grunt , tsconfig , ! eslintOptions . suppressWarnings ) ;
60- arrForEach ( tsDetails , ( tsDetail ) => {
61- if ( tsDetail ) {
62- tsDetail . addFiles ( options . src ) ;
63- tsDetail . addFiles ( taskOptions . src ) ;
39+ done = this . async ( ) ;
40+ ( async function runEslint ( ) {
41+ let tsDefs : Array < string | ITsOption > = [ ] ;
42+ let tsconfig = await resolveValueAsync ( taskOptions . tsconfig , options . tsconfig ) ;
43+
44+ if ( ! tsconfig ) {
45+ if ( isString ( tsconfig ) ) {
46+ tsDefs . push ( tsconfig ) ;
47+ } else if ( Array . isArray ( tsconfig ) ) {
48+ tsDefs = tsconfig ;
49+ } else if ( isIterable ( tsconfig ) || isIterator ( tsconfig ) ) {
50+ iterForOf ( tsconfig , ( value ) => {
51+ tsDefs . push ( value ) ;
52+ } ) ;
53+ } else {
54+ grunt . logError ( "The TSConfig project file [" + tsconfig + "] does not exist" ) ;
55+ return false ;
56+ }
6457 }
65- } ) ;
58+
59+ for ( let lp = 0 ; lp < tsDefs . length ; lp ++ ) {
60+ // eslint-disable-next-line security/detect-non-literal-fs-filename, security/detect-object-injection
61+ let tsDef = tsDefs [ lp ] ;
6662
67- let results : IESLintRunnerResponse = null ;
63+ if ( isString ( tsDef ) ) {
64+ if ( ! grunt . file . exists ( tsDef ) ) {
65+ // eslint-disable-next-line security/detect-object-injection
66+ grunt . logError ( "The TSConfig project file [" + tsDefs [ lp ] + "] does not exist" ) ;
67+ return false ;
68+ }
69+ } else if ( tsDef . name ) {
70+ if ( ! grunt . file . exists ( tsDef . name ) ) {
71+ grunt . logError ( "The TSConfig project file [" + tsDef . name + "] does not exist" ) ;
72+ return false ;
73+ }
74+ }
75+ }
76+
77+ const eslintOptions : IESLintRunnerOptions = {
78+ format : resolveValue ( taskOptions . format , options . format , "codeframe" ) ,
79+ logOutput : resolveValue ( taskOptions . logOutput , options . logOutput ) ,
80+ fix : resolveValue ( taskOptions . fix , options . fix ) ,
81+ suppressWarnings : resolveValue ( taskOptions . suppressWarnings , options . suppressWarnings ) ,
82+ quiet : resolveValue ( taskOptions . quiet , options . quiet ) ,
83+ outputFile : resolveValue ( taskOptions . outputFile , options . outputFile ) ,
84+ disableOutputFixes : resolveValue ( taskOptions . disableOutputFixes , options . disableOutputFixes )
85+ } ;
86+
87+ const maxWarnings = resolveValue ( taskOptions . maxWarnings , options . maxWarnings ) ;
88+ grunt . logDebug ( "grunt-eslint-typescript options: " + dumpObj ( eslintOptions , true ) ) ;
6889
69- done = this . async ( ) ;
70- ( async function runEslint ( ) {
90+ let tsDetails = getTsConfigDetails ( grunt , tsDefs , ! eslintOptions . suppressWarnings ) ;
91+ arrForEach ( tsDetails , ( tsDetail ) => {
92+ if ( tsDetail ) {
93+ tsDetail . addFiles ( options . src ) ;
94+ tsDetail . addFiles ( taskOptions . src ) ;
95+ }
96+ } ) ;
97+
98+ let results : IESLintRunnerResponse = null ;
99+
100+
101+
71102 const eslint = new ESLintRunner ( grunt , eslintOptions ) ;
72103
73104 // Merge all of the additional Config into the linter
@@ -140,7 +171,7 @@ function _registerTask(inst: IGrunt, taskName: string) {
140171 } ) ;
141172
142173 } catch ( e ) {
143- inst . log . error ( "EsLint catch: " + e ) ;
174+ inst . log . error ( "EsLint catch:: " + e + "\n" + dumpObj ( e ) ) ;
144175 if ( done ) {
145176 done ( false ) ;
146177 }
0 commit comments