Skip to content

fix(@angular-devkit/build-angular): fix duplicate lint messages #11636

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

Merged
merged 1 commit into from
Jul 24, 2018
Merged
Show file tree
Hide file tree
Changes from all 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
13 changes: 9 additions & 4 deletions packages/angular_devkit/build_angular/src/tslint/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import * as tslint from 'tslint'; // tslint:disable-line:no-implicit-dependencie
import * as ts from 'typescript'; // tslint:disable-line:no-implicit-dependencies
import { stripBom } from '../angular-cli-files/utilities/strip-bom';


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

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

let result;
let result: undefined | tslint.LintResult;
if (options.tsConfig) {
const tsConfigs = Array.isArray(options.tsConfig) ? options.tsConfig : [options.tsConfig];

Expand All @@ -82,9 +81,15 @@ export default class TslintBuilder implements Builder<TslintBuilderOptions> {
if (result == undefined) {
result = partial;
} else {
result.failures = result.failures
.filter(curr => !partial.failures.some(prev => curr.equals(prev)))
.concat(partial.failures);

// we are not doing much with 'errorCount' and 'warningCount'
// apart from checking if they are greater than 0 thus no need to dedupe these.
result.errorCount += partial.errorCount;
result.warningCount += partial.warningCount;
result.failures = result.failures.concat(partial.failures);

if (partial.fixes) {
result.fixes = result.fixes ? result.fixes.concat(partial.fixes) : partial.fixes;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,22 @@ describe('Tslint Target', () => {
).toPromise().then(done, done.fail);
}, 30000);

it('should report lint error once', (done) => {
host.writeMultipleFiles({'src/app/app.component.ts': 'const foo = "";\n' });
const logger = new TestLogger('lint-error');

runTargetSpec(host, tslintTargetSpec, undefined, DefaultTimeout, logger).pipe(
tap((buildEvent) => expect(buildEvent.success).toBe(false)),
tap(() => {
// this is to make sure there are no duplicates
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is due that duplicate messages are within the same entry since under the hood we are using tslint formatter to format the messages with will convert and array of results to a string

expect(logger.includes(`" should be \'\nERROR`)).toBe(false);

expect(logger.includes(`" should be '`)).toBe(true);
expect(logger.includes(`Lint errors found in the listed files`)).toBe(true);
}),
).toPromise().then(done, done.fail);
}, 30000);

it('supports exclude', (done) => {
host.writeMultipleFiles(filesWithErrors);
const overrides: Partial<TslintBuilderOptions> = { exclude: ['**/foo.ts'] };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,10 @@
"lint": {
"builder": "../../../../packages/angular_devkit/build_angular:tslint",
"options": {
"tsConfig": "src/tsconfig.app.json",
"tsConfig": [
"src/tsconfig.app.json",
"src/tsconfig.spec.json"
],
"exclude": [
"**/node_modules/**"
]
Expand Down