Tslint: Compiler option 'extends' requires a value of type string

Created on 11 Jan 2018  ·  17Comments  ·  Source: palantir/tslint

Bug Report

  • __TSLint version__: 5.9.1
  • __TypeScript version__: 2.6.2
  • __Running TSLint via__: CLI

TypeScript code being linted

// code snippet

with tslint.json configuration:

{
    "defaultSeverity": "error",
    "extends": [
         "tslint-eslint-rules"
     ],
    "jsRules": {},
    "rules": {}
}

Actual behavior

Expected behavior

Not A Bug

Most helpful comment

@StanLee12 what are the exact CLI arguments you're using? I think you might be using the same invalid setup as the other reporters in this thread -- the --project flag must point to a tsconfig.json file, not tslint.json.

@MartijnKooij there were some changes to the implementation of the extends feature in tslint.json in v5.9 which must have inadvertently caused your invalid setup to stop working. As I said above, you must point --project to a tsconfig.json file. None of the TSLint docs have ever claimed that --project path/to/tslint.json is a supported usage pattern.

All 17 comments

when i change tslint.json to

{
    "defaultSeverity": "error",
    "extends":  "tslint-eslint-rules",
    "jsRules": {},
    "rules": {}
}

it's show A path in an 'extends' option must be relative or rooted, but 'tslint-eslint-rules' is not

how can i get the path of tslint-eslint-rules

You are confusing tslint.json and tsconfig.json

I'm sure that i'm not confused. In version 5.8.1, it's correct.

The same problem here.
Changed

"extends": [
    "tslint:recommended"
  ],

to

"extends": "./node_modules/tslint/lib/configs/recommended"

to fix.

A path in an 'extends' option must be relative or rooted, but 'xxx' is not comes from the typescript compiler if your tsconfig.json is wrong. So either you are using -p tslint.json or you have content that should be in tslint.json added to your tsconfig.json.

Another confused user here.
We are calling tslint from the CLI using
"lint": "tslint --project tslint.json -e src/**/*.spec.*",

This has worked just fine for the past year. Just now we updated to tslint 5.9.1 and are seeing the same error:

error TS5024: Compiler option 'extends' requires a value of type string.

Our tslint.json has the following 2 extends

{
    "extends": [
        "tslint:recommended",
        "tslint-sonarts"
    ],

Could you give us a bit more info on what has changed and how we can fix this again?

In case it is indeed relevant, our tsconfig looks like

{
    "compileOnSave": false,
    "compilerOptions": {
        "lib": [
            "dom",
            "es2015"
        ],
        "noImplicitAny": false,
        "target": "es5",
        "rootDir": "src",
        "emitDecoratorMetadata": true,
        "experimentalDecorators": true,
        "sourceMap": true,
        "jsx": "preserve",
        "baseUrl": "src",
        "types": [
            "p-elements-core",
            "@types/jasmine",
            "@types/underscore",
            "@types/requirejs",
            "../../src/types"
        ]
    }
}

@StanLee12 what are the exact CLI arguments you're using? I think you might be using the same invalid setup as the other reporters in this thread -- the --project flag must point to a tsconfig.json file, not tslint.json.

@MartijnKooij there were some changes to the implementation of the extends feature in tslint.json in v5.9 which must have inadvertently caused your invalid setup to stop working. As I said above, you must point --project to a tsconfig.json file. None of the TSLint docs have ever claimed that --project path/to/tslint.json is a supported usage pattern.

Thanks for the extra explanation, I did not get it when @ajafff said we had the tslint instead of the tsconfig as our --project parameter.
My guess is that somewhere out there there's a blog post about using tslint which contains this error.
The documentation on https://palantir.github.io/tslint/usage/cli/ about this is correct, at least now it is ;)

Thanks again, and for completeness and others. We changed:
"lint": "tslint --project tslint.json -e src/**/*.spec.*",
into this
"lint": "tslint --project tsconfig.json -e src/**/*.spec.*",

@ajafff @adidahiya I'm so sorry, it's my fault, thanks a lot!

mocha-tslint is no longer working because of this problem as well. And there configFilePath should point to tslint.json. if i use tsconfig.json instead:
const lint = require('mocha-tslint'); const configFilePath = './tsconfig.json'; lint(configFilePath);
i get this result:
tslint No valid rules have been specified

It was always working with 5.8

@DaveXCS That's most likely caused by mocha-tslint doing something wrong. I guess they use a private API (runner.ts) and use the config file as -c AND -p argument.

I tried to understand the problem in mocha-tslint but i don't really see a problem here:
const tslintConfig = Configuration.loadConfigurationFromPath(configFilePath); fileNames.forEach((file) => test(file, tslintConfig));
const TSLint = require('tslint'); const Linter = TSLint.Linter; const Configuration = TSLint.Configuration;
fs.readFile(file, (err, sourceBuffer) => { const linter = new Linter(options); const source = sourceBuffer.toString(); linter.lint(file, source.toString(), config);

@DaveXCS The problem is this line: https://github.com/t-sauer/mocha-tslint/blob/0ba7f64be458cd74343a4149dff323d5bfd195a5/index.js#L24
It should not pass the path to tslint.json to a function that expects the path to a tsconfig.json

I opened an issue for you: https://github.com/t-sauer/mocha-tslint/issues/9

thanks for your help.
i replaced the --project on the cli with tsconfig.json instead of tslint.json and rewrote "mocha-tslint" (including type checking as well):
https://gist.github.com/DaveXCS/3bd930f7093b748f551c99e80d57c578

this is shockingly poorly documented, just confusing and not intuitive at all.

@devguyrun the CLI usage docs tell you to point --project to a tsconfig.json file multiple times. If you think it could be more clear, feel free to send a PR

error TS18001: A path in an 'extends' option must be relative or rooted, but '<%= sourcedir.split('/').map(x => '..').join('/') %

/tsconfig.json' is not.

I got some other error.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ypresto picture ypresto  ·  3Comments

denkomanceski picture denkomanceski  ·  3Comments

CSchulz picture CSchulz  ·  3Comments

avanderhoorn picture avanderhoorn  ·  3Comments

allbto picture allbto  ·  3Comments