angular-cli icon indicating copy to clipboard operation
angular-cli copied to clipboard

Duplicate Lint Errors

Open dave11mj opened this issue 9 years ago • 11 comments

Please provide us with the following information:

OS?

Windows 7, 8 or 10. Linux (which distribution). Mac OSX (Yosemite? El Capitan?)

OSX El Capitan Version 10.11.6

Versions.

Please run ng --version. If there's nothing outputted, please run in a Terminal: node --version and paste the result here:

@angular/cli: 1.0.0-rc.1
node: 6.9.5
os: darwin x64

Repro steps.

Was this an app that wasn't created using the CLI? What change did you do on your code? etc.

  1. Run ng new lint-test
  2. Run cd lint-test
  3. Run ng g component components/test-lint
  4. Open src/app/components/test-lint/test-lint.component.ts and cause one lint error (e.g, use " instead of ')
  5. Run npm run lint
  6. Notice how the lint errors are logged twice

The log given by the failure.

Normally this include a stack trace and some more information.

> [email protected] lint /path/to/lint-test
> ng lint

/path/to/lint-test/src/app/components/test-lint/test-lint.component.ts[4, 13]: " should be '
/path/to/lint-test/src/app/components/test-lint/test-lint.component.ts[4, 13]: " should be '
Lint errors found in the listed files.

Mention any other details that might be useful.

Through a bit of trial and error it seems the issue only occurs on files that are nested inside subfolders like components and are imported to other nested files. In this case it happens out of the box because ng new generates a test-lint.component.spec.ts file for each component which has an import { TestLintComponent } from './test-lint.component'; thus causing lint errors on the component to be reported twice.

A temporary fix in my particular case was to remove "include": [ "**/*.spec.ts" ] from src/tsconfig.spec.json since linting test specs was a priority to me.

It'd be nice to know more about the cause and if there is a better fix for this dilemma.

Thanks! ^^


Thanks! We'll be in touch soon.

dave11mj avatar Mar 06 '17 23:03 dave11mj

I see the same issue.

$ ng lint
/Users/john/_play/angular-hello/src/app/app.component.ts[13, 5]: Identifier 'f' is never reassigned; use 'const' instead of 'let'.
/Users/john/_play/angular-hello/src/app/app.component.ts[13, 5]: Identifier 'f' is never reassigned; use 'const' instead of 'let'.
Lint errors found in the listed files.
$ ng -v --verbose
    _                      _                 ____ _     ___
   / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
  / △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
 / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
/_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
               |___/
@angular/cli: 1.0.0-rc.1
http_parser: 2.7.0
node: 6.9.1
v8: 5.1.281.84
uv: 1.9.1
zlib: 1.2.8
ares: 1.10.1-DEV
icu: 57.1
modules: 48
openssl: 1.0.2j
os: darwin x64
@angular/common: 4.0.0-rc.2
@angular/compiler: 4.0.0-rc.2
@angular/core: 4.0.0-rc.2
@angular/flex-layout: 2.0.0-rc.1
@angular/forms: 4.0.0-rc.2
@angular/http: 4.0.0-rc.2
@angular/material: 2.0.0-beta.2
@angular/platform-browser: 4.0.0-rc.2
@angular/platform-browser-dynamic: 4.0.0-rc.2
@angular/router: 4.0.0-rc.2
@angular/cli: 1.0.0-rc.1
@angular/compiler-cli: 4.0.0-rc.2

johnpapa avatar Mar 07 '17 21:03 johnpapa

as per chat with @filipesilva , this may be due to the multiple TS projects now included in the CLI.

johnpapa avatar Mar 07 '17 21:03 johnpapa

It seems like the linter runs once for each project? and since the tests should include the same components it is hitting the same code twice

deebloo avatar Mar 08 '17 13:03 deebloo

It seems that there's again a similar issue with @angular/[email protected] now, can someone confirm?

kamenminkov avatar May 23 '18 11:05 kamenminkov

After some tests, I found that commenting one of the two tsConfig entry in angular.json result to output the error one time. Maybe the linter run twice on files included in spec AND in app config ?

eweap avatar May 29 '18 19:05 eweap

Same problem for me. Included two tsConfigs in angular.json:


        "lint": {
          "builder": "@angular-devkit/build-angular:tslint",
          "options": {
            "tsConfig": [
              "src/tsconfig.app.json",
              "src/tsconfig.spec.json"
            ],
            "exclude": [
              "**/node_modules/**"
            ]
          }
        }

vasiliy0s avatar Aug 01 '18 10:08 vasiliy0s

If tsconfig.spec.json includes all the files that tsconfic.app.json does, then specifying only tsconfig.spec.json in the linting config in angular.json is enough to lint everything perfectly:

"lint": {
 "builder": "@angular-devkit/build-angular:tslint",
  "options": {
    "tsConfig": "src/tsconfig.spec.json",
    "typeCheck": true,
    "format": "stylish"
  }
}

axelboc avatar Aug 01 '18 11:08 axelboc

I'd love to have a chance to include both spec and app tsconfigs of my project inside of angular.json/lint options, without caring about their content. Solution above is more like a temporary workaround (I have to admit it works fine), not a state we'd like to see here for ever IMO.

(I see that PR is still closed - is anyone aware of this issue?)

psmyrdek avatar Aug 03 '18 13:08 psmyrdek

CC: @filipesilva

psmyrdek avatar Aug 06 '18 08:08 psmyrdek

I'm also having duplicated error messages when running this:

ng lint --format=stylish --force my-app my-app-e2e

Any solution or workaround available?

arthurspa avatar Feb 01 '19 11:02 arthurspa

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.