import/no-amd 限制
作用
禁止使用 AMD 的 require 和 define 调用。
为什么这不好?
AMD(异步模块定义)是一种较旧的模块格式, 在现代 JavaScript 开发中不太常见,尤其是在 Node.js 中 随着 ES modules 和 CommonJS 的广泛使用更是如此。 AMD 引入了不必要的复杂性,通常被认为已经过时。 此规则强制使用更现代的模块系统,以提高 整个代码库的可维护性和一致性。
示例
以下是此规则的错误代码示例:
javascript
require([a, b], function () {});以下是此规则的正确代码示例:
javascript
require("../name");
require(`../name`);如何使用
To enable this rule using the config file or in the CLI, you can use:
json
{
"plugins": ["import"],
"rules": {
"import/no-amd": "error"
}
}ts
import { defineConfig } from "oxlint";
export default defineConfig({
plugins: ["import"],
rules: {
"import/no-amd": "error",
},
});bash
oxlint --deny import/no-amd --import-plugin版本
此规则于 v0.0.16 中添加。
