@typescript-eslint/no-unnecessary-qualifier
Disallow naming the enclosing namespace or enum where the short name works
fixableneeds types
Also called typescript-eslint/no-unnecessary-qualifier, typescript/no-unnecessary-qualifier
Inside a namespace or an enum, its own members are in scope. Writing Shapes.Circle inside Shapes means the same as Circle.
--fix removes the qualifier.
Configure#
Off by default. This rule needs types, so turning it on makes bun lint type check your code first.
bunfig.toml
[lint.rules]
"@typescript-eslint/no-unnecessary-qualifier" = "error" # or "warn"Examples#
example.ts2 problems
namespace Shapes {
export interface Circle {
radius: number;
}
export const unit: ShapesQualifier is unnecessary since Circle is in scope..Circle = { radius: 1 };
}
enum Level {
Low = 1,
Default = LevelQualifier is unnecessary since Low is in scope..Low,
}example.tsNo problems
namespace Shapes {
export interface Circle {
radius: number;
}
export const unit: Circle = { radius: 1 };
}
enum Level {
Low = 1,
Default = Low,
}
const circle: Shapes.Circle = Shapes.unit;Here limit alone would be the local constant, so Config.limit stays:
example.tsNo problems
namespace Config {
export const limit = 10;
export function clamp(value: number) {
const limit = value * 2;
return Math.min(limit, Config.limit);
}
}