Skip to content

No Instance Methods Without this

ErrorRoblox
small-rules/no-instance-methods-without-this

Detect instance methods that do not use 'this' and suggest converting them to standalone functions for better performance in roblox-ts.

Rationale

If a method never touches this, it shouldn’t be a method. In roblox-ts, instance methods carry metatable overhead even when they don’t use the instance. A standalone function is just faster.

This catches any non-static method that doesn’t reference this or super anywhere in its body. You can scope it with checkPrivate, checkProtected, and checkPublic if you only care about some visibility levels.

Won’t fire on static methods or constructors – those are fine. Only flags genuine instance methods that could be free functions.

Diagnostic Messages

noInstanceMethodWithoutThis
Method '{{methodName}}' does not use 'this' and creates unnecessary metatable overhead in roblox-ts. Convert it to a standalone function for better performance.

Configuration

This rule accepts one options object after the severity.

checkPrivateOptional

Check private methods (default: true)

checkProtectedOptional

Check protected methods (default: true)

checkPublicOptional

Check public methods (default: true)

{
"jsPlugins": [
"@pobammer-ts/small-rules"
],
"rules": {
"small-rules/no-instance-methods-without-this": [
"error",
{
"checkPrivate": true,
"checkProtected": true,
"checkPublic": true
}
]
}
}

Examples

instance method without this
class MyClass {
private notifyChanges(value: number): void {
print(value);
}
}
static method without this
class MyClass {
static helper(): void {
print("static");
}
}