Skip to content

VBC-215: global-pollutant

warning

Category: clean-code
Analysis: Regex (line by line)
File types: .js, .ts, .tsx, .astro
Scope: source code only, ignoring anything inside strings and comments
Tags: clean-code security

What it reports

Assignment to a window property at line {line}. Globals collide across scripts and outlive the code that set them. Export the value, or attach it under one namespaced object if a global is genuinely needed.

Flagged

js
window.myApp = createApp();

Not flagged

js
window.location = target;
js
window.onload = init;
js
if (window.myApp === undefined) { boot(); }

Pattern

regex
window\.(?!location\b|on[a-z]+\b|name\b|opener\b|status\b|document\b|history\b|scrollX\b|scrollY\b|top\b|self\b|parent\b)[a-zA-Z0-9_$]+\s*=(?!=)

Released under the MIT License.