# Commit Linter

<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->

- [commitlint.config.js](#commitlintconfigjs)
  - [Setup](#setup)
  - [Commit Message Format](#commit-message-format)
  - [Breaking Change](#breaking-change)
  - [Types](#types)
  - [Examples](#examples)
    - [Valid Local Commits:](#valid-local-commits)
    - [Valid PR Titles](#valid-pr-titles)

<!-- END doctoc generated TOC please keep comment here to allow auto update -->

## commitlint.config.js

The commit linter follows [conventional changelog](https://github.com/conventional-changelog/commitlint/releases) styled commits, which is similar to angular styled commits. Import `commitlint.config.js` from this project and re-export it within your own project's `commitlint.config.js`.

### Setup

```js
module.exports = require('@box/frontend/commitlint/commitlint.config.js');
```

You will also need to use something like [husky](https://github.com/typicode/husky) for git hooks. And then add the following to your `package.json`.

```js
  "husky": {
    "hooks": {
      "commit-msg": "commitlint -e"
    }
  }
```

### Commit Message Format

```
type(optional-scope): description
[body] # Required for feat, fix, and refactor commits
```

### Breaking Change

Breaking changes must be documented in the commit body starting with `BREAKING CHANGE:`:

```
feat(api): change auth implementation
BREAKING CHANGE: Oauth2 flow now requires 2fa
- Old client credential flow removed
```

### Types

| Type     | Description                                         | Body Required |
| -------- | --------------------------------------------------- | ------------- |
| feat     | New features                                        | Yes           |
| fix      | Bug fixes                                           | Yes           |
| refactor | Code changes that neither fix bugs nor add features | Yes           |
| docs     | Documentation changes                               | No            |
| style    | Code style changes (whitespace, formatting, etc)    | No            |
| perf     | Performance improvements                            | No            |
| test     | Adding or updating tests                            | No            |
| chore    | Maintenance tasks, dependency updates               | No            |
| revert   | Reverting previous commits                          | No            |
| i18n     | Internationalization changes                        | No            |
| l10n     | Localization/translation content updates            | No            |
| ci       | Changes to our CI configuration files and script    | No            |

### Examples

#### Valid Local Commits:

```js
# Bug fix in React app (body required)
fix(auth): resolve token refresh race condition

Fixed issue where multiple auth token refresh attempts could happen
simultaneously, causing API errors. Implemented a mutex pattern to
ensure only one refresh happens at a time.

# Documentation update (body optional)
docs(readme): add component API documentation
```

#### Valid PR Titles

```js
feat(components): add file preview component
fix(auth): resolve token refresh race condition
docs(readme): add component API documentation
```
