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

ng lint with format flag errors #10657

Closed
alisa-duncan opened this issue May 4, 2018 · 7 comments · Fixed by #12673
Closed

ng lint with format flag errors #10657

alisa-duncan opened this issue May 4, 2018 · 7 comments · Fixed by #12673

Comments

@alisa-duncan
Copy link

alisa-duncan commented May 4, 2018

Versions

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

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.6.0
@angular-devkit/build-angular     0.6.0
@angular-devkit/build-optimizer   0.6.0
@angular-devkit/core              0.6.0
@angular-devkit/schematics        0.6.0
@ngtools/webpack                  6.0.0
@schematics/angular               0.6.0
@schematics/update                0.6.0
rxjs                              6.1.0
typescript                        2.7.2
webpack                           4.6.0

Repro steps

  1. Create new application via angular-cli.
  2. Run ng lint with format flag.
ng new my-test
cd my-test
ng lint --format checkstyle

I can edit angular.json to add "format":"checkstyle" option to "my-test" and "my-test-e2e" projects. Then ng lint will run successfully and console will contain checkstyle output for each project.

Observed behavior

Architect commands with multiple targets cannot specify overrides.'lint' would be run on the following projects: my-test,my-test-e2e
Error: Architect commands with multiple targets cannot specify overrides.'lint' would be run on the following projects: my-test,my-test-e2e
    at LintCommand.validate (C:\repos\my-test\node_modules\@angular\cli\models\architect-command.js:91:23)
    at C:\repos\my-test\node_modules\@angular\cli\models\command-runner.js:274:39
    at Generator.next (<anonymous>)
    at C:\repos\my-test\node_modules\@angular\cli\models\command-runner.js:7:71
    at new Promise (<anonymous>)
    at __awaiter (C:\repos\my-test\node_modules\@angular\cli\models\command-runner.js:3:12)
    at validateAndRunCommand (C:\repos\my-test\node_modules\@angular\cli\models\command-runner.js:273:12)
    at Object.<anonymous> (C:\repos\my-test\node_modules\@angular\cli\models\command-runner.js:100:26)
    at Generator.next (<anonymous>)
    at fulfilled (C:\repos\my-test\node_modules\@angular\cli\models\command-runner.js:4:58)

When using format option in angular.json, I get 2 checkstyle outputs (one for each project).

ng lint
<?xml version="1.0" encoding="utf-8"?><checkstyle version="4.3"></checkstyle>
<?xml version="1.0" encoding="utf-8"?><checkstyle version="4.3"></checkstyle>

Desired behavior

  • I would like to be able to pass in format param via command line so that it can be used via CI and local builds.
  • Default output is prose in console.
  • Aggregate all linting errors preferred but can work around. (This was previous behavior).
    • Aggregate lint output for all projects so that I can pipe to file
    • For checkstyle it has all errors in one xml output instead of 2

Mention any other details that might be useful (optional)

We use Jenkins CI and use checkstyle reporter to file for CI builds only, but would like to retain prose console output for local builds. We cannot do that when format is set in angular.json.

This is similar to #10422 but reporter was using multiple libraries. This issue is visible in a basic application.

@alisa-duncan
Copy link
Author

Here's how I got past this:

I created 2 convenience configurations in angular.json specifically for linting for 'my-test' and 'my-test-e2e'. For the purposes of this example, I named them 'ci-app-lint' and 'ci-e2e-lint' In the defined configurations, I added "format" option.

In npm, I created a script that wraps lint for console vs CI by specifying the configurations it should run:

"scripts": {
   "ng": "ng",
   "lint": "ng lint my-test && ng lint my-test-e2e",
   "lint:ci": "ng lint ci-app-lint > lint-output/app.xml && ng lint ci-e2e-lint > lint-output/e2e.xml"
}

Jenkins calls lint:ci and I change the job configuration to look for "lint-output/*.xml".

I know I can get around the convenience configurations and pass all the flags i need for my-test and my-test-e2e in the lint:ci and I may consider changing at some point if having convenience configs causes other problems.

The error output was really unhelpful and the docs weren't much better. It took some trial and error to figure out how to work with configurations.

@alobaidizt
Copy link

@alisa-duncan comment helped me a lot. I didn't realize that in version 6 (or 5) you have to update your npm scripts to include the name of your project. Additionally, project-name-e2e is considered a separate project as well.

This has also helped me figure out why my ng test command was running 0 tests!

Thanks!

@senseysensor
Copy link

@alisa-duncan could you share your angular.json please? those parts with lint configuration added? thank you!

@alisa-duncan
Copy link
Author

@senseysensor something like this

{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "version": 1,
  "newProjectRoot": "projects",
  "projects": {
    "my-test": {
      "root": "",
      "sourceRoot": "src",
      "projectType": "application",
      "prefix": "app",
      "schematics": {},
      "architect": {
        "build": {
          "builder": "@angular-devkit/build-angular:browser",
          "options": {
            "outputPath": "dist/my-test",
            "index": "src/index.html",
            "main": "src/main.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "src/tsconfig.app.json",
            "assets": [
              "src/favicon.ico",
              "src/assets"
            ],
            "styles": [
              "src/styles.css"
            ],
            "scripts": []
          },
          "configurations": {
            "production": {
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.prod.ts"
                }
              ],
              "optimization": true,
              "outputHashing": "all",
              "sourceMap": false,
              "extractCss": true,
              "namedChunks": false,
              "aot": true,
              "extractLicenses": true,
              "vendorChunk": false,
              "buildOptimizer": true
            }
          }
        },
        "serve": {
          "builder": "@angular-devkit/build-angular:dev-server",
          "options": {
            "browserTarget": "my-test:build"
          },
          "configurations": {
            "production": {
              "browserTarget": "my-test:build:production"
            }
          }
        },
        "extract-i18n": {
          "builder": "@angular-devkit/build-angular:extract-i18n",
          "options": {
            "browserTarget": "my-test:build"
          }
        },
        "test": {
          "builder": "@angular-devkit/build-angular:karma",
          "options": {
            "main": "src/test.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "src/tsconfig.spec.json",
            "karmaConfig": "src/karma.conf.js",
            "styles": [
              "src/styles.css"
            ],
            "scripts": [],
            "assets": [
              "src/favicon.ico",
              "src/assets"
            ]
          }
        },
        "lint": {
          "builder": "@angular-devkit/build-angular:tslint",
          "options": {
            "tsConfig": [
              "src/tsconfig.app.json",
              "src/tsconfig.spec.json"
            ],
            "exclude": [
              "**/node_modules/**"
            ]
          }
        }
      }
    },
    "my-test-e2e": {
      "root": "e2e/",
      "projectType": "application",
      "architect": {
        "e2e": {
          "builder": "@angular-devkit/build-angular:protractor",
          "options": {
            "protractorConfig": "e2e/protractor.conf.js",
            "devServerTarget": "my-test:serve"
          }
        },
        "lint": {
          "builder": "@angular-devkit/build-angular:tslint",
          "options": {
            "tsConfig": "e2e/tsconfig.e2e.json",
            "exclude": [
              "**/node_modules/**"
            ]
          }
        }
      }
    },
    "ci-app-lint": {
      "root": "",
      "sourceRoot": "src",
      "projectType": "application",
      "prefix": "app",
      "schematics": {},
      "architect": {
        "lint": {
          "builder": "@angular-devkit/build-angular:tslint",
          "options": {
            "tsConfig": [
              "src/tsconfig.app.json",
              "src/tsconfig.spec.json"
            ],
            "exclude": [
              "**/node_modules/**"
            ],
            "format": "checkstyle"
          }
        }
      }
    },
    "ci-e2e-lint": {
      "root": "e2e/",
      "projectType": "application",
      "architect": {
        "e2e": {
          "builder": "@angular-devkit/build-angular:protractor",
          "options": {
            "protractorConfig": "e2e/protractor.conf.js",
            "devServerTarget": "my-test:serve"
          }
        },
        "lint": {
          "builder": "@angular-devkit/build-angular:tslint",
          "options": {
            "tsConfig": "e2e/tsconfig.e2e.json",
            "exclude": [
              "**/node_modules/**"
            ],
            "format": "checkstyle"
          }
        }
      }
    }
  },
  "defaultProject": "my-test"
}

@valentinkononov
Copy link

I also faced the same issue when updated to the new Angular version. I have fixed it just my specifying exact project name in lint commands in package.json like this:

"scripts": {
   .... 
   "lint": "ng lint test-app --type-check",
   "lint:fix": "ng lint test-app --fix",

where test-app is my project name.

@d3lm
Copy link
Contributor

d3lm commented Jul 19, 2018

I am running into the same issue. I have one application and one lib. My lint:fix command simply runs ng lint --fix which gives me the the following error Architect commands with multiple targets cannot specify overrides. 'lint' would be run on the following projects: app, lib.

I was able to fix it with the solution proposed above.

Is this how we are supposed to deal with this error? Do we have to specify each project individually when fixing linting errors?

mnahkies added a commit to mnahkies/angular-cli that referenced this issue Oct 21, 2018
When running a command with args against multiple targets, all targets
should be given the args. As parseArguments was mutating the passed args
array this wasn't the case. Fix by making a shallow clone of the array.
This was especially noticeable when using the `ng lint --fix` command
on a newly generated project, as files in the app target would be fixed,
but e2e target would be only be linted (with no fix)

Possibly closes angular#10657, angular#10656, angular#11005
mnahkies added a commit to mnahkies/angular-cli that referenced this issue Nov 20, 2018
When running a command with args against multiple targets, all targets
should be given the args. As parseArguments was mutating the passed args
array this wasn't the case. Fix by not mutating the array.

This was especially noticeable when using the `ng lint --fix` command
on a newly generated project, as files in the app target would be fixed,
but e2e target would be only be linted (with no fix)

Possibly closes angular#10657, angular#10656, angular#11005
alexeagle pushed a commit that referenced this issue Dec 6, 2018
When running a command with args against multiple targets, all targets
should be given the args. As parseArguments was mutating the passed args
array this wasn't the case. Fix by not mutating the array.

This was especially noticeable when using the `ng lint --fix` command
on a newly generated project, as files in the app target would be fixed,
but e2e target would be only be linted (with no fix)

Possibly closes #10657, #10656, #11005
alexeagle pushed a commit that referenced this issue Dec 6, 2018
When running a command with args against multiple targets, all targets
should be given the args. As parseArguments was mutating the passed args
array this wasn't the case. Fix by not mutating the array.

This was especially noticeable when using the `ng lint --fix` command
on a newly generated project, as files in the app target would be fixed,
but e2e target would be only be linted (with no fix)

Possibly closes #10657, #10656, #11005
@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.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants