Skip to content

Commit 903d1de

Browse files
Lizjohnnyreilly
authored andcommitted
ignoreLintWarnings option (#213)
* ignoreLintWarnings option * revert format - prettier? * add test for option * do nothing if warning and ignore flag passed * clean up naming, return type * bump version, add changelog entry * update readme
1 parent 8c339d3 commit 903d1de

File tree

5 files changed

+42
-5
lines changed

5 files changed

+42
-5
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## v1.0.0-alpha.7
2+
3+
* [Add ignoreLintWarnings option](https://github.com/Realytics/fork-ts-checker-webpack-plugin/pull/213)
4+
15
## v1.0.0-alpha.6
26

37
* [don't directly depend upon typescript](https://github.com/Realytics/fork-ts-checker-webpack-plugin/pull/208)

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ List of typescript diagnostic codes to ignore.
8282
* **ignoreLints** `string[]`:
8383
List of tslint rule names to ignore.
8484

85+
* **ignoreLintWarnings** `boolean`:
86+
If true, will ignore all lint warnings.
87+
8588
* **reportFiles** `string[]`:
8689
Only report errors on files matching these glob patterns. This can be useful when certain types definitions have errors that are not fatal to your application. Default: `[]`.
8790

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "fork-ts-checker-webpack-plugin",
3-
"version": "1.0.0-alpha.6",
3+
"version": "1.0.0-alpha.7",
44
"description": "Runs typescript type checker and linter on separate process.",
55
"main": "lib/index.js",
66
"types": "lib/index.d.ts",

src/index.ts

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ interface Options {
3838
async: boolean;
3939
ignoreDiagnostics: number[];
4040
ignoreLints: string[];
41+
ignoreLintWarnings: boolean;
4142
reportFiles: string[];
4243
colors: boolean;
4344
logger: Logger;
@@ -84,6 +85,7 @@ class ForkTsCheckerWebpackPlugin {
8485
private watch: string[];
8586
private ignoreDiagnostics: number[];
8687
private ignoreLints: string[];
88+
private ignoreLintWarnings: boolean;
8789
private reportFiles: string[];
8890
private logger: Logger;
8991
private silent: boolean;
@@ -144,6 +146,7 @@ class ForkTsCheckerWebpackPlugin {
144146
typeof options.watch === 'string' ? [options.watch] : options.watch || [];
145147
this.ignoreDiagnostics = options.ignoreDiagnostics || [];
146148
this.ignoreLints = options.ignoreLints || [];
149+
this.ignoreLintWarnings = options.ignoreLintWarnings === true;
147150
this.reportFiles = options.reportFiles || [];
148151
this.logger = options.logger || console;
149152
this.silent = options.silent === true; // default false
@@ -792,7 +795,7 @@ class ForkTsCheckerWebpackPlugin {
792795
file: message.file
793796
};
794797

795-
if (message.isWarningSeverity()) {
798+
if (message.isWarningSeverity() && !this.ignoreLintWarnings) {
796799
compilation.warnings.push(formatted);
797800
} else {
798801
compilation.errors.push(formatted);
@@ -808,6 +811,20 @@ class ForkTsCheckerWebpackPlugin {
808811
return function noopEmitCallback() {};
809812
}
810813

814+
private printLoggerMessage(
815+
message: NormalizedMessage,
816+
formattedMessage: string
817+
): void {
818+
if (message.isWarningSeverity()) {
819+
if (this.ignoreLintWarnings) {
820+
return;
821+
}
822+
this.logger.warn(formattedMessage);
823+
} else {
824+
this.logger.error(formattedMessage);
825+
}
826+
}
827+
811828
private createDoneCallback() {
812829
return function doneCallback(this: ForkTsCheckerWebpackPlugin) {
813830
if (!this.elapsed) {
@@ -838,9 +855,7 @@ class ForkTsCheckerWebpackPlugin {
838855
(this.lints || []).concat(this.diagnostics).forEach(message => {
839856
const formattedMessage = this.formatter(message, this.useColors);
840857

841-
message.isWarningSeverity()
842-
? this.logger.warn(formattedMessage)
843-
: this.logger.error(formattedMessage);
858+
this.printLoggerMessage(message, formattedMessage);
844859
});
845860
}
846861
if (!this.diagnostics.length) {

test/integration/index.spec.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,21 @@ function makeCommonTests(useTypescriptIncrementalApi) {
7575
expect(plugin.watch).to.deep.equal(['/test']);
7676
});
7777

78+
it('should not print warnings when ignoreLintWarnings passed as option', function(callback) {
79+
const fileName = 'lintingError2';
80+
helpers.testLintAutoFixTest(
81+
callback,
82+
fileName,
83+
{
84+
tslint: true,
85+
ignoreLintWarnings: true
86+
},
87+
(err, stats) => {
88+
expect(stats.compilation.warnings.length).to.be.eq(0);
89+
}
90+
);
91+
});
92+
7893
it('should find semantic errors', function(callback) {
7994
var compiler = createCompiler({
8095
tsconfig: 'tsconfig-semantic-error-only.json'

0 commit comments

Comments
 (0)