#Linter Plugin
@praha/byethrow-oxlint is an Oxlint plugin that enforces best practices when using @praha/byethrow.
#Installation
npm install -D @praha/byethrow-oxlint#Setup
#Using the recommended preset
The easiest way to get started is to extend the recommended preset. It enables all rules with their default settings.
import const oxlintByethrowPlugin: OxlintPlugin oxlintByethrowPlugin from '@praha/byethrow-oxlint';
import { function defineConfig<T extends OxlintConfig>(config: T & OxlintConfig): TDefine an Oxlint configuration with type inference.
@paramconfig - Oxlint configuration@returnsConfig unchanged defineConfig } from 'oxlint';
export default defineConfig<{
extends: OxlintConfig[];
}>(config: {
extends: OxlintConfig[];
} & OxlintConfig): {
extends: OxlintConfig[];
}
Define an Oxlint configuration with type inference.
@paramconfig - Oxlint configuration@returnsConfig unchanged defineConfig ({
extends: OxlintConfig[]Configuration objects to extend.
Import configurations and pass them directly instead of using file paths.
extends : [
const oxlintByethrowPlugin: OxlintPlugin oxlintByethrowPlugin .recommended: OxlintConfig recommended ,
],
});#Configuring rules manually
If you need fine-grained control, you can load the plugin and enable individual rules:
import { function defineConfig<T extends OxlintConfig>(config: T & OxlintConfig): 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";
};
} & OxlintConfig): {
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;
}[] & ExternalPluginEntry[]
JS plugins, allows usage of ESLint plugins with Oxlint.
Read more about JS plugins in
the docs.
Note: JS plugins are in alpha and not subject to semver.
Examples:
Basic usage with a local plugin path.
{
"jsPlugins": [
"./custom-plugin.js"
],
"rules": {
"custom/rule-name": "warn"
}
}
Basic usage with a TypeScript plugin and a local plugin path.
TypeScript plugin files are supported in the following environments:
- Deno and Bun: TypeScript files are supported natively.
- Node.js >=22.18.0 and Node.js ^20.19.0: TypeScript files are supported natively with built-in
type-stripping enabled by default.
For older Node.js versions, TypeScript plugins are not supported. Please use JavaScript plugins or upgrade your Node version.
{
"jsPlugins": [
"./custom-plugin.ts"
],
"rules": {
"custom/rule-name": "warn"
}
}
Using a built-in Rust plugin alongside a JS plugin with the same name
by giving the JS plugin an alias.
{
"plugins": [
"import"
],
"jsPlugins": [
{
"name": "import-js",
"specifier": "eslint-plugin-import"
}
],
"rules": {
"import/no-cycle": "error",
"import-js/no-unresolved": "warn"
}
}
jsPlugins : [
{
name: string name : 'byethrow',
specifier: string specifier : '@praha/byethrow-oxlint',
},
],
rules: {
'byethrow/consistent-namespace': "error";
'byethrow/no-ambiguous-error-type': "error";
} & DummyRuleMap
Example
.oxlintrc.json
{
"$schema": "./node_modules/oxlint/configuration_schema.json",
"rules": {
"eqeqeq": "warn",
"import/no-cycle": "error",
"prefer-const": [
"error",
{
"ignoreReadBeforeAssign": true
}
]
}
}
See Oxlint Rules for the list of
rules.
rules : {
'byethrow/consistent-namespace': 'error',
'byethrow/no-ambiguous-error-type': 'error',
// ...
},
});#Settings
You can customize how the plugin detects byethrow imports by adding a byethrow key under settings. This is useful when you re-export @praha/byethrow from your own package.
| Option | Type | Default | Description |
|---|---|---|---|
module | string | string[] | "@praha/byethrow" | Module specifiers to treat as byethrow |
namespace | string | string[] | ["Result", "R"] | Import names to treat as the byethrow namespace |
import { function defineConfig<T extends OxlintConfig>(config: T & OxlintConfig): 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[];
};
};
} & OxlintConfig): {
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[];
};
} & OxlintPluginSettings
Plugin-specific configuration for both built-in and custom plugins.
This includes settings for built-in plugins such as react and jsdoc
as well as configuring settings for JS custom plugins loaded via jsPlugins.
settings : {
byethrow: {
module: string[];
namespace: string[];
}
byethrow : {
module: string[] module : ['@praha/byethrow', '@my-org/result'],
namespace: string[] namespace : ['Result', 'R'],
},
},
});#Rules
| Rule | Description | Fixable |
|---|---|---|
| consistent-namespace | Enforce consistent namespace alias | ✅ |
| no-ambiguous-error-type | Disallow non-specific error types | |
| no-ambiguous-success-type | Disallow non-specific success types | |
| no-negated-type-guards | Disallow negated isSuccess/isFailure | ✅ |
| no-throw-in-callback | Disallow throw in byethrow callbacks | |
| no-try-catch-in-callback | Disallow try-catch in byethrow callbacks | |
| prefer-result-async | Prefer ResultAsync over Promise<Result> | ✅ |
| prefer-result-matchers | Prefer toBeSuccess/toBeFailure matchers | ✅ |
| prefer-result-maybe-async | Prefer ResultMaybeAsync over Result | ResultAsync | ✅ |
