undefined-variable
What it does
Section titled “What it does”Reports a name that no scope declares, that is not a global of ES2026 (or, in a .cjs file, require, module, exports and global) and that is not in the option globals. typeof x and JSX tags are not reported.
Why it matters
Section titled “Why it matters”An undeclared name fails with a ReferenceError when the line runs, or it silently creates a global when it is assigned. A typo in a name is the usual cause.
To fix, declare the name, import it, or add it to globals if the environment provides it.
Example
Section titled “Example”... $x = $a + $b; [$p, $q] = g(); foreach ($arr as $k => $v) { echo $k . $v . $p . $q . $x; }... } $r = function () use ($x) { return $x + $undefined; }; $s = fn($z) => $z + $x;... $list[] = 1; echo $gg . $st . $m2 . $list . Foo::$bar . $this->z . $_GET['a']; echo isset($maybe) ? "$x {$y}" : ''; return $s;}
function g() { return $top;}
...Configuration
Section titled “Configuration”js: lint: rules: undefined-variable: level: warn # off (default), warn, error options: globals: []php: lint: rules: undefined-variable: level: warn # off (default), warn, error options: globals: []python: lint: rules: undefined-variable: level: warn # off (default), warn, error options: globals: []| Option | Type | Default | Description |
|---|---|---|---|
globals |
list | [] |
Names the environment declares (ESLint’s languageOptions.globals), such as window or console. |
Enabled by the presets: js/eslint-recommended, php/phpstan, python/ruff.
Suppress one line with sudsy-disable-next-line undefined-variable in a comment of the file’s language.
Upstream equivalents
Section titled “Upstream equivalents”The same check in other tools. full: Sudsy reports what the upstream rule reports; partial: only part of it, as the last column says.
| Tool | Rule | Match | What differs |
|---|---|---|---|
| eslint | no-undef |
partial | the typeof option keeps its default; languageOptions.globals is the rule’s globals option, and /*global*/ comments are not read; JSX tags are not references |
| phpstan | variable.undefined |
partial | Only a variable that nothing in its function assigns (PHPStan’s level 0 reports exactly those); a variable passed to a call counts as assigned, and a function with extract, parse_str, include or $$x is not checked. |
| ruff | F821 |
full |