# id-match

> Require identifier names to match a regular expression

Use this rule to hold a project to one naming convention, for example no underscores or only camelCase. You give it a regular expression, and it reports the names that don't match.

The default pattern, `^.+$`, matches every name, so the rule reports nothing until you set one.

{/* 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]
"id-match" = "error" # or "warn"
```

Every option, set to its default:

```toml bunfig.toml
[lint.rules]
"id-match" = ["error", "^.+$", {
  properties = false,
  classFields = false,
  onlyDeclarations = false,
  ignoreDestructuring = false,
}]
```

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

## Examples

```toml bunfig.toml
[lint.rules]
id-match = ["error", "^[^_]+$"]
```

The examples on this page use `^[^_]+$`, which means no underscores.

Reported:

{/* bad {"options": ["^[^_]+$"], "count": 3} */}
```js
const user_name = "Ada";

function load_user(user_id) {}
```

Not reported:

{/* good {"options": ["^[^_]+$"]} */}
```js
const userName = "Ada";

function loadUser(userId) {}
```

A function you call and a property you read may come from code you don't control, so they aren't checked:

{/* good {"options": ["^[^_]+$"]} */}
```js
const total = get_total(order.line_items);
```

## Options

The first option is the pattern. The second is an object:

| Option | Default | What it does |
| --- | --- | --- |
| `properties` | `false` | Also check object literal keys and the properties you assign to. |
| `classFields` | `false` | Also check class fields. Methods are checked either way. |
| `onlyDeclarations` | `false` | Only check a name where it's declared, not where it's used. |
| `ignoreDestructuring` | `false` | Don't check a destructured variable that keeps the property's name. |

### `properties`

{/* good {"options": ["^[^_]+$"]} */}
```js
const user = { first_name: "Ada" };
user.last_name = "Lovelace";
```

{/* bad {"options": ["^[^_]+$", {"properties": true}], "count": 2} */}
```js
const user = { first_name: "Ada" };
user.last_name = "Lovelace";
```

### `classFields`

{/* bad {"options": ["^[^_]+$"], "count": 1} */}
```js
class User {
  first_name = "Ada";
  full_name() {}
}
```

{/* bad {"options": ["^[^_]+$", {"classFields": true}], "count": 2} */}
```js
class User {
  first_name = "Ada";
  full_name() {}
}
```

### `onlyDeclarations`

{/* bad {"options": ["^[^_]+$"]} */}
```js
if (legacy_mode) {
  start();
}
```

{/* good {"options": ["^[^_]+$", {"onlyDeclarations": true}]} */}
```js
if (legacy_mode) {
  start();
}
```

{/* bad {"options": ["^[^_]+$", {"onlyDeclarations": true}]} */}
```js
const legacy_mode = true;
```

### `ignoreDestructuring`

{/* bad {"options": ["^[^_]+$"]} */}
```js
const { user_id } = row;
```

{/* good {"options": ["^[^_]+$", {"ignoreDestructuring": true}]} */}
```js
const { user_id } = row;
```

A new name that you choose is still checked:

{/* bad {"options": ["^[^_]+$", {"ignoreDestructuring": true}]} */}
```js
const { user_id: owner_id } = row;
```
