Skip to content
This repository has been archived by the owner on Mar 25, 2021. It is now read-only.

Compiler option 'extends' requires a value of type string #3643

Closed
StanLee12 opened this issue Jan 11, 2018 · 17 comments
Closed

Compiler option 'extends' requires a value of type string #3643

StanLee12 opened this issue Jan 11, 2018 · 17 comments

Comments

@StanLee12
Copy link

StanLee12 commented Jan 11, 2018

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

@StanLee12
Copy link
Author

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

@ajafff
Copy link
Contributor

ajafff commented Jan 11, 2018

You are confusing tslint.json and tsconfig.json

@StanLee12
Copy link
Author

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

@tymfear
Copy link

tymfear commented Jan 11, 2018

The same problem here.
Changed

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

to

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

to fix.

@ajafff
Copy link
Contributor

ajafff commented Jan 11, 2018

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.

@MartijnKooij
Copy link

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"
        ]
    }
}

@adidahiya
Copy link
Contributor

@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.

@MartijnKooij
Copy link

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.*",

@StanLee12
Copy link
Author

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

@ghost
Copy link

ghost commented Jan 16, 2018

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

@ajafff
Copy link
Contributor

ajafff commented Jan 16, 2018

@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.

@ghost
Copy link

ghost commented Jan 16, 2018

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);

@ajafff
Copy link
Contributor

ajafff commented Jan 16, 2018

@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: t-sauer/mocha-tslint#9

@ghost
Copy link

ghost commented Jan 17, 2018

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

@devguyrun
Copy link

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

@adidahiya
Copy link
Contributor

@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

@BukkituNikhil
Copy link

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.

ulmanA pushed a commit to myspecialway/my-special-way-portal that referenced this issue Oct 31, 2018
*fix linting and rest snapshot
*fix ts-lint issue: Compiler option 'extends' requires a value of type string according to: palantir/tslint#3643
nodulusteam pushed a commit to myspecialway/my-special-way-portal that referenced this issue Nov 3, 2018
*fix linting and rest snapshot
*fix ts-lint issue: Compiler option 'extends' requires a value of type string according to: palantir/tslint#3643
nodulusteam pushed a commit to myspecialway/my-special-way-portal that referenced this issue Nov 5, 2018
*fix linting and rest snapshot
*fix ts-lint issue: Compiler option 'extends' requires a value of type string according to: palantir/tslint#3643
nodulusteam pushed a commit to myspecialway/my-special-way-portal that referenced this issue Nov 5, 2018
*fix linting and rest snapshot
*fix ts-lint issue: Compiler option 'extends' requires a value of type string according to: palantir/tslint#3643
nodulusteam pushed a commit to myspecialway/my-special-way-portal that referenced this issue Nov 10, 2018
*fix linting and rest snapshot
*fix ts-lint issue: Compiler option 'extends' requires a value of type string according to: palantir/tslint#3643
nodulusteam pushed a commit to myspecialway/my-special-way-portal that referenced this issue Nov 10, 2018
*fix linting and rest snapshot
*fix ts-lint issue: Compiler option 'extends' requires a value of type string according to: palantir/tslint#3643
nodulusteam pushed a commit to myspecialway/my-special-way-portal that referenced this issue Nov 10, 2018
*fix linting and rest snapshot
*fix ts-lint issue: Compiler option 'extends' requires a value of type string according to: palantir/tslint#3643
nodulusteam pushed a commit to myspecialway/my-special-way-portal that referenced this issue Nov 17, 2018
*fix linting and rest snapshot
*fix ts-lint issue: Compiler option 'extends' requires a value of type string according to: palantir/tslint#3643
nodulusteam pushed a commit to myspecialway/my-special-way-portal that referenced this issue Nov 17, 2018
*fix linting and rest snapshot
*fix ts-lint issue: Compiler option 'extends' requires a value of type string according to: palantir/tslint#3643
nodulusteam pushed a commit to myspecialway/my-special-way-portal that referenced this issue Nov 17, 2018
*fix linting and rest snapshot
*fix ts-lint issue: Compiler option 'extends' requires a value of type string according to: palantir/tslint#3643
nodulusteam pushed a commit to myspecialway/my-special-way-portal that referenced this issue Nov 17, 2018
*fix linting and rest snapshot
*fix ts-lint issue: Compiler option 'extends' requires a value of type string according to: palantir/tslint#3643
nodulusteam pushed a commit to myspecialway/my-special-way-portal that referenced this issue Nov 17, 2018
*fix linting and rest snapshot
*fix ts-lint issue: Compiler option 'extends' requires a value of type string according to: palantir/tslint#3643
nodulusteam pushed a commit to myspecialway/my-special-way-portal that referenced this issue Nov 17, 2018
*fix linting and rest snapshot
*fix ts-lint issue: Compiler option 'extends' requires a value of type string according to: palantir/tslint#3643
nodulusteam pushed a commit to myspecialway/my-special-way-portal that referenced this issue Nov 19, 2018
*fix linting and rest snapshot
*fix ts-lint issue: Compiler option 'extends' requires a value of type string according to: palantir/tslint#3643
nodulusteam pushed a commit to myspecialway/my-special-way-portal that referenced this issue Nov 19, 2018
*fix linting and rest snapshot
*fix ts-lint issue: Compiler option 'extends' requires a value of type string according to: palantir/tslint#3643
nodulusteam pushed a commit to myspecialway/my-special-way-portal that referenced this issue Nov 19, 2018
*fix linting and rest snapshot
*fix ts-lint issue: Compiler option 'extends' requires a value of type string according to: palantir/tslint#3643
nodulusteam pushed a commit to myspecialway/my-special-way-portal that referenced this issue Nov 19, 2018
*fix linting and rest snapshot
*fix ts-lint issue: Compiler option 'extends' requires a value of type string according to: palantir/tslint#3643
nodulusteam pushed a commit to myspecialway/my-special-way-portal that referenced this issue Nov 19, 2018
*fix linting and rest snapshot
*fix ts-lint issue: Compiler option 'extends' requires a value of type string according to: palantir/tslint#3643
nodulusteam pushed a commit to myspecialway/my-special-way-portal that referenced this issue Nov 19, 2018
*fix linting and rest snapshot
*fix ts-lint issue: Compiler option 'extends' requires a value of type string according to: palantir/tslint#3643
nodulusteam pushed a commit to myspecialway/my-special-way-portal that referenced this issue Nov 19, 2018
*fix linting and rest snapshot
*fix ts-lint issue: Compiler option 'extends' requires a value of type string according to: palantir/tslint#3643
nodulusteam pushed a commit to myspecialway/my-special-way-portal that referenced this issue Nov 19, 2018
*fix linting and rest snapshot
*fix ts-lint issue: Compiler option 'extends' requires a value of type string according to: palantir/tslint#3643
nodulusteam pushed a commit to myspecialway/my-special-way-portal that referenced this issue Nov 19, 2018
*fix linting and rest snapshot
*fix ts-lint issue: Compiler option 'extends' requires a value of type string according to: palantir/tslint#3643
nodulusteam pushed a commit to myspecialway/my-special-way-portal that referenced this issue Nov 19, 2018
*fix linting and rest snapshot
*fix ts-lint issue: Compiler option 'extends' requires a value of type string according to: palantir/tslint#3643
nodulusteam pushed a commit to myspecialway/my-special-way-portal that referenced this issue Nov 19, 2018
*fix linting and rest snapshot
*fix ts-lint issue: Compiler option 'extends' requires a value of type string according to: palantir/tslint#3643
nodulusteam pushed a commit to myspecialway/my-special-way-portal that referenced this issue Nov 19, 2018
*fix linting and rest snapshot
*fix ts-lint issue: Compiler option 'extends' requires a value of type string according to: palantir/tslint#3643
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

7 participants