# if statement without braces

Source: https://findproxyforurl.net/rules/if-without-braces/ · last updated 2026-10-04

Rule PAC-B001 (`if-without-braces`), severity low, category: Best practice and maintainability.

if (cond) return "DIRECT"; works, but the next person who adds a line under it changes the logic without noticing. PAC files are edited in production by people who are not JavaScript developers; braces are cheap insurance.

## Why it matters

Without braces only the first statement belongs to the `if`. Adding a log line, a
variable assignment or a second return later silently moves the original statement out of
the condition or leaves the new one unconditional. The pattern is responsible for a whole
class of "it worked until we added one line" incidents. Consistent braces also make the
structure visible in diffs.


## How to fix

Wrap every if/else body in braces.

## Bad

```js
function FindProxyForURL(url, host) {
  if (isPlainHostName(host))
    return "DIRECT";
  return "PROXY proxy.corp.example:8080";
}
```

## Good

```js
function FindProxyForURL(url, host) {
  if (isPlainHostName(host)) {
    return "DIRECT";
  }
  return "PROXY proxy.corp.example:8080";
}
```
