PAC-C017 · constant-condition

Condition is a constant

medium · Correctness

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 checker

Good

function FindProxyForURL(url, host) {
  if (isPlainHostName(host)) {
    return "DIRECT";
  }
  return "PROXY proxy.corp.example:8080";
}
Open good example in checker

Related rules

References