camelcase
Require camelCase names for variables, functions and properties
JavaScript's built-in APIs and most libraries use camelCase. If a codebase has both user_name and userName, you have to look up which spelling each variable uses.
The rule reports names with an underscore in the middle. Underscores at the start or the end (_private, unused_) and names in capitals (MAX_RETRIES) are allowed. Reading a property (row.first_name), a key in quotes and a name in a call (get_user()) aren't reported either, because those names often come from code you don't control.
Configure#
Off by default. To turn it on:
[lint.rules]
"camelcase" = "error" # or "warn"Every option, set to its default:
[lint.rules]
"camelcase" = ["error", {
properties = "always", # "always" or "never"
ignoreDestructuring = false,
ignoreImports = false,
ignoreGlobals = false,
allow = [], # list of strings
}]Examples#
const first_nameIdentifier first_name is not in camel case. = "Ada";
function full_nameIdentifier full_name is not in camel case.(user) {
return { display_nameIdentifier display_name is not in camel case.: user.first + " " + user.last };
}const MAX_RETRIES = 3;
const _cache = new Map();
const firstName = row.first_name;
const user = get_user(firstName);
function fullName(user) {
return { displayName: user.first + " " + user.last, "sort_key": user.last };
}Options#
| Option | Default | What it does |
|---|---|---|
properties | "always" | "never" stops checking property names: object literal keys, class members, and a.b_c = 1. |
ignoreDestructuring | false | Allow a destructured variable that keeps the property's name. |
ignoreImports | false | Allow a named import that keeps the name it's exported with. |
ignoreGlobals | false | Allow the global variables that your config or a /* global */ comment declares. |
allow | [] | Names to allow. Each entry is a name or a regular expression. |
{ "properties": "never" }No problemsconst body = { user_id: 7 };
body.created_at = Date.now();With ignoreDestructuring, only the variable with the same name as the property is allowed. A new name is still checked:
{ "ignoreDestructuring": true }No problemsconst { user_id } = await response.json();{ "ignoreDestructuring": true }1 problemconst { id: user_idIdentifier user_id is not in camel case. } = await response.json();{ "ignoreImports": true }No problemsimport { unstable_cache } from "next/cache";ignoreDestructuring and ignoreImports only cover the line that creates the variable. Using it later is still reported, except where it's called or passed as an argument:
{ "ignoreDestructuring": true }1 problemconst { user_id } = await response.json();
console.log(user_id);
const key = "user:" + user_idIdentifier user_id is not in camel case.;{ "ignoreImports": true }1 problemimport { unstable_cache } from "next/cache";
export const cache = unstable_cacheIdentifier unstable_cache is not in camel case.;{ "ignoreGlobals": true }No problems/* global api_key */
const key = api_key;{ "allow": ["^UNSAFE_", "user_id"] }No problemsconst user_id = 7;
class Form {
UNSAFE_componentWillMount() {}
}