Typescript eslint disable no-unused-vars
我正在研究Typescript React项目,通常将占位符变量放入代码中,以便对所有内容进行布局,直到实现所有内容为止。这会导致一堆
如何在我准备就绪之前如何全局禁用它?我使用
我注意到
1 2 3 4 5 6 | "eslintConfig": { "extends":"react-app", "rules": { "no-unused-vars":"off" } }, |
Update
(已删除<
我更新了
1 2 3 4 5 6 | "eslintConfig": { "extends":"react-app", "rules": { "@typescript-eslint/no-unused-vars":"off" } }, |
我尝试将规则移至项目根目录中的
似乎唯一起作用的是将
我认为有些混乱。
问题和唯一答案都建议在tsconfig.json中放置一个规则部分。这是我从未听说过的东西,在文档或官方架构中也没有提及.https://www.typescriptlang.org/docs/handbook/tsconfig-json.html
也,问题是关于在eslint中禁用规则,因此规则更改应放在.eslintrc.json文件(或问题中考虑的package.json中的eslintConfig部分)中。
但这是打字稿和typescript-eslint,因此规则应为:
"@typescript-eslint/no-unused-vars" :"off"
,答案中提出的hacky解决方案需要更改为与某人链接(请注意,答案是针对js的eslint,而不是ts)。
/ * eslint-disable @ typescript-eslint / no-unused-vars * /
这些解决方案对我有用[email protected]@typescript -eslint/[email protected]@ typescript-eslint / parser @ 2.3.2
由于您使用了
中应该已经为您创建了
1 2 3 4 5 6 7 8 9 10 11 12 | { "extends": [...], "compilerOptions": { ... }, "include": [...], "rules": { ... "no-unused-vars":"off" ... } } |
我有类似的问题。这是我的解决方案:
1 2 3 4 5 | module.exports = { ... "rules": {...}, ... } |
1 2 3 4 5 6 7 8 | module.exports = { ... "rules": { ... "@typescript-eslint/no-unused-vars": process.env.NODE_ENV ==="production" ?"error" :"warn" }, ... } |
在eslintrc.json内添加" rules ",您只需将no-unused-vars写入0。
" rules ":{" no-unused-vars " :0}