Angular-cli: Lint xml output is invalid

Created on 4 Jun 2019  路  10Comments  路  Source: angular/angular-cli

馃悶 Bug report

Command (mark with an x)

- [ ] new
- [ ] build
- [ ] serve
- [ ] test
- [ ] e2e
- [ ] generate
- [ ] add
- [ ] update
- [x] lint
- [ ] xi18n
- [ ] run
- [ ] config
- [ ] help
- [ ] version
- [ ] doc

Is this a regression?

No.

Description

As there's no way to specify output to a file (#4959) the only option is to redirect stdout. However, if there are multiple apps the checkstyle (and other formats) generate multiple xml documents.

馃敩 Minimal Reproduction

From a new project run

ng lint --format=checkstyle >checkstyle-result.xml

馃敟 Exception or Error

The output is invalid, being a concatenation of multiple documents:

<?xml version="1.0" encoding="utf-8"?><checkstyle version="4.3"><file name=".../src/environments/environment.ts"></file><file name=".../src/app/app.component.ts"></file><file name=".../src/app/app.module.ts"></file><file name=.../src/main.ts"></file><file name=".../src/polyfills.ts"></file><file name=".../src/test.ts"></file><file name=".../src/app/app.component.spec.ts"></file><file name=".../src/environments/environment.prod.ts"></file></checkstyle>
<?xml version="1.0" encoding="utf-8"?><checkstyle version="4.3"><file name=".../e2e/app.po.ts"></file><file name=".../e2e/app.e2e-spec.ts"></file></checkstyle>

馃實 Your Environment


Angular CLI: 8.0.1
Node: 10.15.3
OS: win32 x64
Angular: 8.0.0
... common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, router

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.800.1
@angular-devkit/build-angular     0.800.1
@angular-devkit/build-optimizer   0.800.1
@angular-devkit/build-webpack     0.800.1
@angular-devkit/core              8.0.1
@angular-devkit/schematics        8.0.1
@angular/cli                      8.0.1
@ngtools/webpack                  8.0.1
@schematics/angular               8.0.1
@schematics/update                0.800.1
rxjs                              6.5.2
typescript                        3.4.5
webpack                           4.30.0
devkibuild-angular lint low broken triage #1 bufix non-obvious

Most helpful comment

In such a case, it's on us to fix the issue.

All 10 comments

Hi, as a workaround you can lint a single project by passing the project as an argument.
Example

ng lint <project-name> --format=checkstyle >checkstyle-result.xml

As another workaround you can pipe to split.

ng lint --format=checkstyle | split -l 1 - checkstyle.xml.

Not sure if the CLI is the right place to address the issue. Maybe tslint's XML reporter is the one to handle the behavior?

ng lint is a multi-project command. It runs the lint target for all projects in the workspace. The issue is there is no first-class support within the builders for this so the CLI runs each target sequentially and output of each is concatenated. This works for human consumption but in the case of a structured output (XML in this case but JSON would have the same problem) the end result is invalid.

In such a case, it's on us to fix the issue.

@OrangeDog
Piping to split loses the information of the exit code of ng lint.
So e.g. maven-fronted-plugin will no longer break the build

@bohni you can set pipefail if you want that behaviour.
Fortunately I don't want it to break the build. The point of having xml output is for a further process to evaluate the build health.

@mgechev Any news on this issues?

We have this same issue with JSON format...
Or output looks like:

[{
 ...
}]
[{
 ...
}]

which results into any invalid JSON.

Closing since the TSLint builder is deprecated as part of the TSLint deprecation.

More info https://blog.angular.io/version-11-of-angular-now-available-74721b7952f7

Was this page helpful?
0 / 5 - 0 ratings