Skip to content
NewBun 1.4.5 is out. Release notes
AphrodyBun

Linter · Rules

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:

bunfig.toml
[lint.rules]
"id-match" = "error" # or "warn"

Every option, set to its default:

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

Examples

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

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

Reported:

const user_name = "Ada";

function load_user(user_id) {}

Not reported:

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:

const total = get_total(order.line_items);

Options

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

OptionDefaultWhat it does
propertiesfalseAlso check object literal keys and the properties you assign to.
classFieldsfalseAlso check class fields. Methods are checked either way.
onlyDeclarationsfalseOnly check a name where it's declared, not where it's used.
ignoreDestructuringfalseDon't check a destructured variable that keeps the property's name.

properties

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

classFields

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

onlyDeclarations

if (legacy_mode) {
  start();
}
if (legacy_mode) {
  start();
}
const legacy_mode = true;

ignoreDestructuring

const { user_id } = row;
const { user_id } = row;

A new name that you choose is still checked:

const { user_id: owner_id } = row;