Skip to content
← Back to rules

unicorn/require-module-attributes スタイル

An auto-fix is available for this rule.

何をするか

このルールは、インポート/エクスポート文および import() 式で空でない属性リストを強制します。

なぜ悪いのか

インポート属性は、モジュールの読み込み方法に関するメタデータを提供することを目的としています(例:with { type: "json" })。空の属性オブジェクトは情報を提供せず、削除すべきです。

このルールに違反するコードの例:

js
import foo from "foo" with {};

export { foo } from "foo" with {};

const foo = await import("foo", {});

const foo = await import("foo", { with: {} });

このルールに準拠するコードの例:

js
import foo from "foo";

export { foo } from "foo";

const foo = await import("foo");

const foo = await import("foo");

使用方法

設定ファイルまたは CLI でこのルールを有効化するには、次のように使用できます:

json
{
  "rules": {
    "unicorn/require-module-attributes": "error"
  }
}
bash
oxlint --deny unicorn/require-module-attributes

参照