### Install and Run Commitlint Development Setup Source: https://github.com/conventional-changelog/commitlint/blob/master/README.md Instructions for cloning the repository, installing dependencies, and running build or watch tasks for development. Use `pnpm start` to rebuild on change. ```sh git clone git@github.com:conventional-changelog/commitlint.git cd commitlint pnpm install pnpm build # run build tasks pnpm start # rebuild on change (tsc -b --watch) node @commitlint/cli/cli.js # run CLI ``` -------------------------------- ### Example Workspace Setup Source: https://github.com/conventional-changelog/commitlint/blob/master/@commitlint/config-workspace-scopes/readme.md Demonstrates a typical package.json with workspaces and the corresponding commitlint configuration. ```json { "workspaces": ["packages/*"] } ``` ```javascript { extends: ['@commitlint/config-workspace-scopes'] } ``` -------------------------------- ### Install and Configure @commitlint/prompt-cli Source: https://github.com/conventional-changelog/commitlint/blob/master/@commitlint/prompt-cli/README.md Installs the prompt CLI and an example Angular configuration globally. Creates a basic commitlint configuration file. ```sh npm install -g @commitlint/prompt-cli @commitlint/config-angular echo "export default {extends: ['@commitlint/config-angular']};" > commitlint.config.js ``` -------------------------------- ### Install and Configure Source: https://github.com/conventional-changelog/commitlint/blob/master/@commitlint/config-workspace-scopes/readme.md Install the necessary packages and create a commitlint configuration file. ```sh npm install --save-dev @commitlint/config-workspace-scopes @commitlint/cli echo "export default {extends: ['@commitlint/config-workspace-scopes']};" > commitlint.config.js ``` -------------------------------- ### Install Dependencies and Configure Commitlint Source: https://github.com/conventional-changelog/commitlint/blob/master/@commitlint/prompt/README.md Installs the necessary packages and creates a basic commitlint configuration file. Ensure commitizen is also installed. ```bash npm install --save-dev @commitlint/prompt @commitlint/config-conventional commitizen echo "module.exports = {extends: ['@commitlint/config-conventional']};" > commitlint.config.js ``` -------------------------------- ### Install and Configure Commitlint Source: https://github.com/conventional-changelog/commitlint/blob/master/@commitlint/config-pnpm-scopes/readme.md Install the necessary packages and create a commitlint configuration file. ```bash npm install --save-dev @commitlint/config-pnpm-scopes @commitlint/cli echo "module.exports = {extends: ['@commitlint/config-pnpm-scopes']};" > commitlint.config.js ``` -------------------------------- ### Install and Configure Commitlint Source: https://github.com/conventional-changelog/commitlint/blob/master/@commitlint/cz-commitlint/README.md Install commitlint CLI and conventional config, then create a basic commitlint.config.js file. ```bash # Install commitlint cli and conventional config npm install --save-dev @commitlint/config-conventional @commitlint/cli # or yarn yarn add @commitlint/config-conventional @commitlint/cli -D # Simple: config with conventional echo "module.exports = {extends: ['@commitlint/config-conventional']};" > commitlint.config.js ``` -------------------------------- ### Install and Configure commitlint Source: https://github.com/conventional-changelog/commitlint/blob/master/@commitlint/config-rush-scopes/readme.md Install the necessary packages and create a commitlint configuration file. ```sh npm install --save-dev @commitlint/config-rush-scopes @commitlint/cli echo "export default {extends: ['@commitlint/config-rush-scopes']};" > commitlint.config.js ``` -------------------------------- ### Install @commitlint/load Source: https://github.com/conventional-changelog/commitlint/blob/master/docs/api/load.md Install the @commitlint/load package using npm. ```sh npm install --save @commitlint/load ``` -------------------------------- ### JavaScript Configuration Object Example Source: https://github.com/conventional-changelog/commitlint/blob/master/docs/reference/configuration.md This example demonstrates a comprehensive JavaScript configuration object for Commitlint, including extends, parserPreset, formatter, rules, ignores, defaultIgnores, helpUrl, and prompt configurations. Ensure referenced packages are installed. ```javascript const Configuration = { /* * Resolve and load @commitlint/config-conventional from node_modules. * Referenced packages must be installed */ extends: ["@commitlint/config-conventional"], /* * Resolve and load conventional-changelog-atom from node_modules. * Referenced packages must be installed */ parserPreset: "conventional-changelog-atom", /* * Resolve and load @commitlint/format from node_modules. * Referenced package must be installed */ formatter: "@commitlint/format", /* * Any rules defined here will override rules from @commitlint/config-conventional */ rules: { "type-enum": [2, "always", ["foo"]], }, /* * Array of functions that return true if commitlint should ignore the given message. * Given array is merged with predefined functions, which consist of matchers like: * * - 'Merge pull request', 'Merge X into Y' or 'Merge branch X' * - 'Revert X' * - 'v1.2.3' (ie semver matcher) * - 'Automatic merge X' or 'Auto-merged X into Y' * * To see full list, check https://github.com/conventional-changelog/commitlint/blob/master/%40commitlint/is-ignored/src/defaults.ts. * To disable those ignores and run rules always, set `defaultIgnores: false` as shown below. */ ignores: [(commit) => commit === ""], /* * Whether commitlint uses the default ignore rules, see the description above. */ defaultIgnores: true, /* * Custom URL to show upon failure */ helpUrl: "https://github.com/conventional-changelog/commitlint/#what-is-commitlint", /* * Custom prompt configs */ prompt: { messages: {}, questions: { type: { description: "please input type:", }, }, }, }; export default Configuration; ``` ```javascript module.exports = Configuration; ``` -------------------------------- ### Install and Configure Commitlint with Patternplate Source: https://github.com/conventional-changelog/commitlint/blob/master/@commitlint/config-patternplate/README.md Install the necessary packages and create a commitlint configuration file. ```sh npm install --save-dev @commitlint/config-patternplate @commitlint/cli echo "module.exports = {extends: ['@commitlint/config-patternplate']};" > commitlint.config.js ``` -------------------------------- ### Install @commitlint/read Source: https://github.com/conventional-changelog/commitlint/blob/master/@commitlint/read/README.md Install the @commitlint/read package using npm. ```shell npm install --save @commitlint/read ``` -------------------------------- ### Commitlint Configuration Example Source: https://github.com/conventional-changelog/commitlint/blob/master/@commitlint/config-pnpm-scopes/readme.md Example of a commitlint configuration file extending the pnpm scopes config. ```javascript { extends: ['@commitlint/config-pnpm-scopes'] } ``` -------------------------------- ### Install @commitlint/format Source: https://github.com/conventional-changelog/commitlint/blob/master/@commitlint/format/README.md Install the @commitlint/format package using npm. ```shell npm install --save @commitlint/format ``` -------------------------------- ### Install Husky and Setup Commit Message Linting (bun on Linux/macOS) Source: https://github.com/conventional-changelog/commitlint/blob/master/docs/guides/local-setup.md Installs Husky and configures the 'commit-msg' hook to lint commit messages using bun. This is for husky@v9 or lower. ```sh bun add --dev husky # husky@v9 bunx husky init # husky@v8 or lower bunx husky install # Add commit message linting to commit-msg hook echo "bunx commitlint --edit $1" > .husky/commit-msg ``` -------------------------------- ### Install and Configure @commitlint/config-nx-scopes Source: https://github.com/conventional-changelog/commitlint/blob/master/@commitlint/config-nx-scopes/readme.md Install the necessary packages and create a commitlint.config.js file to extend the nx-scopes configuration. ```bash npm install --save-dev @commitlint/config-nx-scopes @commitlint/cli echo "module.exports = {extends: ['@commitlint/config-nx-scopes']};" > commitlint.config.js ``` -------------------------------- ### Install @commitlint/parse Source: https://github.com/conventional-changelog/commitlint/blob/master/@commitlint/parse/README.md Install the @commitlint/parse package using npm. ```bash npm install --save @commitlint/parse ``` -------------------------------- ### Install Commitlint CLI, Conventional Config, and Prompt CLI Source: https://github.com/conventional-changelog/commitlint/blob/master/docs/guides/use-prompt.md Install the necessary @commitlint packages for your project using npm, yarn, pnpm, bun, or deno. This also includes creating a basic commitlint configuration file. ```sh npm install --save-dev @commitlint/cli @commitlint/config-conventional @commitlint/prompt-cli echo "export default { extends: ['@commitlint/config-conventional'] };" > commitlint.config.js ``` ```sh yarn add --dev @commitlint/cli @commitlint/config-conventional @commitlint/prompt-cli echo "export default { extends: ['@commitlint/config-conventional'] };" > commitlint.config.js ``` ```sh pnpm add --save-dev @commitlint/cli @commitlint/config-conventional @commitlint/prompt-cli echo "export default { extends: ['@commitlint/config-conventional'] };" > commitlint.config.js ``` ```sh bun add --dev @commitlint/cli @commitlint/config-conventional @commitlint/prompt-cli echo "export default { extends: ['@commitlint/config-conventional'] };" > commitlint.config.js ``` ```sh deno add --dev npm:@commitlint/cli npm:@commitlint/config-conventional npm:@commitlint/prompt-cli echo "export default { extends: ['@commitlint/config-conventional'] };" > commitlint.config.js ``` -------------------------------- ### Install and Configure @commitlint/config-angular Source: https://github.com/conventional-changelog/commitlint/blob/master/@commitlint/config-angular/README.md Install the necessary packages and create a commitlint configuration file. ```sh npm install --save-dev @commitlint/config-angular @commitlint/cli echo "export default {extends: ['@commitlint/config-angular']};" > commitlint.config.js ``` -------------------------------- ### Install Husky and Setup Commit Message Linting (bun on Windows) Source: https://github.com/conventional-changelog/commitlint/blob/master/docs/guides/local-setup.md Installs Husky and configures the 'commit-msg' hook to lint commit messages using bun on Windows. This is for husky@v9 or lower. ```sh bun add --dev husky # husky@v9 bunx husky init # husky@v8 or lower bunx husky install # Add commit message linting to commit-msg hook node -e "fs.writeFileSync('.husky/commit-msg', 'bunx commitlint --edit $'+'1\n')" ``` -------------------------------- ### Reference a File Example Source: https://github.com/conventional-changelog/commitlint/blob/master/docs/api/load.md Shows how to load a configuration by referencing an extended configuration file. ```javascript import load from "@commitlint/load"; const config = await load({ extends: ["./package"] }); console.log(config); // => { extends: ['./package', './package-b'], rules: {} } ``` -------------------------------- ### Install Husky and Setup Commit Message Linting (deno on Linux/macOS) Source: https://github.com/conventional-changelog/commitlint/blob/master/docs/guides/local-setup.md Installs Husky and configures the 'commit-msg' hook to lint commit messages using deno. This is for husky@v9 or lower. ```sh deno add --dev husky # husky@v9 deno task --eval husky init # husky@v8 or lower deno task --eval husky install # Add commit message linting to commit-msg hook echo "deno task --eval commitlint --edit $1" > .husky/commit-msg ``` -------------------------------- ### Example Project Structure Source: https://github.com/conventional-changelog/commitlint/blob/master/@commitlint/config-nx-scopes/readme.md Demonstrates a typical Nx project structure with 'api', 'app', and 'web' packages. ```bash ❯ cat commitlint.config.js { extends: ['@commitlint/config-nx-scopes'] } ❯ tree packages packages ├── api ├── app └── web ``` -------------------------------- ### Install Husky and Setup Commit Message Linting (deno on Windows) Source: https://github.com/conventional-changelog/commitlint/blob/master/docs/guides/local-setup.md Installs Husky and configures the 'commit-msg' hook to lint commit messages using deno on Windows. This is for husky@v9 or lower. ```sh deno add --dev husky # husky@v9 deno task --eval husky init # husky@v8 or lower deno task --eval husky install # Add commit message linting to commit-msg hook node -e "fs.writeFileSync('.husky/commit-msg', 'deno task --eval commitlint --edit $'+'1\n')" ``` -------------------------------- ### Example Tree Structure Source: https://github.com/conventional-changelog/commitlint/blob/master/@commitlint/config-workspace-scopes/readme.md Illustrates the directory structure of a project with workspaces. ```text packages ├── api ├── app └── web ``` -------------------------------- ### Install Husky and Setup Commit Message Linting (pnpm on Linux/macOS) Source: https://github.com/conventional-changelog/commitlint/blob/master/docs/guides/local-setup.md Installs Husky and configures the 'commit-msg' hook to lint commit messages using pnpm. This is for husky@v9 or lower. ```sh pnpm add --save-dev husky # husky@v9 pnpm husky init # husky@v8 or lower pnpm husky install # Add commit message linting to commit-msg hook echo "pnpm dlx commitlint --edit $1" > .husky/commit-msg ``` -------------------------------- ### Install @commitlint/travis-cli Source: https://github.com/conventional-changelog/commitlint/blob/master/@commitlint/travis-cli/README.md Install the package as a development dependency. ```bash npm install --save-dev @commitlint/travis-cli ``` -------------------------------- ### Install @commitlint/lint Source: https://github.com/conventional-changelog/commitlint/blob/master/@commitlint/lint/README.md Install the @commitlint/lint package using npm. ```shell npm install --save @commitlint/lint ``` -------------------------------- ### Install @commitlint/load Source: https://github.com/conventional-changelog/commitlint/blob/master/@commitlint/load/README.md Install the @commitlint/load package as a development dependency using npm. ```shell npm install --save-dev @commitlint/load ``` -------------------------------- ### Example commitlint.config.js Source: https://github.com/conventional-changelog/commitlint/blob/master/@commitlint/config-nx-scopes/readme.md A basic commitlint configuration file extending @commitlint/config-nx-scopes. ```javascript { extends: ['@commitlint/config-nx-scopes'] } ``` -------------------------------- ### Install Husky and Setup Commit Message Linting (yarn on Linux/macOS) Source: https://github.com/conventional-changelog/commitlint/blob/master/docs/guides/local-setup.md Installs Husky and configures the 'commit-msg' hook to lint commit messages using yarn. This is for husky@v9 or lower. ```sh yarn add --dev husky # husky@v9 yarn husky init # husky@v8 or lower yarn husky install # Add commit message linting to commit-msg hook echo "yarn commitlint --edit $1" > .husky/commit-msg ``` -------------------------------- ### Install Husky and Setup Commit Message Linting (npm on Linux/macOS) Source: https://github.com/conventional-changelog/commitlint/blob/master/docs/guides/local-setup.md Installs Husky and configures the 'commit-msg' hook to lint commit messages using npm. This is for husky@v9 or lower. ```sh npm install --save-dev husky # husky@v9 npx husky init # husky@v8 or lower npx husky install # Add commit message linting to commit-msg hook echo "npx --no -- commitlint --edit $1" > .husky/commit-msg ``` -------------------------------- ### Install Husky and Setup Commit Message Linting (npm on Windows) Source: https://github.com/conventional-changelog/commitlint/blob/master/docs/guides/local-setup.md Installs Husky and configures the 'commit-msg' hook to lint commit messages using npm on Windows. This is for husky@v9 or lower. ```sh npm install --save-dev husky # husky@v9 npx husky init # husky@v8 or lower npx husky install # Add commit message linting to commit-msg hook node -e "fs.writeFileSync('.husky/commit-msg', 'npx --no -- commitlint --edit $'+'1\n')" ``` -------------------------------- ### Install Husky and Setup Commit Message Linting (pnpm on Windows) Source: https://github.com/conventional-changelog/commitlint/blob/master/docs/guides/local-setup.md Installs Husky and configures the 'commit-msg' hook to lint commit messages using pnpm on Windows. This is for husky@v9 or lower. ```sh pnpm add --save-dev husky # husky@v9 pnpm husky init # husky@v8 or lower pnpm husky install # Add commit message linting to commit-msg hook node -e "fs.writeFileSync('.husky/commit-msg', 'pnpm dlx commitlint --edit $'+'1\n')" ``` -------------------------------- ### Install Husky and Setup Commit Message Linting (yarn on Windows) Source: https://github.com/conventional-changelog/commitlint/blob/master/docs/guides/local-setup.md Installs Husky and configures the 'commit-msg' hook to lint commit messages using yarn on Windows. This is for husky@v9 or lower. ```sh yarn add --dev husky # husky@v9 yarn husky init # husky@v8 or lower yarn husky install # Add commit message linting to commit-msg hook node -e "fs.writeFileSync('.husky/commit-msg', 'yarn commitlint --edit $'+'1\n')" ``` -------------------------------- ### Install Commitlint CLI and Conventional Config with bun Source: https://github.com/conventional-changelog/commitlint/blob/master/docs/guides/getting-started.md Install the Commitlint CLI and the conventional configuration package as a dev dependency using bun. ```sh bun add -d @commitlint/cli @commitlint/config-conventional ``` -------------------------------- ### Install Commitlint CLI Source: https://github.com/conventional-changelog/commitlint/blob/master/README.md Install the commitlint CLI as a development dependency in your project. ```sh npm install --save-dev @commitlint/cli ``` -------------------------------- ### Install Commitlint CLI and Conventional Config with deno Source: https://github.com/conventional-changelog/commitlint/blob/master/docs/guides/getting-started.md Install the Commitlint CLI and the conventional configuration package as a dev dependency using deno. ```sh deno add -D npm:@commitlint/cli npm:@commitlint/config-conventional ``` -------------------------------- ### Example commitlint.config.js Source: https://github.com/conventional-changelog/commitlint/blob/master/@commitlint/config-rush-scopes/readme.md Shows the content of a typical commitlint.config.js file using the rush-scopes config. ```js { extends: ['@commitlint/config-rush-scopes'] } ``` -------------------------------- ### Install Dependencies for Shareable Configuration (npm) Source: https://github.com/conventional-changelog/commitlint/blob/master/docs/reference/configuration.md Install the necessary packages for using shareable configurations with npm. This includes `commitlint-config-lerna` and `@commitlint/config-conventional`. ```sh npm install --save-dev commitlint-config-lerna @commitlint/config-conventional ``` -------------------------------- ### Install shareable configuration package Source: https://github.com/conventional-changelog/commitlint/blob/master/docs/concepts/shareable-config.md Install the desired commitlint configuration package as a dev dependency using npm. ```bash npm install --save-dev commitlint-config-example ``` -------------------------------- ### Azure Pipelines Setup for Commitlint Source: https://github.com/conventional-changelog/commitlint/blob/master/docs/guides/ci-setup.md Set up an Azure Pipelines job to validate commit messages. This includes checking out code, installing Node.js, printing versions, installing commitlint, and validating commits based on the build reason. ```yml steps: - checkout: self fetchDepth: 0 - task: NodeTool@0 inputs: versionSpec: "20.x" checkLatest: true - script: | git --version node --version npm --version npx commitlint --version displayName: Print versions - script: | npm install conventional-changelog-conventionalcommits npm install commitlint@latest displayName: Install commitlint - script: npx commitlint --last --verbose condition: ne(variables['Build.Reason'], 'PullRequest') displayName: Validate current commit (last commit) with commitlint - script: | echo "Accessing Azure DevOps API..." response=$(curl -s -X GET -H "Cache-Control: no-cache" -H "Authorization: Bearer $(System.AccessToken)" $(System.TeamFoundationCollectionUri)$(System.TeamProject)/_apis/git/repositories/$(Build.Repository.Name)/pullRequests/$(System.PullRequest.PullRequestId)/commits?api-version=6.0) numberOfCommits=$(echo "$response" | jq -r '.count') echo "$numberOfCommits commits to check" npx commitlint --from $(System.PullRequest.SourceCommitId)~${numberOfCommits} --to $(System.PullRequest.SourceCommitId) --verbose condition: eq(variables['Build.Reason'], 'PullRequest') displayName: Validate PR commits with commitlint ``` -------------------------------- ### Config File with Current Working Directory Example Source: https://github.com/conventional-changelog/commitlint/blob/master/docs/api/load.md Demonstrates loading a configuration file from a specific current working directory. ```javascript import load from "@commitlint/load"; const config = await load({}, { file: ".commitlintrc.yml", cwd: process.cwd() }); console.log(config); /* => { extends: [], rules: { 'body-leading-blank': [ 1, 'always' ] }, formatter: '@commitlint/format', plugins: {} } */ ``` -------------------------------- ### Install Commitlint CLI and Conventional Config with npm Source: https://github.com/conventional-changelog/commitlint/blob/master/docs/guides/getting-started.md Install the Commitlint CLI and the conventional configuration package as a dev dependency using npm. ```sh npm install -D @commitlint/cli @commitlint/config-conventional ``` -------------------------------- ### Install conventional-changelog-atom Source: https://github.com/conventional-changelog/commitlint/blob/master/docs/reference/configuration.md Install the `conventional-changelog-atom` npm package as a development dependency. ```sh npm install --save-dev conventional-changelog-atom ``` -------------------------------- ### Install Commitizen Adapter Source: https://github.com/conventional-changelog/commitlint/blob/master/@commitlint/cz-commitlint/README.md Install the commitlint cz-commitlint adapter and commitizen. Inquirer is a required peer dependency. ```bash npm install --save-dev @commitlint/cz-commitlint commitizen inquirer@9 # inquirer is required as peer dependency # or yarn yarn add -D @commitlint/cz-commitlint commitizen inquirer@9 # inquirer is required as peer dependency ``` -------------------------------- ### Install Commitlint CLI and Conventional Config with pnpm Source: https://github.com/conventional-changelog/commitlint/blob/master/docs/guides/getting-started.md Install the Commitlint CLI and the conventional configuration package as a dev dependency using pnpm. ```sh pnpm add -D @commitlint/cli @commitlint/config-conventional ``` -------------------------------- ### Install and Configure Commitlint with Lerna Scopes Source: https://github.com/conventional-changelog/commitlint/blob/master/@commitlint/config-lerna-scopes/readme.md Install the necessary packages and create a commitlint configuration file extending the lerna scopes config. ```sh npm install --save-dev @commitlint/config-lerna-scopes @commitlint/cli echo "export default {extends: ['@commitlint/config-lerna-scopes']};" > commitlint.config.js ``` -------------------------------- ### Commitlint Configuration Example Source: https://github.com/conventional-changelog/commitlint/blob/master/@commitlint/config-lerna-scopes/readme.md A basic commitlint configuration file extending the lerna scopes config. ```javascript { extends: ['@commitlint/config-lerna-scopes'] } ``` -------------------------------- ### Install and Configure @commitlint/config-angular-type-enum Source: https://github.com/conventional-changelog/commitlint/blob/master/@commitlint/config-angular-type-enum/README.md Install the necessary packages and create a commitlint configuration file extending this config. ```sh npm install --save-dev @commitlint/config-angular-type-enum @commitlint/cli echo "module.exports = {extends: ['@commitlint/config-angular-type-enum']};" > commitlint.config.js ``` -------------------------------- ### TypeScript Configuration Example Source: https://github.com/conventional-changelog/commitlint/blob/master/docs/reference/configuration.md This TypeScript configuration example shows how to import types from '@commitlint/types' and use them for defining the configuration object. It highlights the use of `RuleConfigSeverity` for rule severities. ```typescript import type { UserConfig } from "@commitlint/types"; // [!code focus] import { RuleConfigSeverity } from "@commitlint/types"; // [!code focus] const Configuration: UserConfig = { // [!code focus] extends: ["@commitlint/config-conventional"], parserPreset: "conventional-changelog-atom", formatter: "@commitlint/format", rules: { "type-enum": [RuleConfigSeverity.Error, "always", ["foo"]], // [!code focus] }, // ... }; export default Configuration; ``` -------------------------------- ### Install Travis CLI for Commitlint Source: https://github.com/conventional-changelog/commitlint/blob/master/docs/guides/ci-setup.md Install the commitlint Travis CLI package as a dev dependency for use in Travis CI. ```bash # Install and configure if needed npm install --save-dev @commitlint/travis-cli ``` -------------------------------- ### Install Commitlint CLI and Conventional Config with yarn Source: https://github.com/conventional-changelog/commitlint/blob/master/docs/guides/getting-started.md Install the Commitlint CLI and the conventional configuration package as a dev dependency using yarn. ```sh yarn add -D @commitlint/cli @commitlint/config-conventional ``` -------------------------------- ### Local Plugin Usage Example Source: https://github.com/conventional-changelog/commitlint/blob/master/docs/reference/plugins.md Configure commitlint to use a local plugin by including its rules directly in the plugins array of your commitlint.config.js. This example shows a 'hello-world-rule'. ```javascript export default { rules: { "hello-world-rule": [2, "always"], }, plugins: [ { rules: { "hello-world-rule": ({ subject }) => { const HELLO_WORLD = "Hello World"; return [ subject.includes(HELLO_WORLD), `Your subject should contain ${HELLO_WORLD} message`, ]; }, }, }, ], }; ``` -------------------------------- ### Alternative Commitlint Script Setup (npm on Windows) Source: https://github.com/conventional-changelog/commitlint/blob/master/docs/guides/local-setup.md Sets up a 'commitlint' script in package.json and configures the 'commit-msg' hook to use it via npm on Windows. ```sh npm pkg set scripts.commitlint="commitlint --edit" node -e "fs.writeFileSync('.husky/commit-msg', 'npm run commitlint $'+'{1}\n')" ``` -------------------------------- ### Alternative Commitlint Script Setup (npm on Linux/macOS) Source: https://github.com/conventional-changelog/commitlint/blob/master/docs/guides/local-setup.md Sets up a 'commitlint' script in package.json and configures the 'commit-msg' hook to use it via npm. ```sh npm pkg set scripts.commitlint="commitlint --edit" echo "npm run commitlint ${1}" > .husky/commit-msg ``` -------------------------------- ### Inline Rules Example Source: https://github.com/conventional-changelog/commitlint/blob/master/docs/api/load.md Demonstrates how to load a configuration with inline rules defined directly within the `seed` object. ```javascript import load from "@commitlint/load"; const config = await load({ rules: { "body-leading-blank": [2, "always"], }, }); console.log(config); // => { extends: [], rules: { 'body-leading-blank': [ 2, 'always' ] } } ``` -------------------------------- ### Example Conventional Commit Messages Source: https://github.com/conventional-changelog/commitlint/blob/master/README.md Real-world examples of commit messages adhering to the conventional commit format. ```text chore: run tests on travis ci ``` ```text fix(server): send cors headers ``` ```text feat(blog): add comment section ``` -------------------------------- ### Alternative Commitlint Script Setup (pnpm on Linux/macOS) Source: https://github.com/conventional-changelog/commitlint/blob/master/docs/guides/local-setup.md Sets up a 'commitlint' script in package.json and configures the 'commit-msg' hook to use it via pnpm. ```sh npm pkg set scripts.commitlint="commitlint --edit" echo "pnpm commitlint ${1}" > .husky/commit-msg ``` -------------------------------- ### Add files and start commit prompt Source: https://github.com/conventional-changelog/commitlint/blob/master/@commitlint/prompt-cli/README.md Stages changes in Git and then initiates the commit message prompt. ```sh git add . commit ``` -------------------------------- ### Alternative Commitlint Script Setup (yarn on Windows) Source: https://github.com/conventional-changelog/commitlint/blob/master/docs/guides/local-setup.md Sets up a 'commitlint' script in package.json and configures the 'commit-msg' hook to use it via yarn on Windows. ```sh npm pkg set scripts.commitlint="commitlint --edit" node -e "fs.writeFileSync('.husky/commit-msg', 'yarn commitlint $'+'{1}\n')" ``` -------------------------------- ### Alternative Commitlint Script Setup (pnpm on Windows) Source: https://github.com/conventional-changelog/commitlint/blob/master/docs/guides/local-setup.md Sets up a 'commitlint' script in package.json and configures the 'commit-msg' hook to use it via pnpm on Windows. ```sh npm pkg set scripts.commitlint="commitlint --edit" node -e "fs.writeFileSync('.husky/commit-msg', 'pnpm commitlint $'+'{1}\n')" ``` -------------------------------- ### Alternative Commitlint Script Setup (yarn on Linux/macOS) Source: https://github.com/conventional-changelog/commitlint/blob/master/docs/guides/local-setup.md Sets up a 'commitlint' script in package.json and configures the 'commit-msg' hook to use it via yarn. ```sh npm pkg set scripts.commitlint="commitlint --edit" echo "yarn commitlint ${1}" > .husky/commit-msg ``` -------------------------------- ### Install latest conventional-changelog-lint Source: https://github.com/conventional-changelog/commitlint/blob/master/docs/support/upgrade.md Update conventional-changelog-lint to the latest version as a development dependency. ```sh npm install --save-dev conventional-changelog-lint@latest ``` -------------------------------- ### type-case Rule Examples Source: https://github.com/conventional-changelog/commitlint/blob/master/@commitlint/config-conventional/README.md Demonstrates commit messages that pass and fail the type-case rule. ```sh echo "FIX: some message" # fails ``` ```sh echo "fix: some message" # passes ``` -------------------------------- ### header-max-length Rule Examples Source: https://github.com/conventional-changelog/commitlint/blob/master/@commitlint/config-conventional/README.md Demonstrates commit messages that pass and fail the header-max-length rule. ```sh echo "fix: some message that is way too long and breaks the line max-length by several characters" # fails ``` ```sh echo "fix: some message" # passes ``` -------------------------------- ### Inline Parser Preset Example Source: https://github.com/conventional-changelog/commitlint/blob/master/docs/api/load.md Illustrates how to specify an inline `parserPreset` for custom parsing logic. ```javascript import load from "@commitlint/load"; const config = await load({ parserPreset: "./parser-preset.js" }); console.log(config); /* => { extends: [], rules: {}, parserPreset: { name: './parser-preset.js', path: './parser-preset.js', opts: {} } } */ ``` -------------------------------- ### footer-max-line-length Rule Examples Source: https://github.com/conventional-changelog/commitlint/blob/master/@commitlint/config-conventional/README.md Demonstrates commit messages that pass and fail the footer-max-line-length rule. ```sh echo "fix: some message BREAKING CHANGE: footer with multiple lines has a message that is way too long and will break the line rule 'line-max-length' by several characters" # fails ``` ```sh echo "fix: some message BREAKING CHANGE: footer with multiple lines but still no line is too long" # passes ``` -------------------------------- ### footer-leading-blank Rule Examples Source: https://github.com/conventional-changelog/commitlint/blob/master/@commitlint/config-conventional/README.md Demonstrates commit messages that pass and fail the footer-leading-blank rule. ```sh echo "fix: some message BREAKING CHANGE: It will be significant" # warning ``` ```sh echo "fix: some message BREAKING CHANGE: It will be significant" # passes ``` -------------------------------- ### type-empty Rule Examples Source: https://github.com/conventional-changelog/commitlint/blob/master/@commitlint/config-conventional/README.md Demonstrates commit messages that pass and fail the type-empty rule. ```sh echo ": some message" # fails ``` ```sh echo "fix: some message" # passes ``` -------------------------------- ### body-leading-blank Rule Examples Source: https://github.com/conventional-changelog/commitlint/blob/master/@commitlint/config-conventional/README.md Demonstrates commit messages that pass and fail the body-leading-blank rule. ```sh echo "fix: some message body" # warning ``` ```sh echo "fix: some message body" # passes ``` -------------------------------- ### body-max-line-length Rule Examples Source: https://github.com/conventional-changelog/commitlint/blob/master/@commitlint/config-conventional/README.md Demonstrates commit messages that pass and fail the body-max-line-length rule. ```sh echo "fix: some message body with multiple lines has a message that is way too long and will break the line rule 'line-max-length' by several characters" # fails ``` ```sh echo "fix: some message body with multiple lines but still no line is too long" # passes ``` -------------------------------- ### Extend local relative configuration Source: https://github.com/conventional-changelog/commitlint/blob/master/docs/concepts/shareable-config.md Load a local configuration file using a relative path. The path must start with a dot (.). ```javascript export default { extends: ["./example"], // => ./example.js }; ``` -------------------------------- ### Run Commitizen Source: https://github.com/conventional-changelog/commitlint/blob/master/@commitlint/cz-commitlint/README.md Execute the commitizen script to start the interactive commit process. ```bash git add . npm run commit # or yarn yarn commit ``` -------------------------------- ### type-enum Rule Examples Source: https://github.com/conventional-changelog/commitlint/blob/master/@commitlint/config-conventional/README.md Demonstrates commit messages that pass and fail the type-enum rule. ```sh echo "foo: some message" # fails ``` ```sh echo "fix: some message" # passes ``` -------------------------------- ### subject-case Rule Examples Source: https://github.com/conventional-changelog/commitlint/blob/master/@commitlint/config-conventional/README.md Demonstrates commit messages that pass and fail the subject-case rule. ```sh echo "fix(SCOPE): Some message" # fails ``` ```sh echo "fix(SCOPE): Some Message" # fails ``` ```sh echo "fix(SCOPE): SomeMessage" # fails ``` ```sh echo "fix(SCOPE): SOMEMESSAGE" # fails ``` ```sh echo "fix(scope): some message" # passes ``` ```sh echo "fix(scope): some Message" # passes ``` -------------------------------- ### subject-empty Rule Examples Source: https://github.com/conventional-changelog/commitlint/blob/master/@commitlint/config-conventional/README.md Demonstrates commit messages that pass and fail the subject-empty rule. ```sh echo "fix:" # fails ``` ```sh echo "fix: some message" # passes ``` -------------------------------- ### subject-full-stop Rule Examples Source: https://github.com/conventional-changelog/commitlint/blob/master/@commitlint/config-conventional/README.md Demonstrates commit messages that pass and fail the subject-full-stop rule. ```sh echo "fix: some message." # fails ``` ```sh echo "fix: some message" # passes ``` -------------------------------- ### Valid Commit Example Source: https://github.com/conventional-changelog/commitlint/blob/master/@commitlint/config-workspace-scopes/readme.md Shows a commit message that adheres to the workspace scope rules. ```sh echo "build(api): change something in api's build" | commitlint ``` -------------------------------- ### Test Commitlint with Example Messages Source: https://github.com/conventional-changelog/commitlint/blob/master/@commitlint/config-angular-type-enum/README.md Pipe commit messages through commitlint to see how it handles valid and invalid types. ```sh echo "foo: bar" | commitlint # fails echo "build: bar" | commitlint # passes ``` -------------------------------- ### Migrate from conventional-changelog-lint to commitlint Source: https://github.com/conventional-changelog/commitlint/blob/master/docs/support/upgrade.md Commands to migrate from conventional-changelog-lint to commitlint, including package removal, installation, and configuration file renaming. ```sh npm remove --save-dev conventional-changelog-lint npm install --save commitlint mv .conventional-changelog-lintrc commitlint.config.js ``` -------------------------------- ### Shareable Configuration with Local Files Source: https://github.com/conventional-changelog/commitlint/blob/master/docs/reference/configuration.md Configure Commitlint to extend local shareable configurations. This example shows extending multiple local files, `commitlint.base.js` and `commitlint.types.js`, which are then picked up by the main `commitlint.config.js`. ```js export default { extends: ["./commitlint.base.js", "./commitlint.types.js"], }; ``` ```js // will be picked up by commitlint.config.js export default { rules: { "type-enum": [2, "always", ["foo"]], }, }; ``` ```js // will be picked up by commitlint.config.js export default { extends: ["@commitlint/config-conventional"], // extends can be nested parserPreset: "conventional-changelog-atom", }; ``` -------------------------------- ### Initialize Git Repository Source: https://github.com/conventional-changelog/commitlint/blob/master/docs/guides/use-prompt.md Use this command to initialize a new Git repository if one does not already exist. ```sh git init ``` -------------------------------- ### Load configuration and lint commit message Source: https://github.com/conventional-changelog/commitlint/blob/master/docs/api/lint.md Load a conventional commit configuration and use it to lint a commit message. This example demonstrates integrating @commitlint/load with @commitlint/lint. ```js import load from "@commitlint/load"; import lint from "@commitlint/lint"; const CONFIG = { extends: ["@commitlint/config-conventional"], }; const opts = await load(CONFIG); const report = await lint( "foo: bar", opts.rules, opts.parserPreset ? { parserOpts: opts.parserPreset.parserOpts } : {}, ); console.log(report); /* => { valid: false, errors: [ { level: 2, valid: false, name: 'type-enum', message: 'type must be one of [build, chore, ci, docs, feat, fix, perf, refactor, revert, style, test]' } ], warnings: [] } */ ``` -------------------------------- ### Initialize package.json with different package managers Source: https://github.com/conventional-changelog/commitlint/blob/master/docs/guides/use-prompt.md Initialize a package.json file for your project using npm, yarn, pnpm, or bun. ```sh npm init ``` ```sh yarn init ``` ```sh pnpm init ``` ```sh bun init ``` -------------------------------- ### Invalid Commit Message Example Source: https://github.com/conventional-changelog/commitlint/blob/master/@commitlint/config-pnpm-scopes/readme.md Example of a commit message that violates the pnpm scopes configuration, showing the error output. ```bash echo "test(foo): this won't pass" | commitlint ⧗ --- input --- test(foo): this won't pass ✖ scope must be one of [api, app, web] [scope-enum] ✖ found 1 problems, 0 warnings ``` -------------------------------- ### Commitlint Prompt Configuration Example Source: https://github.com/conventional-changelog/commitlint/blob/master/docs/reference/prompt.md This JavaScript object defines the configuration for Commitlint's prompt, including parser presets, rule configurations, and detailed prompt settings for messages and interactive questions. ```javascript export default { parserPreset: 'conventional-changelog-conventionalcommits', rules: { ... }, prompt: { settings: {}, messages: { skip: ':skip', max: 'upper %d chars', min: '%d chars at least', emptyWarning: 'can not be empty', upperLimitWarning: 'over limit', lowerLimitWarning: 'below limit' }, questions: { type: { description: "Select the type of change that you're committing:", enum: { feat: { description: 'A new feature', title: 'Features', emoji: '✨', }, fix: { description: 'A bug fix', title: 'Bug Fixes', emoji: '🐛', }, docs: { description: 'Documentation only changes', title: 'Documentation', emoji: '📚', }, style: { description: 'Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)', title: 'Styles', emoji: '💎', }, refactor: { description: 'A code change that neither fixes a bug nor adds a feature', title: 'Code Refactoring', emoji: '📦', }, perf: { description: 'A code change that improves performance', title: 'Performance Improvements', emoji: '🚀', }, test: { description: 'Adding missing tests or correcting existing tests', title: 'Tests', emoji: '🚨', }, build: { description: 'Changes that affect the build system or external dependencies (example scopes: gulp, broccoli, npm)', title: 'Builds', emoji: '🛠', }, ci: { description: 'Changes to our CI configuration files and scripts (example scopes: Travis, Circle, BrowserStack, SauceLabs)', title: 'Continuous Integrations', emoji: '⚙️', }, chore: { description: "Other changes that don't modify src or test files", title: 'Chores', emoji: '♻️', }, revert: { description: 'Reverts a previous commit', title: 'Reverts', emoji: '🗑', }, }, }, scope: { description: 'What is the scope of this change (e.g. component or file name)', }, subject: { description: 'Write a short, imperative tense description of the change', }, body: { description: 'Provide a longer description of the change', }, isBreaking: { description: 'Are there any breaking changes?', }, breakingBody: { description: 'A BREAKING CHANGE commit requires a body. Please enter a longer description of the commit itself', }, breaking: { description: 'Describe the breaking changes', }, isIssueAffected: { description: 'Does this change affect any open issues?', }, issuesBody: { description: 'If issues are closed, the commit requires a body. Please enter a longer description of the commit itself', }, issues: { description: 'Add issue references (e.g. "fix #123", "re #123".)', }, }, } }; ``` -------------------------------- ### Test Commit Prompt with different package managers Source: https://github.com/conventional-changelog/commitlint/blob/master/docs/guides/use-prompt.md Stage your changes and then run the commit prompt using the appropriate command for your package manager (npm, yarn, pnpm, bun, or deno). ```sh git add . npm run commit ``` ```sh git add . yarn commit ``` ```sh git add . pnpm commit ``` ```sh git add . bun commit ``` ```sh git add . denotask commit ``` -------------------------------- ### Install husky for Git hooks Source: https://github.com/conventional-changelog/commitlint/blob/master/docs/support/upgrade.md Install husky as a dev dependency to manage Git hooks, which is often used in conjunction with commit message validation. ```sh npm install --save-dev husky ``` -------------------------------- ### Load Configuration by Referencing a File Source: https://github.com/conventional-changelog/commitlint/blob/master/docs/api/load.md Load a commitlint configuration by extending from another configuration file. This promotes reusability of configurations. ```js const config = await load({ extends: ["./package"] }); console.log(config); // => { extends: ['./package', './package-b'], rules: {} } ``` -------------------------------- ### Remove validate-commit-msg and install commitlint CLI and config Source: https://github.com/conventional-changelog/commitlint/blob/master/docs/support/upgrade.md Use this command to remove the deprecated validate-commit-msg package and install the necessary commitlint packages for migration. ```sh npm remove validate-commit-msg --save-dev npm install --save-dev @commitlint/cli @commitlint/config-conventional ``` -------------------------------- ### subject-empty Rule Examples Source: https://github.com/conventional-changelog/commitlint/blob/master/@commitlint/config-angular/README.md Ensures the commit subject is not empty. ```sh echo "fix:" # fails echo "fix: some message" # passes ``` -------------------------------- ### scope-case Rule Examples Source: https://github.com/conventional-changelog/commitlint/blob/master/@commitlint/config-angular/README.md Ensures the commit scope is in lowercase. ```sh echo "fix(SCOPE): some message" # fails echo "fix(scope): some message" # passes ``` -------------------------------- ### Configure Commitlint with Conventional Config on Windows Source: https://github.com/conventional-changelog/commitlint/blob/master/docs/guides/getting-started.md Use Node.js to create a commitlint.config.js file, avoiding potential encoding issues on Windows. ```sh node -e "fs.writeFileSync('commitlint.config.js', process.argv[1])" "export default { extends: ['@commitlint/config-conventional'] };" ``` -------------------------------- ### type-empty Rule Examples Source: https://github.com/conventional-changelog/commitlint/blob/master/@commitlint/config-angular/README.md Ensures the commit type is not empty. ```sh echo ": some message" # fails echo "fix: some message" # passes ``` -------------------------------- ### type-case Rule Examples Source: https://github.com/conventional-changelog/commitlint/blob/master/@commitlint/config-angular/README.md Ensures the commit type is in lowercase. ```sh echo "FIX: some message" # fails echo "fix: some message" # passes ``` -------------------------------- ### subject-full-stop Rule Examples Source: https://github.com/conventional-changelog/commitlint/blob/master/@commitlint/config-angular/README.md Ensures the commit subject does not end with a period. ```sh echo "fix: some message." # fails echo "fix: some message" # passes ``` -------------------------------- ### Commitlint CLI Help Source: https://github.com/conventional-changelog/commitlint/blob/master/docs/reference/cli.md Displays the help message for the commitlint CLI, outlining available commands and options. This is useful for understanding the full range of functionalities. ```sh-vue ❯ npx commitlint --help @commitlint/cli@{{ commitlintVersion }} - Lint your commit messages [input] reads from stdin if --edit, --env, --from and --to are omitted Options: -c, --color toggle colored output [boolean] [default: true] -g, --config path to the config file; result code 9 if config is missing [string] --print-config print resolved config [string] [choices: "", "text", "json"] -d, --cwd directory to execute in [string] [default: (Working Directory)] -e, --edit read last commit message from the specified file or fallbacks to ./.git/COMMIT_EDITMSG [string] -E, --env check message in the file at path given by environment variable value [string] -x, --extends array of shareable configurations to extend [array] -H, --help-url help url in error message [string] -f, --from lower end of the commit range to lint; applies if edit=false [string] --from-last-tag uses the last tag as the lower end of the commit range to lint; applies if edit=false and from is not set [boolean] --git-log-args additional git log arguments as space separated string, example '--first-parent --cherry-pick' [string] -l, --last just analyze the last commit; applies if edit=false [boolean] -o, --format output format of the results [string] -p, --parser-preset configuration preset to use for conventional-commits-parser [string] -q, --quiet toggle console output [boolean] [default: false] -t, --to upper end of the commit range to lint; applies if edit=false [string] -V, --verbose enable verbose output for reports without problems [boolean] -s, --strict enable strict mode; result code 2 for warnings, 3 for errors [boolean] --options path to a JSON file or Common.js module containing CLI options -v, --version display version information [boolean] -h, --help Show help [boolean] ``` -------------------------------- ### header-max-length Rule Examples Source: https://github.com/conventional-changelog/commitlint/blob/master/@commitlint/config-angular/README.md Ensures the commit header does not exceed 72 characters. ```sh echo "fix: some message that is way too long and breaks the line max-length by several characters" # fails echo "fix: some message" # passes ``` -------------------------------- ### Load Configuration with Inline Rules Source: https://github.com/conventional-changelog/commitlint/blob/master/docs/api/load.md Load a commitlint configuration with inline rules defined. This is useful for quick local configurations. ```js const config = await load({ rules: { "body-leading-blank": [2, "always"], }, }); console.log(config); // => { extends: [], rules: { 'body-leading-blank': [ 2, 'always' ] } } ``` -------------------------------- ### Configure Commitlint with Conventional Config on Linux/macOS Source: https://github.com/conventional-changelog/commitlint/blob/master/docs/guides/getting-started.md Create a commitlint.config.js file to extend the conventional Commitlint configuration. ```sh echo "export default { extends: ['@commitlint/config-conventional'] };" > commitlint.config.js ``` -------------------------------- ### Configure Commitizen in package.json Source: https://github.com/conventional-changelog/commitlint/blob/master/@commitlint/prompt/README.md Sets up commitizen to use the @commitlint/prompt adapter by specifying its path in the package.json configuration. Also adds a script for running the commitizen CLI. ```json { "scripts": { "commit": "git-cz" }, "config": { "commitizen": { "path": "@commitlint/prompt" } } } ``` -------------------------------- ### Load Configuration from a Specific File in Current Working Directory Source: https://github.com/conventional-changelog/commitlint/blob/master/docs/api/load.md Load a commitlint configuration from a specified file (e.g., .commitlintrc.yml) using the current working directory. This is useful for project-specific configurations. ```js const config = await load({}, { file: ".commitlintrc.yml", cwd: process.cwd() }); console.log(config); /* => { extends: [], rules: { 'body-leading-blank': [ 1, 'always' ] }, formatter: '@commitlint/format', plugins: {} } */ ``` -------------------------------- ### Invalid Commit Example Source: https://github.com/conventional-changelog/commitlint/blob/master/@commitlint/config-workspace-scopes/readme.md Demonstrates a commit message with an invalid scope that will be rejected by commitlint. ```sh echo "test(foo): this won't pass" | commitlint ``` -------------------------------- ### Local Plugin CLI Test Source: https://github.com/conventional-changelog/commitlint/blob/master/docs/reference/plugins.md Test the local plugin's functionality using the commitlint CLI with different subjects. One subject fails the 'hello-world-rule', while another passes. ```bash > echo "feat: random subject" | commitlint # fails > echo "feat: Hello World" | commitlint # passes ```