# bun/no-restricted-text

> Disallow text that matches a pattern in strings, templates, JSX text, comments, and regular expressions

Some mistakes are in the words, not in the code, like an `http://` URL, an old product name, or three dots where the design asks for an ellipsis. This rule reports text that matches a regular expression you give it, with your own message.

The rule does nothing until you list `patterns`. Each match gets its own report.

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

## Configure

Off by default. To turn it on:

```toml bunfig.toml
[lint.rules]
"bun/no-restricted-text" = "error" # or "warn"
```

Every option, set to its default. The ones that are commented out are unset by default.

```toml bunfig.toml
[lint.rules]
"bun/no-restricted-text" = ["error", {
  # patterns = <list of objects>,
}]
```

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

## Examples

These examples use this config:

```toml bunfig.toml
[lint.rules]
"bun/no-restricted-text" = ["error", {
  patterns = [{
    pattern = "http://",
    message = "Use https.",
    in = ["strings", "templates"],
  }],
}]
```

Reported:

{/* bad {"count": 2, "options": [{"patterns": [{"pattern": "http://", "message": "Use https.", "in": ["strings", "templates"]}]}]} */}
```js
const api = "http://api.example.com";
const avatar = `http://img.example.com/${user.id}.png`;
```

Not reported:

{/* good {"options": [{"patterns": [{"pattern": "http://", "message": "Use https.", "in": ["strings", "templates"]}]}]} */}
```js
// This was http:// until the certificate arrived.
const api = "https://api.example.com";
```

## Options

`patterns` is a list of objects with these keys:

| Key | Default | What it does |
| --- | --- | --- |
| `pattern` | required | The source of a JavaScript regular expression. |
| `flags` | `"u"` | Its flags. |
| `message` | The matched text and the pattern | What the report says. |
| `in` | All five | Where to look: `"strings"`, `"templates"`, `"jsxText"`, `"comments"`, `"regularExpressions"`. |

The pattern sees the text as it's written in the file, so an escape such as `\n` in a string is a backslash and an `n`. A pattern that isn't a valid regular expression is a config error.

Text between JSX tags:

{/* bad {"options": [{"patterns": [{"pattern": "\\.\\.\\.", "message": "Use the ellipsis character.", "in": ["jsxText"]}]}]} */}
```jsx
const status = <p>Loading...</p>;
```

{/* good {"options": [{"patterns": [{"pattern": "\\.\\.\\.", "message": "Use the ellipsis character.", "in": ["jsxText"]}]}]} */}
```jsx
const status = <p {...props}>Loading…</p>;
```

With the `i` flag, upper and lower case both match:

{/* bad {"options": [{"patterns": [{"pattern": "acme corp", "flags": "iu", "in": ["strings"]}]}]} */}
```js
const footer = "Copyright ACME Corp";
```
