Skip to content
← Back to rules

import/no-named-export Style

它的作用

禁止命名导出。

为什么这不好?

命名导出要求严格的标识符匹配,容易导致脆弱的导入, 而默认导出会强制使用单一、一致的模块入口点。

示例

以下是此规则的错误代码示例:

js
export const foo = "foo";

const bar = "bar";
export { bar };

以下是此规则的正确代码示例:

js
export default 'bar';

const foo = 'foo';
export { foo as default }

如何使用

To enable this rule using the config file or in the CLI, you can use:

json
{
  "plugins": ["import"],
  "rules": {
    "import/no-named-export": "error"
  }
}
ts
import { defineConfig } from "oxlint";

export default defineConfig({
  plugins: ["import"],
  rules: {
    "import/no-named-export": "error",
  },
});
bash
oxlint --deny import/no-named-export --import-plugin

版本

此规则已在 v1.19.0 中添加。

参考资料