prefer-module-scope-constants
Require SCREAMING_SNAKE_CASE variables to be const declarations at module scope.
Rule details Suggestion
Section titled “Rule details ”SuggestionThis 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.
Examples
Section titled “Examples” Incorrect
Local or mutable uppercase names
Section titled “Local or mutable uppercase names”function calculate() { const PI = 3.14;}
let MAX_RETRIES = 3; Correct
Module-scope constants
Section titled “Module-scope constants”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.
Related rules
Section titled “Related rules” prefer-pascal-case-enums Keeps enum names and members in PascalCase