For AI agents: the complete documentation index is available at /byethrow/ja/llms.txt, the full documentation bundle is available at /byethrow/ja/llms-full.txt, and this page is available as Markdown at /byethrow/ja/guide/ecosystem/linter/consistent-namespace.md.
  • 日本語
  • consistent-namespace

    @praha/byethrow を常に同じ名前空間のエイリアス(Result または R)でインポートすることを強制します。

    このルールは自動修正に対応しています。修正時には、インポートとそのすべての参照がリネームされます。

    ルールの詳細

    @praha/byethrow は同じ関数群を Result と R の両方の名前でエクスポートしています。 Result のインポート方法で説明しているとおり、1 つのコードベースで両方を使うとコードの一貫性が失われ、検索もしにくくなります。 このルールは、ローカル名が推奨するエイリアスと異なるインポートをすべて報告します。

    誤った例

    // ❌ Result を推奨しているのに R を使っている
    import { 
    import R
    R
    } from '@praha/byethrow';
    const
    const success: R.Result<42, never>
    success
    =
    import R
    R
    .
    function succeed<42>(value: 42): R.Result<42, never> (+1 overload)

    Creates a Success result from a given value.

    Passing a Promise is allowed, but it is recommended to await it before passing to succeed.

    @typeParamT - The type of the value to wrap.@returnsA Result containing the given value.@example

    Synchronous Usage

    import { Result } from '@praha/byethrow';
    
    const result = Result.succeed(42);
    // Result.Result<42, never>
    @example

    With No Value

    import { Result } from '@praha/byethrow';
    
    const result = Result.succeed();
    // Result.Result<void, never>
    @seecollect - For collect multiple Results into a single Result.@seesequence - For sequence multiple Results into a single Result.@categoryCreators
    succeed
    (42);
    // ❌ Result と R を混在させている
    import { 
    import Result
    Result
    ,
    import R
    R
    } from '@praha/byethrow';
    const
    const success: Result.Result<42, never>
    success
    =
    import Result
    Result
    .
    function succeed<42>(value: 42): Result.Result<42, never> (+1 overload)

    Creates a Success result from a given value.

    Passing a Promise is allowed, but it is recommended to await it before passing to succeed.

    @typeParamT - The type of the value to wrap.@returnsA Result containing the given value.@example

    Synchronous Usage

    import { Result } from '@praha/byethrow';
    
    const result = Result.succeed(42);
    // Result.Result<42, never>
    @example

    With No Value

    import { Result } from '@praha/byethrow';
    
    const result = Result.succeed();
    // Result.Result<void, never>
    @seecollect - For collect multiple Results into a single Result.@seesequence - For sequence multiple Results into a single Result.@categoryCreators
    succeed
    (42);
    const
    const failure: Result.Result<never, Error>
    failure
    =
    import R
    R
    .
    function fail<Error>(error: Error): Result.Result<never, Error> (+1 overload)

    Creates a Failure result from a given error.

    Passing a Promise is allowed, but it is recommended to await it before passing to fail.

    @typeParamE - The type of the error to wrap.@returnsA Result containing the given error.@example

    Synchronous Usage

    import { Result } from '@praha/byethrow';
    
    const result = Result.fail('Something went wrong');
    // Result.Result<never, string>
    @example

    With No Value

    import { Result } from '@praha/byethrow';
    
    const result = Result.fail();
    // Result.Result<never, void>
    @seecollect - For collect multiple Results into a single Result.@seesequence - For sequence multiple Results into a single Result.@categoryCreators
    fail
    (new
    var Error: ErrorConstructor
    new (message?: string, options?: ErrorOptions) => Error (+1 overload)
    Error
    ('Something went wrong'));

    正しい例

    // ✅ Result で統一している
    import { 
    import Result
    Result
    } from '@praha/byethrow';
    const
    const success: Result.Result<42, never>
    success
    =
    import Result
    Result
    .
    function succeed<42>(value: 42): Result.Result<42, never> (+1 overload)

    Creates a Success result from a given value.

    Passing a Promise is allowed, but it is recommended to await it before passing to succeed.

    @typeParamT - The type of the value to wrap.@returnsA Result containing the given value.@example

    Synchronous Usage

    import { Result } from '@praha/byethrow';
    
    const result = Result.succeed(42);
    // Result.Result<42, never>
    @example

    With No Value

    import { Result } from '@praha/byethrow';
    
    const result = Result.succeed();
    // Result.Result<void, never>
    @seecollect - For collect multiple Results into a single Result.@seesequence - For sequence multiple Results into a single Result.@categoryCreators
    succeed
    (42);
    const
    const failure: Result.Result<never, Error>
    failure
    =
    import Result
    Result
    .
    function fail<Error>(error: Error): Result.Result<never, Error> (+1 overload)

    Creates a Failure result from a given error.

    Passing a Promise is allowed, but it is recommended to await it before passing to fail.

    @typeParamE - The type of the error to wrap.@returnsA Result containing the given error.@example

    Synchronous Usage

    import { Result } from '@praha/byethrow';
    
    const result = Result.fail('Something went wrong');
    // Result.Result<never, string>
    @example

    With No Value

    import { Result } from '@praha/byethrow';
    
    const result = Result.fail();
    // Result.Result<never, void>
    @seecollect - For collect multiple Results into a single Result.@seesequence - For sequence multiple Results into a single Result.@categoryCreators
    fail
    (new
    var Error: ErrorConstructor
    new (message?: string, options?: ErrorOptions) => Error (+1 overload)
    Error
    ('Something went wrong'));

    オプション

    推奨するエイリアスを文字列で指定します。デフォルトは "Result" です。

    R を推奨する場合は次のように設定します。

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

    Define an Oxlint configuration with type inference.

    @paramconfig - Oxlint configuration@returnsConfig unchanged
    defineConfig
    } from 'oxlint';
    export default
    defineConfig<{
        rules: {
            'byethrow/consistent-namespace': ["error", "R"];
        };
    }>(config: {
        rules: {
            'byethrow/consistent-namespace': ["error", "R"];
        };
    } & OxlintConfig): {
        rules: {
            'byethrow/consistent-namespace': ["error", "R"];
        };
    }

    Define an Oxlint configuration with type inference.

    @paramconfig - Oxlint configuration@returnsConfig unchanged
    defineConfig
    ({
    rules: {
        'byethrow/consistent-namespace': ["error", "R"];
    } & 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', 'R'], }, });

    このオプションを指定すると、次のコードが正しい例になります。

    // ✅ R で統一している
    import { 
    import R
    R
    } from '@praha/byethrow';
    const
    const success: R.Result<42, never>
    success
    =
    import R
    R
    .
    function succeed<42>(value: 42): R.Result<42, never> (+1 overload)

    Creates a Success result from a given value.

    Passing a Promise is allowed, but it is recommended to await it before passing to succeed.

    @typeParamT - The type of the value to wrap.@returnsA Result containing the given value.@example

    Synchronous Usage

    import { Result } from '@praha/byethrow';
    
    const result = Result.succeed(42);
    // Result.Result<42, never>
    @example

    With No Value

    import { Result } from '@praha/byethrow';
    
    const result = Result.succeed();
    // Result.Result<void, never>
    @seecollect - For collect multiple Results into a single Result.@seesequence - For sequence multiple Results into a single Result.@categoryCreators
    succeed
    (42);
    const
    const failure: R.Result<never, Error>
    failure
    =
    import R
    R
    .
    function fail<Error>(error: Error): R.Result<never, Error> (+1 overload)

    Creates a Failure result from a given error.

    Passing a Promise is allowed, but it is recommended to await it before passing to fail.

    @typeParamE - The type of the error to wrap.@returnsA Result containing the given error.@example

    Synchronous Usage

    import { Result } from '@praha/byethrow';
    
    const result = Result.fail('Something went wrong');
    // Result.Result<never, string>
    @example

    With No Value

    import { Result } from '@praha/byethrow';
    
    const result = Result.fail();
    // Result.Result<never, void>
    @seecollect - For collect multiple Results into a single Result.@seesequence - For sequence multiple Results into a single Result.@categoryCreators
    fail
    (new
    var Error: ErrorConstructor
    new (message?: string, options?: ErrorOptions) => Error (+1 overload)
    Error
    ('Something went wrong'));