Skip to content

prefer-module-scope-constants

Require SCREAMING_SNAKE_CASE variables to be const declarations at module scope.

This rule checks simple identifier names that match SCREAMING_SNAKE_CASE. Those bindings must use const, and they must live at the top level of the module.

If a value needs to change, or it only makes sense inside a function or block, use a different name.

Incorrect
function calculate() {
const PI = 3.14;
}
let MAX_RETRIES = 3;
Correct
const PI = 3.14;
const MAX_RETRIES = 3;
function calculate(radius: number) {
return radius * radius * PI;
}

In script files, the rule also allows a first-level function scope. That matches common CommonJS wrapper patterns.