Angular-cli: Feature: Add --out flag to ng lint

Created on 23 Feb 2017  路  16Comments  路  Source: angular/angular-cli

Use-case

In our CI we use SonarQube and the TypeScript plugin which can parse the tslint output and translate it into issues. To generate the output I want to use ng lint.

Request

Because there is no way to store the output of ng lint --format json into a valid json file it would be useful to add the --out argument and pass it to tslint.

Most helpful comment

This was never actually added from what I can see, please revisit this. It would be a great simplification.

All 16 comments

The next release will allow you to properly redirect the output to a file.
ref: https://github.com/angular/angular-cli/pull/4917

Closing as answered. Thanks to @moritz-h for implementing it!

Awesome. Thank you!

@filipesilva @clydin @philipooo
Thanks for mentioning my fix. But this was only the easy small part I did. There is a even bigger issue for using ng lint formatted output in CI. See #4849. There I found the error source, but I don't know how it could be fixed. I just have a workaround for pmd format:

ng lint --format pmd > result.xml
tr -d '\n' < result.xml > result-fix.xml # all text in one line for sed
sed -i -e 's/<\/pmd><pmd version="tslint">//g' result-fix.xml # fix xml

Hello, which release has the --out option in? I can't seem to find it in the code.
I don't see it within the latest beta tag:
https://github.com/angular/angular-cli/blob/v1.5.0-beta.2/packages/%40angular/cli/commands/lint.ts

Thanks for the workaround, @moritz-h. I had some trouble on Windows but got it working with two commands:

ng lint --format pmd > result.xml
sed -i -r -n -e "/<pmd version=\"tslint\">/,${p}" result.xml

@LayZeeDK The problem with messed up xml is fixed long time ago. See the issue I referenced above.
The tr and sed workaround is not needed anymore, just do:

ng lint --format pmd > result.xml

This was never actually added from what I can see, please revisit this. It would be a great simplification.

It would be really great to have that "--output" option.

Right now the only possibility to store the tslint result in a file is by redirecting standard output stream to a file, but it sometimes includes the ANSI escapes (colors) in the generated file, making the file not well-formatted. Example:
ng lint wp --format checkstyle --force > ../target/tslint-result.xml

Thanks

@GregorioPerego It appears redirecting to a file is the intended way to do this. The fix mentioned above by @moritz-h was to enable that. If the format is non-human readable and there are illegal characters in the output then that would be a separate bug on it's own.

ng lint --format json > lint.json
The content of the file is not json as all the other log output is there. --silent hides the json and leaves the debug output.

@rtaft I think you are encoutnering https://github.com/angular/angular-cli/issues/12674

@westonpace yes, that sounds about right, thank you

Hey guys, I think you should reconsider this issue.

Given the default setup creates two projects ("example" and "example-e2e") when we run

ng lint --format junit > lint.xml

the result file ends up containing both xml documents like so

<?xml version="1.0" encoding="utf-8"?><testsuites package="tslint"></testsuites>
<?xml version="1.0" encoding="utf-8"?><testsuites package="tslint"></testsuites>

@leandro-manifesto that's a separate defect that needs to be fixed.

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