如何设置.eslintrc识别“需要"? [英] How to set .eslintrc to recognize 'require'?

查看:114
本文介绍了如何设置.eslintrc识别“需要"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 ESLint 的新手,并且我已经成功地将ESLint与

I am new to ESLint, and I have successfully integrated ESLint with IntelliJ.

开箱即用,我对ESLint的集成无法识别node,但是对文档的基本检查表明,通过在项目文件夹的根目录下创建名为.eslintrc的配置文件(使用适当的IntelliJ设置,访问此文件)并设置"node":true,ESLint会识别node(即以下完整的.eslintrc可用).

Out of the box, my integration of ESLint did not recognize node, but basic review of documentation made clear that by creating the configuration file named .eslintrc at the root of my project folder (with the proper IntelliJ setting to access this file) and setting "node":true, ESLint recognizes node (i.e., the following complete .eslintrc works).

// Contents of .eslintrc at root of project - support for Node and jQuery
{
  "env" : {
    "node" : true,
    "jquery" : true
  },
}

但是,如以下屏幕截图所示,ESLint仍然无法识别require():

However, ESLint still does not recognize require(), as evidenced by this screenshot:

我已在合理的时间内竭尽所能,以寻找有关如何使ESLint识别require()的基本问题的解决方案.特别是,我在此处中找到了可能的提示,建议在(I .eslintrc文件-不能.

I have done my best in a reasonable amount of time searching for a solution to the basic question of how to get ESLint to recognize require(). In particular, I found a possible hint here, where it suggested to add "amd":false in (I presumed) the .eslintrc file - but no go.

这似乎很基本.如何获得.eslintrc识别require()?

This seems basic. How can I get .eslintrc to recognize require()?

(如果在您的答案中,您可以提供见解如何涵盖更一般的情况,那也将有所帮助.谢谢!)

(If, in your answer, you can provide insight how to cover more general cases, that would also be helpful. Thanks!)

推荐答案

问题不在于ESLint.如果您仔细查看邮件,则会显示 JSHint .

The problem is not with ESLint. If you look closely at your message, it says JSHint.

由于您要配置ESLint,所以最简单的解决方案是从IDE中禁用或删除JSHint插件.

Since you're trying to configure ESLint, simplest solution would be to disable or remove JSHint plugin form your IDE.

如果您仍然希望将JSHint与ESLint一起使用,则可以执行以下操作:

If you still want to use JSHint along with ESLint, you can do the following:

单个文件解决方案:在文件顶部添加/* global require */.

Single file solution: add /* global require */ at the top of your file.

所有文件的常规解决方案:在.jshintrc中添加 "node": true 行.

General solution for all files: add "node": true line to your .jshintrc.

这篇关于如何设置.eslintrc识别“需要"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆