Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ignoreLintWarnings option #213

Merged
merged 8 commits into from
Feb 20, 2019
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ interface Options {
async: boolean;
ignoreDiagnostics: number[];
ignoreLints: string[];
ignoreLintWarnings: boolean;
reportFiles: string[];
colors: boolean;
logger: Logger;
Expand Down Expand Up @@ -84,6 +85,7 @@ class ForkTsCheckerWebpackPlugin {
private watch: string[];
private ignoreDiagnostics: number[];
private ignoreLints: string[];
private ignoreLintWarnings: boolean;
private reportFiles: string[];
private logger: Logger;
private silent: boolean;
Expand Down Expand Up @@ -144,6 +146,7 @@ class ForkTsCheckerWebpackPlugin {
typeof options.watch === 'string' ? [options.watch] : options.watch || [];
this.ignoreDiagnostics = options.ignoreDiagnostics || [];
this.ignoreLints = options.ignoreLints || [];
this.ignoreLintWarnings = options.ignoreLintWarnings === true;
this.reportFiles = options.reportFiles || [];
this.logger = options.logger || console;
this.silent = options.silent === true; // default false
Expand Down Expand Up @@ -792,7 +795,7 @@ class ForkTsCheckerWebpackPlugin {
file: message.file
};

if (message.isWarningSeverity()) {
if (message.isWarningSeverity() && !this.ignoreLintWarnings) {
compilation.warnings.push(formatted);
} else {
compilation.errors.push(formatted);
Expand All @@ -808,6 +811,20 @@ class ForkTsCheckerWebpackPlugin {
return function noopEmitCallback() {};
}

private getLoggerMessage(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this change - could I request one more tweak to avoid confusion please?

The name and the return type of the method suggests a logger message is passed back. In reality no value is ever returned I think? Could this be tweaked to make intention a bit clearer please?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops yes, you're totally right. Will update.

message: NormalizedMessage,
formattedMessage: string
): string | void {
if (message.isWarningSeverity()) {
if (this.ignoreLintWarnings) {
return;
}
this.logger.warn(formattedMessage);
} else {
this.logger.error(formattedMessage);
}
}

private createDoneCallback() {
return function doneCallback(this: ForkTsCheckerWebpackPlugin) {
if (!this.elapsed) {
Expand Down Expand Up @@ -838,9 +855,7 @@ class ForkTsCheckerWebpackPlugin {
(this.lints || []).concat(this.diagnostics).forEach(message => {
const formattedMessage = this.formatter(message, this.useColors);

message.isWarningSeverity()
? this.logger.warn(formattedMessage)
: this.logger.error(formattedMessage);
this.getLoggerMessage(message, formattedMessage);
});
}
if (!this.diagnostics.length) {
Expand Down
15 changes: 15 additions & 0 deletions test/integration/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,21 @@ function makeCommonTests(useTypescriptIncrementalApi) {
expect(plugin.watch).to.deep.equal(['/test']);
});

it('should not print warnings when ignoreLintWarnings passed as option', function(callback) {
const fileName = 'lintingError2';
helpers.testLintAutoFixTest(
callback,
fileName,
{
tslint: true,
ignoreLintWarnings: true
},
(err, stats) => {
expect(stats.compilation.warnings.length).to.be.eq(0);
}
);
});

it('should find semantic errors', function(callback) {
var compiler = createCompiler({
tsconfig: 'tsconfig-semantic-error-only.json'
Expand Down