// code snippet
使用tslint.json
配置:
{
"defaultSeverity": "error",
"extends": [
"tslint-eslint-rules"
],
"jsRules": {},
"rules": {}
}
当我将tslint.json
更改为
{
"defaultSeverity": "error",
"extends": "tslint-eslint-rules",
"jsRules": {},
"rules": {}
}
它显示A path in an 'extends' option must be relative or rooted, but 'tslint-eslint-rules' is not
我怎样才能得到tslint-eslint-rules
的路径
你混淆了tslint.json
和tsconfig.json
我确定我没有感到困惑。 在5.8.1
,它是正确的。
同样的问题在这里。
改变了
"extends": [
"tslint:recommended"
],
到
"extends": "./node_modules/tslint/lib/configs/recommended"
修理。
如果您的tsconfig .json错误,则A path in an 'extends' option must be relative or rooted, but 'xxx' is not
来自打字稿编译器。 因此,您要么使用-p tslint.json
要么将 tslint.json 中的内容添加到 tsconfig.json 中。
另一个困惑的用户在这里。
我们正在使用 CLI 调用 tslint
"lint": "tslint --project tslint.json -e src/**/*.spec.*",
这在过去一年中运作良好。 刚刚我们更新到 tslint 5.9.1 并看到相同的错误:
error TS5024: Compiler option 'extends' requires a value of type string.
我们的tslint.json
有以下 2 个扩展
{
"extends": [
"tslint:recommended",
"tslint-sonarts"
],
你能给我们更多关于发生了什么变化以及我们如何再次解决这个问题的信息吗?
如果确实相关,我们的 tsconfig 看起来像
{
"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您使用的确切 CLI 参数是什么? 我认为您可能使用与该线程中的其他记者相同的无效设置—— --project
标志必须指向tsconfig.json
文件,而不是tslint.json
。
@MartijnKooij在 v5.9 中对 tslint.json 中的extends
功能的实现进行了一些更改,这一定是无意中导致您的无效设置停止工作。 正如我上面所说,您必须将--project
指向一个 tsconfig.json 文件。 没有任何 TSLint 文档声称--project path/to/tslint.json
是受支持的使用模式。
感谢您的额外解释,当@ajafff说我们将 tslint 而不是 tsconfig 作为我们的 --project 参数时,我没有明白。
我的猜测是某处有一篇关于使用 tslint 的博客文章,其中包含此错误。
https://palantir.github.io/tslint/usage/cli/ 上关于此的文档是正确的,至少现在是 ;)
再次感谢,以及完整性和其他。 我们改变了:
"lint": "tslint --project tslint.json -e src/**/*.spec.*",
进入这个"lint": "tslint --project tsconfig.json -e src/**/*.spec.*",
@ajafff @adidahiya对不起,是我的错,非常感谢!
由于这个问题, mocha-tslint 也不再工作。 并且 configFilePath 应该指向 tslint.json。 如果我改用 tsconfig.json:
const lint = require('mocha-tslint');
const configFilePath = './tsconfig.json';
lint(configFilePath);
我得到这个结果:
tslint
No valid rules have been specified
它一直在使用 5.8
@DaveXCS这很可能是由mocha-tslint
做错了什么引起的。 我猜他们使用私有 API (runner.ts) 并将配置文件用作-c
和-p
参数。
我试图理解 mocha-tslint 中的问题,但我在这里没有真正看到问题:
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);
谢谢你的帮助。
我用 tsconfig.json 而不是 tslint.json 替换了 cli 上的 --project 并重写了“mocha-tslint”(也包括类型检查):
https://gist.github.com/DaveXCS/3bd930f7093b748f551c99e80d57c578
这是令人震惊的糟糕记录,只是令人困惑且根本不直观。
@devguyrun CLI 使用文档告诉您多次将--project
指向tsconfig.json
文件。 如果您认为它可以更清楚,请随时发送 PR
错误 TS18001:'extends' 选项中的路径必须是相对的或有根的,但 '<%= sourcedir.split('/').map(x => '..').join('/') %
/tsconfig.json' 不是。
我有一些其他错误。
最有用的评论
@StanLee12您使用的确切 CLI 参数是什么? 我认为您可能使用与该线程中的其他记者相同的无效设置——
--project
标志必须指向tsconfig.json
文件,而不是tslint.json
。@MartijnKooij在 v5.9 中对 tslint.json 中的
extends
功能的实现进行了一些更改,这一定是无意中导致您的无效设置停止工作。 正如我上面所说,您必须将--project
指向一个 tsconfig.json 文件。 没有任何 TSLint 文档声称--project path/to/tslint.json
是受支持的使用模式。