Skip to content

staticMemberOnlyClasses

Reports classes that only contain static members.

✅ This rule is included in the ts logicalStrict presets.

Classes that contain only static members are essentially being used as namespaces. In JavaScript and TypeScript, objects and module-level exports are more idiomatic and straightforward.

This rule reports on any class that only contains static members.

class
class MathUtils
MathUtils
{
static
MathUtils.PI: number
PI
= 3.14159;
static
MathUtils.add(a: number, b: number): number
add
(
a: number
a
: number,
b: number
b
: number) {
return
a: number
a
+
b: number
b
;
}
}
class
class Config
Config
{
static
Config.defaultValue: number
defaultValue
= 42;
constructor() {}
}
class
class StaticAccessors
StaticAccessors
{
static get
StaticAccessors.value: number
value
() {
return 42;
}
}

This rule is not configurable.

If your codebase uses classes as namespaces for organizing related static utilities, and you don’t mind the extra complexity of classes, you may want to disable this rule. Some frameworks or patterns may also require static-only classes for specific use cases. You might consider using Flint disable comments and/or configuration file disables for those specific situations instead of completely disabling this rule.

Made with ❤️‍🔥 around the world by the Flint team and contributors.