Skip to content

Commit 9295217

Browse files
alan-agius4filipesilva
authored andcommitted
fix(@angular-devkit/build-angular): fix duplicate lint messages when having multiple tsconfigs
Closes angular#11633
1 parent adb5861 commit 9295217

File tree

3 files changed

+29
-5
lines changed

3 files changed

+29
-5
lines changed

packages/angular_devkit/build_angular/src/tslint/index.ts

+9-4
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import * as tslint from 'tslint'; // tslint:disable-line:no-implicit-dependencie
2323
import * as ts from 'typescript'; // tslint:disable-line:no-implicit-dependencies
2424
import { stripBom } from '../angular-cli-files/utilities/strip-bom';
2525

26-
2726
export interface TslintBuilderOptions {
2827
tslintConfig?: string;
2928
tsConfig?: string | string[];
@@ -45,7 +44,7 @@ export default class TslintBuilder implements Builder<TslintBuilderOptions> {
4544
try {
4645
tslint = await import('tslint'); // tslint:disable-line:no-implicit-dependencies
4746
} catch {
48-
throw new Error('Unable to find TSLint. Ensure TSLint is installed.');
47+
throw new Error('Unable to find TSLint. Ensure TSLint is installed.');
4948
}
5049

5150
const version = tslint.Linter.VERSION && tslint.Linter.VERSION.split('.');
@@ -72,7 +71,7 @@ export default class TslintBuilder implements Builder<TslintBuilderOptions> {
7271
: null;
7372
const Linter = projectTslint.Linter;
7473

75-
let result;
74+
let result: undefined | tslint.LintResult;
7675
if (options.tsConfig) {
7776
const tsConfigs = Array.isArray(options.tsConfig) ? options.tsConfig : [options.tsConfig];
7877

@@ -82,9 +81,15 @@ export default class TslintBuilder implements Builder<TslintBuilderOptions> {
8281
if (result == undefined) {
8382
result = partial;
8483
} else {
84+
result.failures = result.failures
85+
.filter(curr => !partial.failures.some(prev => curr.equals(prev)))
86+
.concat(partial.failures);
87+
88+
// we are not doing much with 'errorCount' and 'warningCount'
89+
// apart from checking if they are greater than 0 thus no need to dedupe these.
8590
result.errorCount += partial.errorCount;
8691
result.warningCount += partial.warningCount;
87-
result.failures = result.failures.concat(partial.failures);
92+
8893
if (partial.fixes) {
8994
result.fixes = result.fixes ? result.fixes.concat(partial.fixes) : partial.fixes;
9095
}

packages/angular_devkit/build_angular/test/tslint/works_spec_large.ts

+16
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,22 @@ describe('Tslint Target', () => {
2525
).toPromise().then(done, done.fail);
2626
}, 30000);
2727

28+
it('should report lint error once', (done) => {
29+
host.writeMultipleFiles({'src/app/app.component.ts': 'const foo = "";\n' });
30+
const logger = new TestLogger('lint-error');
31+
32+
runTargetSpec(host, tslintTargetSpec, undefined, DefaultTimeout, logger).pipe(
33+
tap((buildEvent) => expect(buildEvent.success).toBe(false)),
34+
tap(() => {
35+
// this is to make sure there are no duplicates
36+
expect(logger.includes(`" should be \'\nERROR`)).toBe(false);
37+
38+
expect(logger.includes(`" should be '`)).toBe(true);
39+
expect(logger.includes(`Lint errors found in the listed files`)).toBe(true);
40+
}),
41+
).toPromise().then(done, done.fail);
42+
}, 30000);
43+
2844
it('supports exclude', (done) => {
2945
host.writeMultipleFiles(filesWithErrors);
3046
const overrides: Partial<TslintBuilderOptions> = { exclude: ['**/foo.ts'] };

tests/angular_devkit/build_angular/hello-world-app/angular.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,10 @@
115115
"lint": {
116116
"builder": "../../../../packages/angular_devkit/build_angular:tslint",
117117
"options": {
118-
"tsConfig": "src/tsconfig.app.json",
118+
"tsConfig": [
119+
"src/tsconfig.app.json",
120+
"src/tsconfig.spec.json"
121+
],
119122
"exclude": [
120123
"**/node_modules/**"
121124
]

0 commit comments

Comments
 (0)