如何让 ESLint 忽略来自其他文件的 class 名称和方法?

How to make ESLint ignore class names and methods from other files?

以前可能有人问过这个问题,但我真的不知道如何搜索它,所以如果有,我真的很抱歉。

假设我有一个名为 a.js 的文件,其中有一个名为 Navigation 的 class,然后在 b.js 我用 class 中的一个方法调用它 getView();

a.js

Navigation.prototype.getView = function getView(id) {
   return this.views[id]; 
};

b.js

var currentView = Navigation.getView(id);

我该如何告诉 ESLint 应该根据 no-undef 规则忽略 Navigation?

您可以尝试使用文件内的globals注释来忽略它。

/* globals MY_GLOBAL */

ESLint 独立检查每个文件,因此它不会解析其他文件中定义的标识符。 /* exported ... */ comment and globals 允许您通知 ESLint 其他文件中的依赖项。

Note that /* exported */ has no effect for any of the following:

  • when the environment is node or commonjs
  • when parserOptions.sourceType is module
  • when ecmaFeatures.globalReturn is true