Tslint: Cannot lint when "composite" is true in tsconfig.json

Created on 2 Sep 2018  ยท  7Comments  ยท  Source: palantir/tslint

Bug Report

This bug is occurring in a monorepo project managed with Yarn Workspaces. I've recently upgraded it to TypeScript 3 and was looking to take advantage of Project References. To do this, I set composite: true under compilerOptions in tsconfig.json for each subpackage. If I set it to false, then everything works fine.

  • __TSLint version__: 5.11.0
  • __TypeScript version__: 3.0.1
  • __Running TSLint via__: (pick one) CLI

Actual behavior

$ tslint -p tsconfig.json -t codeFrame 'src/**/*.ts' -e 'src/**/*.spec.ts'
TypeError: Cannot read property 'replace' of undefined
    at Object.normalizeSlashes (/[PROJECT_PATH]]/node_modules/typescript/lib/typescript.js:14080:21)
    at getCommonSourceDirectory (/[PROJECT_PATH]]/node_modules/typescript/lib/typescript.js:82737:68)
    at verifyCompilerOptions (/[PROJECT_PATH]]/node_modules/typescript/lib/typescript.js:84278:27)
    at Object.createProgram (/[PROJECT_PATH]]/node_modules/typescript/lib/typescript.js:82703:9)
    at Function.Linter.createProgram (/[PROJECT_PATH]]/packages/framework/node_modules/tslint/lib/linter.js:80:26)
    at resolveFilesAndProgram (/[PROJECT_PATH]]/packages/framework/node_modules/tslint/lib/runner.js:120:35)
    at /[PROJECT_PATH]]/packages/framework/node_modules/tslint/lib/runner.js:90:18
    at step (/[PROJECT_PATH]]/node_modules/tslib/tslib.js:133:27)
    at Object.next (/[PROJECT_PATH]]/node_modules/tslib/tslib.js:114:57)
    at /[PROJECT_PATH]]/node_modules/tslib/tslib.js:107:75

Expected behavior

It should lint with no problems.

Similar issues

P1 Bug ๐ŸŒน R.I.P. ๐ŸŒน

Most helpful comment

The workaround might be obvious to some, perhaps, but I thought I'd share mine in case it helps someone.

  1. Create a tsconfig.lint.json:
{
  "extends": "./tsconfig.json",
  "compilerOptions": {
    // https://github.com/palantir/tslint/issues/4148
    "composite": false
  }
}
  1. Run tslint --project tsconfig.lint.json instead of tslint --project .

All 7 comments

Oops, seems like this is infact not a duplicate - just two related issues to do with project references.

I'm guessing this just requires tslint to update tslib - maybe you can try it out and make a PR.

I upgraded tslib in a local copy of tslint, but it didn't seem to fix the issue ๐Ÿ˜ข

The workaround might be obvious to some, perhaps, but I thought I'd share mine in case it helps someone.

  1. Create a tsconfig.lint.json:
{
  "extends": "./tsconfig.json",
  "compilerOptions": {
    // https://github.com/palantir/tslint/issues/4148
    "composite": false
  }
}
  1. Run tslint --project tsconfig.lint.json instead of tslint --project .

๐Ÿ’€ _It's time!_ ๐Ÿ’€

TSLint is deprecated and no longer accepting pull requests other than security fixes. See #4534. โ˜ ๏ธ
We recommend you instead use typescript-eslint to lint your TypeScript code with ESLint. โœ…

๐Ÿ‘‹ It was a pleasure open sourcing with you!

๐Ÿค– Beep boop! ๐Ÿ‘‰ TSLint is deprecated ๐Ÿ‘ˆ _(#4534)_ and you should switch to typescript-eslint! ๐Ÿค–

๐Ÿ”’ This issue is being locked to prevent further unnecessary discussions. Thank you! ๐Ÿ‘‹

Was this page helpful?
0 / 5 - 0 ratings