Disallow re-declaring a variable with
varafter it has already been declared.
| Type | problem |
| Default severity | warn in recommended; error in strict |
| Fixable | — |
In AMPscript, re-declaring an already-declared variable with var silently resets its value to null. This is a common source of bugs when code is copy-pasted or blocks are re-ordered — the second var @x statement discards any value assigned in between, leading to unexpected empty output or runtime errors downstream.
| Setting | Values | Default |
|---|---|---|
| severity | "error" | "warn" | "off" |
"warn" |
This rule has no configuration options.
Not allowed:
%%[
var @name
set @name = "Alice"
var @name
/* @name is now null */
output(concat("Hello ", @name))
]%%
Allowed:
%%[
var @name
set @name = "Alice"
output(concat("Hello ", @name))
]%%
// eslint.config.js
rules: { 'sfmc/amp-no-var-redeclaration': 'off' }