Skip to content
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

Feature: Add a way to output lint result to a file #13497

Closed
PodgeHeavin opened this issue Jan 22, 2019 · 13 comments · Fixed by #13510
Closed

Feature: Add a way to output lint result to a file #13497

PodgeHeavin opened this issue Jan 22, 2019 · 13 comments · Fixed by #13510
Labels
area: devkit/build-angular freq1: low Only reported by a handful of users who observe it rarely severity5: regression type: bug/fix
Milestone

Comments

@PodgeHeavin
Copy link

PodgeHeavin commented Jan 22, 2019

🚀 Feature request

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

Description

ng lint --format=json > issues.json
Worked previously as describe here: #4959
Worked for outputting results to json or any format.

In Angular 7 there was the addition of color to the output of lint results. This has broken the above workaround for outputting to a file.

what was previously like:

[
    {
        "endPosition": {
            "character": 144,
            "line": 8,
            "position": 361
        },
        "failure": "Exceeds maximum line length of 140",
        "name": "C:/myProject/src/app/modeling.component.ts",
        "ruleName": "max-line-length",
        "ruleSeverity": "ERROR",
        "startPosition": {
            "character": 0,
            "line": 8,
            "position": 217
        }
    }
]

is now like so

�[37m[
    {
        "endPosition": {
            "character": 144,
            "line": 8,
            "position": 361
        },
        "failure": "Exceeds maximum line length of 140",
        "name": "C:/myProject/src/spp/modeling.component.ts",
        "ruleName": "max-line-length",
        "ruleSeverity": "ERROR",
        "startPosition": {
            "character": 0,
            "line": 8,
            "position": 217
        }
    }
]�[39m

Solution I would like

I would like an option added to ng lint to output to a file easily

Workaround

"ng lint --format=json | sed -r \"s/\\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[mGK]//g\" > issues.json"
Which is ugly but works

@mgechev
Copy link
Member

mgechev commented Jan 22, 2019

I'd approach similarly - just redirect stdout to a file. If you want to have a more "native" feel, I'd recommend you to implement a custom tslint formatter and update your configuration in tslint.json.

Although this feature seems useful in some specific scenarios, we need to be careful expanding the scope of the CLI with functionalities which have good pre-existing solutions.

I hope this helps! Thanks :)

@mgechev mgechev closed this as completed Jan 22, 2019
@PodgeHeavin
Copy link
Author

What is the point of the json ouput option if the cli is printing it unusable as actual json. Makes no sense to me. This was working in Angular 6 but has broken in Angular 7

@mgechev mgechev reopened this Jan 22, 2019
@mgechev
Copy link
Member

mgechev commented Jan 22, 2019

@alan-agius4 pointed out that this is a regression; reopening.

@alan-agius4 alan-agius4 added type: bug/fix freq1: low Only reported by a handful of users who observe it rarely severity5: regression area: devkit/build-angular labels Jan 22, 2019
@ngbot ngbot bot modified the milestone: Backlog Jan 22, 2019
@alan-agius4
Copy link
Collaborator

alan-agius4 commented Jan 22, 2019

@PodgeHeavin, I am unable to reproduce the issue.

Can you run ng --version?

You should have the following versions

@angular-devkit/build-angular     0.12.2
@angular-devkit/core              7.2.2

My result is

[
    {
        "endPosition": {
            "character": 26,
            "line": 8,
            "position": 214
        },
        "failure": "\" should be '",
        "fix": {
            "innerStart": 198,
            "innerLength": 16,
            "innerText": "'int-issue-json'"
        },
        "name": "/Users/alan/git/lint-issue-json/src/app/app.component.ts",
        "ruleName": "quotemark",
        "ruleSeverity": "ERROR",
        "startPosition": {
            "character": 10,
            "line": 8,
            "position": 198
        }
    },
    {
        "endPosition": {
            "character": 26,
            "line": 8,
            "position": 214
        },
        "failure": "Missing semicolon",
        "fix": {
            "innerStart": 214,
            "innerLength": 0,
            "innerText": ";"
        },
        "name": "/Users/alan/git/lint-issue-json/src/app/app.component.ts",
        "ruleName": "semicolon",
        "ruleSeverity": "ERROR",
        "startPosition": {
            "character": 26,
            "line": 8,
            "position": 214
        }
    }
]

@alan-agius4 alan-agius4 added the needs: more info Reporter must clarify the issue label Jan 22, 2019
@PodgeHeavin
Copy link
Author

PodgeHeavin commented Jan 22, 2019

     _                      _                 ____ _     ___
    / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
   / △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
  / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
 /_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
                |___/


Angular CLI: 7.1.4
Node: 8.11.3
OS: win32 x64
Angular: 7.1.4
... animations, cli, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.11.4
@angular-devkit/build-angular     0.11.4
@angular-devkit/build-optimizer   0.11.4
@angular-devkit/build-webpack     0.11.4
@angular-devkit/core              7.1.4
@angular-devkit/schematics        7.1.4
@ngtools/webpack                  7.1.4
@schematics/angular               7.1.4
@schematics/update                0.11.4
rxjs                              6.3.3
typescript                        3.1.6
webpack                           4.23.1

@alan-agius4
Copy link
Collaborator

Kindly update to the latest version of packages mentioned above and see if you still encounter the issue.

@PodgeHeavin
Copy link
Author

PodgeHeavin commented Jan 22, 2019

Issue persists.

The issue is only present in bash/linux but not in windows CMD.
I am running the commands from git bash window

     _                      _                 ____ _     ___
    / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
   / △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
  / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
 /_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
                |___/


Angular CLI: 7.2.2
Node: 8.11.3
OS: win32 x64
Angular: 7.2.1
... animations, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, router

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.12.2
@angular-devkit/build-angular     0.12.2
@angular-devkit/build-optimizer   0.12.2
@angular-devkit/build-webpack     0.12.2
@angular-devkit/core              7.2.2
@angular-devkit/schematics        7.2.2
@angular/cli                      7.2.2
@angular/language-service         7.2.0
@ngtools/webpack                  7.2.2
@schematics/angular               7.2.2
@schematics/update                0.12.2
rxjs                              6.3.3
typescript                        3.2.4
webpack                           4.28.4

@alan-agius4
Copy link
Collaborator

alan-agius4 commented Jan 23, 2019

Hi,If you want to redirect the stream output in git bash I suggest you use the FORCE_COLOR environment variable.

FORCE_COLOR=0 ng lint --format=json > issues.json

Let me know if this solved your issue.

Thanks.

@PodgeHeavin
Copy link
Author

This has not fixed the issue unfortunately. What has changed from Angular 6 to Angular 7 to cause this? We have some of our code on Angular 6 and the command is working fine and a new project running with angular 7 and this is where we are seeing the issue. It is failing on git bash locally and all our linux build servers.

@alan-agius4
Copy link
Collaborator

I removed the colors for the info, Git Bash is known to have some issues with colors. Though using FORCE_COLOR=0 should have solved the issue.

@alan-agius4 alan-agius4 removed the needs: more info Reporter must clarify the issue label Jan 23, 2019
mgechev pushed a commit that referenced this issue Jan 23, 2019
Rely on the terminal to provide the color for info messages

fixes #13497
mgechev pushed a commit that referenced this issue Jan 23, 2019
Rely on the terminal to provide the color for info messages

fixes #13497
@PodgeHeavin
Copy link
Author

Thanks for this. Impressed with the turn around.

@mgechev
Copy link
Member

mgechev commented Jan 23, 2019

@PodgeHeavin this should be part of 7.2.3 in an hour or so.

@angular-automatic-lock-bot
Copy link

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.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 9, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: devkit/build-angular freq1: low Only reported by a handful of users who observe it rarely severity5: regression type: bug/fix
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants