File tree Expand file tree Collapse file tree 4 files changed +25
-8
lines changed Expand file tree Collapse file tree 4 files changed +25
-8
lines changed Original file line number Diff line number Diff line change @@ -114,7 +114,7 @@ There's a good explanation on setting up TypeScript ESLint support by Robert Coo
114
114
115
115
- ** eslintOptions** ` object ` :
116
116
117
- - Options that can be used to initialise ESLint. See https://eslint.org/docs/1.0.0/ developer-guide/nodejs-api#cliengine
117
+ - Options that can be used to initialise ESLint. See https://eslint.org/docs/developer-guide/nodejs-api#cliengine
118
118
119
119
- ** async** ` boolean ` :
120
120
True by default - ` async: false ` can block webpack's emit to wait for type checker/linter and to add errors to the webpack's compilation.
Original file line number Diff line number Diff line change 1
1
import * as path from 'path' ;
2
2
3
- import { LintReport } from './types/eslint' ;
3
+ import { LintReport , Options as EslintOptions } from './types/eslint' ;
4
4
import { throwIfIsInvalidSourceFileError } from './FsHelper' ;
5
5
6
- export function createEslinter ( eslintOptions : object ) {
6
+ export function createEslinter ( eslintOptions : EslintOptions ) {
7
7
// eslint-disable-next-line @typescript-eslint/no-var-requires
8
8
const { CLIEngine } = require ( 'eslint' ) ;
9
9
10
- // See https://eslint.org/docs/1.0.0/ developer-guide/nodejs-api#cliengine
10
+ // See https://eslint.org/docs/developer-guide/nodejs-api#cliengine
11
11
const eslinter = new CLIEngine ( eslintOptions ) ;
12
12
13
13
function getReport ( filepath : string ) : LintReport | undefined {
@@ -21,7 +21,13 @@ export function createEslinter(eslintOptions: object) {
21
21
return undefined ;
22
22
}
23
23
24
- return eslinter . executeOnFiles ( [ filepath ] ) ;
24
+ const lintReport = eslinter . executeOnFiles ( [ filepath ] ) ;
25
+
26
+ if ( eslintOptions && eslintOptions . fix ) {
27
+ eslinter . outputFixes ( lintReport ) ;
28
+ }
29
+
30
+ return lintReport ;
25
31
} catch ( e ) {
26
32
throwIfIsInvalidSourceFileError ( filepath , e ) ;
27
33
}
Original file line number Diff line number Diff line change @@ -21,6 +21,7 @@ import { getForkTsCheckerWebpackPluginHooks } from './hooks';
21
21
import { RUN , RunPayload , RunResult } from './RpcTypes' ;
22
22
import { Issue , IssueSeverity } from './issue' ;
23
23
import { VueOptions } from './types/vue-options' ;
24
+ import { Options as EslintOptions } from './types/eslint' ;
24
25
25
26
const checkerPluginName = 'fork-ts-checker-webpack-plugin' ;
26
27
@@ -39,8 +40,8 @@ namespace ForkTsCheckerWebpackPlugin {
39
40
tsconfig : string ;
40
41
compilerOptions : object ;
41
42
eslint : boolean ;
42
- /** Options to supply to eslint https://eslint.org/docs/1.0.0/ developer-guide/nodejs-api#cliengine */
43
- eslintOptions : object ;
43
+ /** Options to supply to eslint https://eslint.org/docs/developer-guide/nodejs-api#cliengine */
44
+ eslintOptions : EslintOptions ;
44
45
async : boolean ;
45
46
ignoreDiagnostics : number [ ] ;
46
47
ignoreLints : string [ ] ;
@@ -79,7 +80,7 @@ class ForkTsCheckerWebpackPlugin {
79
80
private tsconfig : string ;
80
81
private compilerOptions : object ;
81
82
private eslint = false ;
82
- private eslintOptions : object = { } ;
83
+ private eslintOptions : EslintOptions = { } ;
83
84
private ignoreDiagnostics : number [ ] ;
84
85
private ignoreLints : string [ ] ;
85
86
private ignoreLintWarnings : boolean ;
Original file line number Diff line number Diff line change @@ -34,3 +34,13 @@ export interface LintReport {
34
34
fixableErrorCount : number ;
35
35
fixableWarningCount : number ;
36
36
}
37
+
38
+ export interface Options {
39
+ fix ?: boolean ;
40
+
41
+ // The rest of the properties are not specified here because they are not
42
+ // directly used by this package and are instead just passed to eslint.
43
+ // We do this in order to avoid a dependency on @types /eslint (since the use
44
+ // of eslint is optional) and to avoid copying types from @types/eslint.
45
+ [ key : string ] : any ;
46
+ }
You can’t perform that action at this time.
0 commit comments