Condition is a constant
medium
if (true), if (0) or if ("DIRECT") does not depend on the request. Everything after an always-true branch that returns is dead; an always-false branch is dead itself.
Why it matters
Constant conditions are usually debugging leftovers (“temporarily force DIRECT”) or the
result of a typo that turned a comparison into a literal. In a PAC an always-true if
with a return makes the whole rest of the function unreachable, including the real default
route. A string literal is truthy when non-empty, so if ("DIRECT") is always taken.
How to fix
Replace the constant with the intended comparison or remove the branch.
Examples
Bad
function FindProxyForURL(url, host) {
if (true) {
return "DIRECT";
}
return "PROXY proxy.corp.example:8080";
}
Open bad example in checkerGood
function FindProxyForURL(url, host) {
if (isPlainHostName(host)) {
return "DIRECT";
}
return "PROXY proxy.corp.example:8080";
}
Open good example in checkerRelated rules
- Statements after an unconditional return PAC-E016
- Assignment used as a condition PAC-E009