require-module-level-instantiation
Requires configured classes to be instantiated at module scope.
Rule details Problem
Section titled “Rule details ”ProblemThis 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.
Examples
Section titled “Examples” 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");}Options
Section titled “Options”| Option | Type | Default | Notes |
|---|---|---|---|
classes | Record<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", }, }, ], }, },];Related rules
Section titled “Related rules” strict-component-boundaries Keeps module boundaries from leaking across folders