Skip to main content

JavaScript 常见问题解答

我的 lint 规则之一在纯 JavaScript 文件上无法正常工作

¥One of my lint rules isn't working correctly on a pure JavaScript file

这是可以预料到的 - ESLint 规则不会故意检查文件扩展名,因为这会在使用非标准扩展名的环境中导致问题(例如,.vue.md 文件都可以包含要进行 linted 的 TypeScript 代码)。

¥This is to be expected - ESLint rules do not check file extensions on purpose, as it causes issues in environments that use non-standard extensions (for example, a .vue and a .md file can both contain TypeScript code to be linted).

如果你有一些纯 JavaScript 代码,你不想应用某些 lint 规则,那么你可以使用 ESLint 的 overrides 配置 关闭某些规则,甚至根据 glob 模式更改解析器。

¥If you have some pure JavaScript code that you do not want to apply certain lint rules to, then you can use ESLint's overrides configuration to turn off certain rules, or even change the parser based on glob patterns.

我应该在转译的输出 JavaScript 文件上运行 ESLint 吗?

¥Should I run ESLint on transpiled output JavaScript files?

不。

¥No.

源 TypeScript 文件包含输出 JavaScript 文件的所有内容以及类型注释。对输出 JavaScript 文件进行 linting 并没有什么好处。

¥Source TypeScript files have all the content of output JavaScript files, plus type annotations. There's no benefit to also linting output JavaScript files.