Skip to content

require-module-level-instantiation

Requires configured classes to be instantiated at module scope.

This rule does nothing until you configure a classes map.

Once configured, it tracks imports that match the class name and source you listed, then reports new ClassName() when it happens inside a non-top-level scope. Top-level module and global scope instantiations are allowed.

The rule handles both direct class imports and member access such as new Library.Log() when the configured class name matches the member name.

Incorrect
import Log from "@rbxts/rbxts-sleitnick-log";
function runTask() {
const log = new Log();
log.Info("running");
}
Correct
import Log from "@rbxts/rbxts-sleitnick-log";
const log = new Log();
function runTask() {
log.Info("running");
}
OptionTypeDefaultNotes
classesRecord<string, string>{}Maps class names to import sources.

Example config:

import ceaseNonsense from "eslint-plugin-cease-nonsense";
export default [
{
plugins: {
"cease-nonsense": ceaseNonsense,
},
rules: {
"cease-nonsense/require-module-level-instantiation": [
"error",
{
classes: {
Log: "@rbxts/rbxts-sleitnick-log",
Server: "@rbxts/net",
},
},
],
},
},
];