#Linter プラグイン
@praha/byethrow-oxlint は、@praha/byethrow 使用時のベストプラクティスを強制する Oxlint プラグインです。
#インストール
npm install -D @praha/byethrow-oxlint#セットアップ
#推奨プリセットを使用する
最も簡単な方法は、推奨プリセットを拡張することです。すべてのルールがデフォルト設定で有効になります。
oxlint.config.ts
import const oxlintByethrowPlugin: OxlintPlugin oxlintByethrowPlugin from '@praha/byethrow-oxlint';
import { function defineConfig<T extends OxlintConfig>(config: T): TDefine an Oxlint configuration with type inference.
@paramconfig - Oxlint configuration@returnsConfig unchanged defineConfig } from 'oxlint';
export default defineConfig<{
extends: OxlintConfig[];
}>(config: {
extends: OxlintConfig[];
}): {
extends: OxlintConfig[];
}
Define an Oxlint configuration with type inference.
@paramconfig - Oxlint configuration@returnsConfig unchanged defineConfig ({
extends: OxlintConfig[] extends : [
const oxlintByethrowPlugin: OxlintPlugin oxlintByethrowPlugin .recommended: OxlintConfig recommended ,
],
});#ルールを手動で設定する
より細かく制御したい場合は、プラグインを読み込んで個別のルールを有効にできます。
oxlint.config.ts
import { function defineConfig<T extends OxlintConfig>(config: T): TDefine an Oxlint configuration with type inference.
@paramconfig - Oxlint configuration@returnsConfig unchanged defineConfig } from 'oxlint';
export default defineConfig<{
jsPlugins: {
name: string;
specifier: string;
}[];
rules: {
'byethrow/consistent-namespace': "error";
'byethrow/no-ambiguous-error-type': "error";
};
}>(config: {
jsPlugins: {
name: string;
specifier: string;
}[];
rules: {
'byethrow/consistent-namespace': "error";
'byethrow/no-ambiguous-error-type': "error";
};
}): {
jsPlugins: {
name: string;
specifier: string;
}[];
rules: {
'byethrow/consistent-namespace': "error";
'byethrow/no-ambiguous-error-type': "error";
};
}
Define an Oxlint configuration with type inference.
@paramconfig - Oxlint configuration@returnsConfig unchanged defineConfig ({
jsPlugins: {
name: string;
specifier: string;
}[]
jsPlugins : [
{
name: string name : 'byethrow',
specifier: string specifier : '@praha/byethrow-oxlint',
},
],
rules: {
'byethrow/consistent-namespace': "error";
'byethrow/no-ambiguous-error-type': "error";
}
rules : {
'byethrow/consistent-namespace': 'error',
'byethrow/no-ambiguous-error-type': 'error',
// ...
},
});#設定
settings に byethrow キーを追加することで、プラグインがbyethrowのインポートを検出する方法をカスタマイズできます。独自パッケージから @praha/byethrow を再エクスポートしている場合などに便利です。
| オプション | 型 | デフォルト | 説明 |
|---|---|---|---|
module | string | string[] | "@praha/byethrow" | byethrowとして扱うモジュールの指定子 |
namespace | string | string[] | ["Result", "R"] | byethrow名前空間として扱うインポート名 |
oxlint.config.ts
import { function defineConfig<T extends OxlintConfig>(config: T): TDefine an Oxlint configuration with type inference.
@paramconfig - Oxlint configuration@returnsConfig unchanged defineConfig } from 'oxlint';
export default defineConfig<{
settings: {
byethrow: {
module: string[];
namespace: string[];
};
};
}>(config: {
settings: {
byethrow: {
module: string[];
namespace: string[];
};
};
}): {
settings: {
byethrow: {
module: string[];
namespace: string[];
};
};
}
Define an Oxlint configuration with type inference.
@paramconfig - Oxlint configuration@returnsConfig unchanged defineConfig ({
settings: {
byethrow: {
module: string[];
namespace: string[];
};
}
settings : {
byethrow: {
module: string[];
namespace: string[];
}
byethrow : {
module: string[] module : ['@praha/byethrow', '@my-org/result'],
namespace: string[] namespace : ['Result', 'R'],
},
},
});#ルール
| ルール | 説明 | 自動修正 |
|---|---|---|
| consistent-namespace | 一貫した名前空間エイリアスを強制 | ✅ |
| no-ambiguous-error-type | 非具体的なエラー型を禁止 | |
| no-ambiguous-success-type | 非具体的な成功型を禁止 | |
| no-negated-type-guards | isSuccess/isFailure の否定を禁止 | ✅ |
| no-throw-in-callback | byethrowコールバック内の throw を禁止 | |
| no-try-catch-in-callback | byethrowコールバック内の try-catch を禁止 | |
| prefer-result-async | Promise<Result> より ResultAsync を優先 | ✅ |
| prefer-result-matchers | toBeSuccess/toBeFailure マッチャーを優先 | ✅ |
| prefer-result-maybe-async | Result | ResultAsync より ResultMaybeAsync を優先 | ✅ |
