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

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

Every option, set to its default:

```toml bunfig.toml
[lint.rules]
"camelcase" = ["error", {
  properties = "always", # "always" or "never"
  ignoreDestructuring = false,
  ignoreImports = false,
  ignoreGlobals = false,
  allow = [], # list of strings
}]
```

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

## Examples

Reported:

{/* bad {"count": 3} */}
```js
const first_name = "Ada";

function full_name(user) {
  return { display_name: user.first + " " + user.last };
}
```

Not reported:

{/* good */}
```js
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. |

{/* good {"options": [{"properties": "never"}]} */}
```js
const 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:

{/* good {"options": [{"ignoreDestructuring": true}]} */}
```js
const { user_id } = await response.json();
```

{/* bad {"options": [{"ignoreDestructuring": true}]} */}
```js
const { id: user_id } = await response.json();
```

{/* good {"options": [{"ignoreImports": true}]} */}
```js
import { 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:

{/* bad {"options": [{"ignoreDestructuring": true}], "count": 1} */}
```js
const { user_id } = await response.json();
console.log(user_id);
const key = "user:" + user_id;
```

{/* bad {"options": [{"ignoreImports": true}], "count": 1} */}
```js
import { unstable_cache } from "next/cache";
export const cache = unstable_cache;
```

{/* good {"options": [{"ignoreGlobals": true}]} */}
```js
/* global api_key */
const key = api_key;
```

{/* good {"options": [{"allow": ["^UNSAFE_", "user_id"]}]} */}
```js
const user_id = 7;

class Form {
  UNSAFE_componentWillMount() {}
}
```
