简体   繁体   English

eslint - 尽管有 correct.eslintrc.json 设置,但 no-unused-vars 警告仍然存在

[英]eslint - no-unused-vars warning persists despite correct .eslintrc.json setting

I have a an.eslintrc.json file whose rules my code is obeying.我有一个 an.eslintrc.json 文件,我的代码遵守其规则。 Except the "no-unused-vars" rule.除了“无未使用的变量”规则。

It works in my editor, that is, the unused vars are no longer highlighted red, but when I run the app in the console the console throws the warning.它在我的编辑器中工作,也就是说,未使用的变量不再突出显示为红色,但是当我在控制台中运行该应用程序时,控制台会抛出警告。 It's like they're using two separate configs or something.就像他们在使用两个单独的配置之类的。 It's a create-react-app.这是一个 create-react-app。

Stop your app, run rm -rf node_modules/.cache/eslint-loader , then start it again.停止您的应用程序,运行rm -rf node_modules/.cache/eslint-loader ,然后重新启动它。 If that doesn't work then your editor is probably using a different eslint config than your app, but it's hard to say without looking at your setup.如果这不起作用,那么您的编辑器可能使用了与您的应用程序不同的 eslint 配置,但如果不查看您的设置就很难说。

Either way, check out CRA's official documentation on extending ESLint rules , or even better, use something like craco , react-app-rewired or customize-cra to get complete control over your ESLint config without having to eject from CRA.无论哪种方式,请查看CRA 关于扩展 ESLint 规则的官方文档,或者更好的是,使用诸如cracoreact-app- rewired 或customize-cra之类的东西来完全控制你的 ESLint 配置,而不必从 CRA 中弹出。

As it turned out, the only thing I needed to do was add a .env file in my project root with this:事实证明,我唯一需要做的就是在我的项目根目录中添加一个.env文件:

EXTEND_ESLINT=true

Then everything worked fine.然后一切正常。 I love simple solutions but my lord was that tedious: :)我喜欢简单的解决方案,但我的主人太乏味了::)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM