# no-irregular-whitespace

> Disallow whitespace characters other than the ordinary space, tab and line break

A no-break space (U+00A0) looks exactly like a space, and a zero-width space (U+200B) looks like nothing. They get into a file when you paste from a web page or a chat, or press Option+Space on a Mac. The code may still run, but a search for `total = price` no longer finds the line, and diffs show changes that nobody can see.

Reported characters: U+000B, U+000C, U+0085, U+00A0, U+1680, U+180E, U+2000 to U+200B, U+2028, U+2029, U+202F, U+205F, U+3000 and U+FEFF. A byte order mark at the very start of the file is fine.

Only code is checked by default. In strings, template literals, comments, regular expressions and JSX text these characters are usually there on purpose: French puts a no-break space before `:` and `€`, and Japanese text uses the full-width space U+3000.

This rule is on by default.

{/* Generated by src/codegen/lint-rule-docs.ts. Do not edit this section. */}

## Configure

On by default as an error. To turn it off:

```toml bunfig.toml
[lint.rules]
"no-irregular-whitespace" = "off" # or "warn"
```

Every option, set to its default:

```toml bunfig.toml
[lint.rules]
"no-irregular-whitespace" = ["error", {
  skipStrings = true,
  skipComments = true,
  skipRegExps = true,
  skipTemplates = true,
  skipJSXText = true,
}]
```

{/* End of the generated section. */}

## Examples

Reported. The character after `=` is a no-break space:

{/* bad */}
```js
const total = price * quantity;
```

Not reported, with an ordinary space:

{/* good */}
```js
const total = price * quantity;
```

Not reported either. These no-break spaces are part of the text:

{/* good */}
```jsx
// At most 10 kg.
const weight = "10 kg";
const price = <p>Prix : 10 €</p>;
```

## Options

Each option allows the characters in one kind of place.

| Option | Default | What it does |
| --- | --- | --- |
| `skipStrings` | `true` | Allow them in string literals. |
| `skipComments` | `true` | Allow them in comments. |
| `skipRegExps` | `true` | Allow them in regular expression literals. |
| `skipTemplates` | `true` | Allow them in template literals. |
| `skipJSXText` | `true` | Allow them in JSX text. |

With an ESLint config file the defaults are ESLint's: only `skipStrings` is `true`.

Every example below has a no-break space between `10` and `kg`.

{/* bad {"options": [{"skipStrings": false}]} */}
```js
const weight = "10 kg";
```

{/* bad {"options": [{"skipComments": false, "skipTemplates": false}], "count": 2} */}
```js
// At most 10 kg.
const weight = `10 kg`;
```

{/* good {"options": [{"skipComments": true, "skipTemplates": true}]} */}
```js
// At most 10 kg.
const weight = `10 kg`;
```

{/* bad {"options": [{"skipJSXText": false, "skipRegExps": false}], "count": 2} */}
```jsx
const label = <span>10 kg</span>;
const pattern = /10 kg/;
```

{/* good {"options": [{"skipJSXText": true, "skipRegExps": true}]} */}
```jsx
const label = <span>10 kg</span>;
const pattern = /10 kg/;
```
