angular / angular-cli

CLI tool for Angular
https://cli.angular.io
MIT License
26.77k stars 11.97k forks source link

Since v1.5.0-beta.2 ng lint does not work anymore for .spec.ts files -> Invalid source file #7878

Closed Martin-Luft closed 5 years ago

Martin-Luft commented 7 years ago

Bug Report or Feature Request (mark with an x)

- [x] bug report
- [ ] feature request

Versions.

@angular/cli: 1.5.0-beta.2 node: 7.10.1 os: linux x64 @angular/common: 5.0.0-rc.0 @angular/compiler: 5.0.0-rc.0 @angular/core: 5.0.0-rc.0 @angular/forms: 5.0.0-rc.0 @angular/http: 5.0.0-rc.0 @angular/platform-browser: 5.0.0-rc.0 @angular/platform-browser-dynamic: 5.0.0-rc.0 @angular/router: 5.0.0-rc.0 @angular/cli: 1.5.0-beta.2 @angular/compiler-cli: 5.0.0-rc.0 typescript: 2.5.3

Repro steps.

ng lint

The log given by the failure.

Invalid source file: src/app/app.component.spec.ts. Ensure that the files supplied to lint have a .ts, .tsx, .d.ts, .js or .jsx extension.

Error
    at new FatalError (/work/laninja/node_modules/tslint/lib/error.js:31:23)
    at Linter.getSourceFile (/work/laninja/node_modules/tslint/lib/linter.js:204:23)
    at Linter.lint (/work/laninja/node_modules/tslint/lib/linter.js:72:31)
    at files.forEach (/work/laninja/node_modules/@angular/cli/tasks/lint.js:67:24)
    at Array.forEach (native)
    at lintConfigs.map (/work/laninja/node_modules/@angular/cli/tasks/lint.js:58:19)
    at Array.map (native)
    at Class.run (/work/laninja/node_modules/@angular/cli/tasks/lint.js:35:14)
    at Class.run (/work/laninja/node_modules/@angular/cli/commands/lint.js:46:25)
    at resolve (/work/laninja/node_modules/@angular/cli/ember-cli/lib/models/command.js:261:20)

Desired functionality.

ng lint should work as it did in v1.5.0-beta.1

Mention any other details that might be useful.

The .spec.ts files are the problem.

clydin commented 7 years ago

Can you provide the lint config section from the project's .angular-cli.json?

The most likely cause is that the files option is used in combination with the project option. Only one is needed for most use cases. The default new CLI app only includes the project option. If both are used the files option should only include files present within the TS project. Previously files not part of the project were not linted and silently ignored.

Martin-Luft commented 7 years ago

@clydin

  "lint": [
    {
      "files": "src/app/**/*.ts",
      "project": "src/tsconfig.app.json"
    },
    {
      "files": "src/app/**/*.ts",
      "project": "src/tsconfig.spec.json"
    },
    {
      "project": "e2e/tsconfig.e2e.json"
    }
  ],
JonnyBGod commented 7 years ago

Having exact same error with:

Angular CLI: 1.5.0
Node: 8.9.0
OS: darwin x64
Angular: 5.0.0
... animations, common, compiler, compiler-cli, core, forms
... http, platform-browser, platform-browser-dynamic
... platform-server, router

@angular/cli: 1.5.0
@angular-devkit/build-optimizer: 0.0.32
@angular-devkit/core: 0.0.20
@angular-devkit/schematics: 0.0.35
@ngtools/json-schema: 1.1.0
@ngtools/webpack: 1.8.0
@schematics/angular: 0.1.0
typescript: 2.6.1
webpack: 3.8.1
mpicard commented 7 years ago

Same, tslint v 5.8.0 and 5.7.0 do it

Angular CLI: 1.5.0
Node: 6.11.3
OS: linux x64
Angular: 5.0.0
... animations, common, compiler, compiler-cli, core, forms
... http, platform-browser, platform-browser-dynamic
... platform-server, router

@angular/cli: 1.5.0
@angular/language-service: 4.4.6
@angular-devkit/build-optimizer: 0.0.32
@angular-devkit/core: 0.0.20
@angular-devkit/schematics: 0.0.34
@ngtools/json-schema: 1.1.0
@ngtools/webpack: 1.8.0
@schematics/angular: 0.1.1
typescript: 2.4.2
webpack: 3.8.1
julienevano commented 7 years ago

You can exclude spec and other test files in the lint config for the app.

Here is an example of lint config in the .angular-cli.json:

...
"lint": [
    {
      "files": "src/**/*.ts",
      "project": "src/tsconfig.app.json",
      "exclude": [
        "src/**/*.spec.ts",
        "src/test/**/*",
        "src/test.ts",
        "src/wallabyTest.ts"
      ]
    },
    {
      "files": "src/**/*.spec.ts",
      "project": "src/tsconfig.spec.json"
    },
    {
      "files": "e2e/**/*.ts",
      "project": "e2e/tsconfig.e2e.json"
    }
  ],
...
clydin commented 7 years ago

Alternatively, remove the files fields. They are unnecessary unless they are more restrictive than the files described by the project option's tsconfig (in which case exclude is a cleaner option). The behavior follows tslint in that the files option has priority over the project option but the project option is still used to retrieve the file. CLI 1.6 will have a more descriptive error message in this case as the current one is misleading.

alan-agius4 commented 5 years ago

Thanks for reporting this issue. This issue is now obsolete due to changes in the recent releases. Please update to the most recent Angular CLI version.

If the problem persists after upgrading, please open a new issue, provide a simple repository reproducing the problem, and describe the difference between the expected and current behavior.

angular-automatic-lock-bot[bot] commented 5 years ago

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.