#consistent-namespace
Enforces that @praha/byethrow is always imported under the same namespace alias, either Result or R.
This rule is auto-fixable. The fix renames the import and every reference to it.
#Rule Details
@praha/byethrow exports the same functions as both Result and R.
Using both in one codebase makes the code inconsistent and harder to search, as explained in Importing Result.
This rule reports every import whose local name is not the preferred alias.
#Incorrect
// ❌ R is used although Result is preferred
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.@exampleSynchronous Usage
import { Result } from '@praha/byethrow';
const result = Result.succeed(42);
// Result.Result<42, never>
@exampleWith 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);// ❌ Mixing Result and 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.@exampleSynchronous Usage
import { Result } from '@praha/byethrow';
const result = Result.succeed(42);
// Result.Result<42, never>
@exampleWith 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.@exampleSynchronous Usage
import { Result } from '@praha/byethrow';
const result = Result.fail('Something went wrong');
// Result.Result<never, string>
@exampleWith 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'));#Correct
// ✅ Using Result consistently
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.@exampleSynchronous Usage
import { Result } from '@praha/byethrow';
const result = Result.succeed(42);
// Result.Result<42, never>
@exampleWith 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.@exampleSynchronous Usage
import { Result } from '@praha/byethrow';
const result = Result.fail('Something went wrong');
// Result.Result<never, string>
@exampleWith 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'));#Options
The rule accepts the preferred alias as a string. The default is "Result".
To prefer R instead:
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<{
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'],
},
});With this option, the following code is correct:
// ✅ Using R consistently
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.@exampleSynchronous Usage
import { Result } from '@praha/byethrow';
const result = Result.succeed(42);
// Result.Result<42, never>
@exampleWith 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.@exampleSynchronous Usage
import { Result } from '@praha/byethrow';
const result = Result.fail('Something went wrong');
// Result.Result<never, string>
@exampleWith 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'));