Angular-cli: The "--format" flag of the "ng lint"-command produces invalid output.

Created on 21 Oct 2018  路  7Comments  路  Source: angular/angular-cli

Bug Report or Feature Request (mark with an x)

- [X] bug report -> please search issues before submitting
- [ ] feature request

Command (mark with an x)

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

Versions

Angular CLI: 7.0.2
Node: 8.11.1
OS: linux x64 (Debian 9)
Angular: 7.0.0
... animations, cdk, common, compiler, compiler-cli, core, forms
... http, language-service, material, platform-browser
... platform-browser-dynamic, router

@angular-devkit/architect 0.10.2
@angular-devkit/build-angular 0.10.2
@angular-devkit/build-optimizer 0.10.2
@angular-devkit/build-webpack 0.10.2
@angular-devkit/core 7.0.2
@angular-devkit/schematics 7.0.2
@angular/cli 7.0.2
@ngtools/webpack 7.0.2
@schematics/angular 7.0.2
@schematics/update 0.10.2
rxjs 6.3.3
typescript 3.1.3
webpack 4.19.1

Description

The --format flag produces invalid output.

Repro steps

  1. Create a new angular project
  2. Execute ng lint --format checkstyle [name of the angular project]

The log given by the failure

Linting "[name of the angular project]"...
<?xml version="1.0" encoding="utf-8"?><checkstyle version="4.3"></checkstyle>

Desired functionality

The output should not contain Linting "[name of the angular project]"...

devkibuild-angular low regression bufix

Most helpful comment

this problem breaks several of my builds currently, as well...

parseable output formats should never have this kind of text injection.. at the very least, they should have a switch to allow us to exempt our output from such things. For example, making the --silent switch (which already exists on this command) force this text logging to be quiet.

As a temporary workaround, the following two things worked for me:

ng lint --force --format=checkstyle | sed 's/Linting.*$//' > ../ci/output-tslint.xml

or

ng lint --force --format=checkstyle | sed '1d' > ../ci/output-tslint.xml

where ../ci/output-tslint.xml is the generated checkstyle format file you are needing for your build process or whatnot..

All 7 comments

I faced the exact problem, this started to appear after angular 7 update for me.

It seems that the commit aa25a3344815ba609cdc2f3175469b54c3a14e2f is the problem

The problem is caused by

https://github.com/angular/angular-cli/commit/aa25a3344815ba609cdc2f3175469b54c3a14e2f#diff-de67da9e5a0afd9e30e8fa8a17ada2ceR18

protected async runSingleTarget(targetSpec: TargetSpecifier, options: string[]) {
    this.logger.info(`Linting ${JSON.stringify(targetSpec.project)}...`);

    return super.runSingleTarget(targetSpec, options);
}

Specifically

this.logger.info(`Linting ${JSON.stringify(targetSpec.project)}...`);

Output (ng lint --format=json):

Linting "app"...
[]

Solution:
Only log when the format is one of the non-parseable formats.

this problem breaks several of my builds currently, as well...

parseable output formats should never have this kind of text injection.. at the very least, they should have a switch to allow us to exempt our output from such things. For example, making the --silent switch (which already exists on this command) force this text logging to be quiet.

As a temporary workaround, the following two things worked for me:

ng lint --force --format=checkstyle | sed 's/Linting.*$//' > ../ci/output-tslint.xml

or

ng lint --force --format=checkstyle | sed '1d' > ../ci/output-tslint.xml

where ../ci/output-tslint.xml is the generated checkstyle format file you are needing for your build process or whatnot..

I also see 'All files pass linting.' at the end of the output

The workaround from @corvinrok ported to windows systems:

@powershell -NoProfile -ExecutionPolicy Unrestricted -Command "& { ng lint --force --format=checkstyle  | %{$_ -replace 'Linting.*$', ''} | sc ../ci/output-tslint.xml }"

or

@powershell -NoProfile -ExecutionPolicy Unrestricted -Command "& { ng lint --force --format=checkstyle  | select -Skip 1 | sc ../ci/output-tslint.xml }"

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

_This action has been performed automatically by a bot._

Was this page helpful?
0 / 5 - 0 ratings

Related issues

donaldallen picture donaldallen  路  3Comments

jmurphzyo picture jmurphzyo  路  3Comments

sysmat picture sysmat  路  3Comments

JanStureNielsen picture JanStureNielsen  路  3Comments

5amfung picture 5amfung  路  3Comments