# unicorn/filename-case

> Enforce one case style for file names

When `userProfile.js`, `UserProfile.js` and `user-profile.js` are all possible, you need to look up the spelling for every import. Capitals are also easy to get wrong without noticing. `import "./userprofile.js"` finds `userProfile.js` on macOS and Windows, where the file system usually ignores case, and fails on Linux. By default this rule requires `kebab-case`.

Only the file name is checked, not its directories. The extension, underscores at the start and the end of the name, `index` files and files that start with a dot aren't checked.

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

Every option, set to its default. The ones that are commented out are unset by default.

```toml bunfig.toml
[lint.rules]
"unicorn/filename-case" = ["error", {
  case = "kebabCase",
  # cases = <value>,
  ignore = [], # list of strings
  multipleFileExtensions = true,
}]
```

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

## Examples

Reported:

{/* bad {"filename": "src/userProfile.js"} */}
```js
export function userProfile() {}
```

{/* bad {"filename": "src/user_profile.js"} */}
```js
export function userProfile() {}
```

Not reported:

{/* good {"filename": "src/user-profile.js"} */}
```js
export function userProfile() {}
```

{/* good {"filename": "src/__mocks__/_user-profile.test.js"} */}
```js
export function userProfile() {}
```

## Options

| Option | Default | What it does |
| --- | --- | --- |
| `case` | `"kebabCase"` | The one style to allow: `"camelCase"`, `"kebabCase"`, `"snakeCase"`, `"pascalCase"`, `"lowercase"` or `"screamingSnakeCase"`. |
| `cases` | | Allow several styles: an object with the names above as keys and `true` as values. Ignored if `case` is set. |
| `ignore` | `[]` | Regular expressions, as strings. A file name that matches one of them isn't checked. |
| `multipleFileExtensions` | `true` | Treat everything after the first dot as the extension. With `false`, only the part after the last dot is the extension. |

A project with React components often wants two styles:

{/* good {"filename": "src/UserProfile.jsx", "options": [{"cases": {"kebabCase": true, "pascalCase": true}}]} */}
```jsx
export const UserProfile = () => <section />;
```

{/* bad {"filename": "src/user_profile.jsx", "options": [{"cases": {"kebabCase": true, "pascalCase": true}}]} */}
```jsx
export const UserProfile = () => <section />;
```

`ignore` matches against the whole file name, including its extension:

{/* good {"filename": "src/LICENSE_header.js", "options": [{"ignore": ["^LICENSE"]}]} */}
```js
export const header = "MIT";
```

In `user-profile.testUtils.js`, `.testUtils.js` counts as the extension by default:

{/* good {"filename": "src/user-profile.testUtils.js"} */}
```js
export function render() {}
```

{/* bad {"filename": "src/user-profile.testUtils.js", "options": [{"multipleFileExtensions": false}]} */}
```js
export function render() {}
```
