# 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.

## 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,
}]
```

## Examples

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

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

Reported:

```js
const user_name = "Ada";

function load_user(user_id) {}
```

Not reported:

```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:

```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`

```js
const user = { first_name: "Ada" };
user.last_name = "Lovelace";
```

```js
const user = { first_name: "Ada" };
user.last_name = "Lovelace";
```

### `classFields`

```js
class User {
  first_name = "Ada";
  full_name() {}
}
```

```js
class User {
  first_name = "Ada";
  full_name() {}
}
```

### `onlyDeclarations`

```js
if (legacy_mode) {
  start();
}
```

```js
if (legacy_mode) {
  start();
}
```

```js
const legacy_mode = true;
```

### `ignoreDestructuring`

```js
const { user_id } = row;
```

```js
const { user_id } = row;
```

A new name that you choose is still checked:

```js
const { user_id: owner_id } = row;
```
