4.0.0 ā€¢ Published 4 months ago

@wayofdev/commitlint-config v4.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
4 months ago

Shareable Commitlint Config

šŸ“„ About

A shareable commitlint configuration for enforcing consistent commit messages in your projects.

ā†’ Purpose

  • Provides a set of rules to ensure that all commits in your project follow a consistent structure.
  • Consistent commit messages are important for project collaboration, maintainability, and project history.
  • The commitlint configuration helps ensure that all commits in your project follow a consistent structure, making it easier for your team to understand what changes were made and why.

šŸ’æ Installation

This package should be added to the root of your monorepo, where you have a file commitlint.config.js and a package.json file. Within your monorepo, you should have a structure with directories for your apps and packages, such as:

.
ā”œā”€ā”€ commitlint.config.js (root)
ā”œā”€ā”€ package.json (root)
ā”œā”€ā”€ apps
ā”‚   ā””ā”€ā”€ my-first-app
ā”‚       ā”œā”€ā”€ package.json
ā”‚       ā””ā”€ā”€ ... (other app files)
ā””ā”€ā”€ packages
    ā””ā”€ā”€ my-first-package
        ā”œā”€ā”€ package.json
        ā””ā”€ā”€ ... (other package files)
  1. To use this configuration, you'll need to install this package as a devDependency in your monorepository's root:

    pnpm add -wD @commitlint/cli @wayofdev/commitlint-config
  2. To configure the commitlint.config.js file, include the following line:

    module.exports = {
      extends: ["@wayofdev/commitlint-config"],
    }

    This extends the @wayofdev/commitlint-config and uses its pre-defined configuration.

    Alternatively the configuration can be defined in a commitlint.config.js, .commitlintrc.js, .commitlintrc, .commitlintrc.json, .commitlintrc.yml file

  3. Install Husky in your monorepository as devDependency. Husky is a handy git hook helper available on npm.

    # Install as dev-dependency into root of monorepo
    $ pnpm add -wD husky is-ci
    
    # Activate hooks
    $ pnpm husky install
  4. Add commit-msg hook:

    npx husky add .husky/commit-msg 'pnpm commitlint --edit "${1}"'
  5. Add scripts to package.json

    pnpm pkg set scripts.lint:commits="pnpm commitlint --from HEAD~1 --to HEAD --verbose"
    
    pnpm pkg set scripts.prepare="is-ci || husky install"

šŸ’» Usage

ā†’ Test simple usage

For a first simple usage test of commitlint you can do the following:

# using pnpm
$ pnpm commitlint --from HEAD~1 --to HEAD --verbose

# or, using npx
$ npx commitlint --from HEAD~1 --to HEAD --verbose

# or, if script was added
$ pnpm lint:commits

This will check your last commit and return an error if invalid or a positive output if valid.

ā†’ Test the hook

You can test the hook by simply committing. If the commit message is valid, the commit will go through, otherwise you will see an error message.

Here's an example of what the error message would look like if your commit message doesn't meet the required format:

$ git commit -m "foo: this will fail"
husky > commit-msg (node v10.1.0)
No staged files match any of provided globs.
ā§—   input: foo: this will fail
āœ–   type must be one of [build, chore, ci, docs, feat, fix, perf, refactor, revert, style, test] [type-enum]

āœ–   found 1 problems, 0 warnings
ā“˜   Get help: https://github.com/conventional-changelog/commitlint/#what-is-commitlint

husky > commit-msg hook failed (add --no-verify to bypass)

If your commit message meets the required format, you should see a message like this:

$ git commit -m "feat: add new feature"
husky > commit-msg (node v10.1.0)
[master 9d41607] feat: add new feature
 1 file changed, 1 insertion(+)

šŸ§© Extending

This shows, how config can be extended with your custom rules.

commitlint.config.js

module.exports = {
  extends: ["@wayofdev/commitlint-config"],
  rules: {
    "body-leading-blank": [2, "always"],
  },
}

šŸ¤ License

Licence

šŸ§± Credits and Useful Resources

Based on:

Related projects:

Guides:

šŸ™†šŸ¼ā€ā™‚ļø Author Information

This repository was created in 2023 by lotyp / wayofdev.

šŸ™Œ Want to Contribute?

Thank you for considering contributing to the wayofdev community! We are open to all kinds of contributions. If you want to:

  • šŸ¤” Suggest a feature
  • šŸ› Report an issue
  • šŸ“– Improve documentation
  • šŸ‘Øā€šŸ’» Contribute to the code

You are more than welcome. Before contributing, kindly check our guidelines.

4.0.0

4 months ago

3.0.5

4 months ago

3.0.4

5 months ago

3.0.3

7 months ago

3.0.2

9 months ago

3.0.1

10 months ago

3.0.0

10 months ago

2.0.7

1 year ago

2.0.5

1 year ago

2.0.6

1 year ago

2.0.4

1 year ago

2.0.3

1 year ago

2.0.2

1 year ago

2.0.1

1 year ago

2.0.0

1 year ago

1.2.1

1 year ago

1.2.0

1 year ago

1.1.0

1 year ago

1.0.3

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago