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