• English
  • 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

    The easiest way to get started is to extend the recommended preset. It enables all rules with their default settings.

    oxlint.config.ts
    import 
    const oxlintByethrowPlugin: OxlintPlugin
    oxlintByethrowPlugin
    from '@praha/byethrow-oxlint';
    import {
    function defineConfig<T extends OxlintConfig>(config: T): T

    Define 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
    ,
    ], });

    Configuring rules manually

    If you need fine-grained control, you can load the plugin and enable individual rules:

    oxlint.config.ts
    import { 
    function defineConfig<T extends OxlintConfig>(config: T): T

    Define 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

    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.

    OptionTypeDefaultDescription
    modulestring | string[]"@praha/byethrow"Module specifiers to treat as byethrow
    namespacestring | string[]["Result", "R"]Import names to treat as the byethrow namespace
    oxlint.config.ts
    import { 
    function defineConfig<T extends OxlintConfig>(config: T): T

    Define 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'],
    }, }, });

    Rules

    RuleDescriptionFixable
    consistent-namespaceEnforce consistent namespace alias
    no-ambiguous-error-typeDisallow non-specific error types
    no-ambiguous-success-typeDisallow non-specific success types
    no-negated-type-guardsDisallow negated isSuccess/isFailure
    no-throw-in-callbackDisallow throw in byethrow callbacks
    no-try-catch-in-callbackDisallow try-catch in byethrow callbacks
    prefer-result-asyncPrefer ResultAsync over Promise<Result>
    prefer-result-matchersPrefer toBeSuccess/toBeFailure matchers
    prefer-result-maybe-asyncPrefer ResultMaybeAsync over Result | ResultAsync