Skip to content

commitlint-config 3.0.0

Install from the command line:
Learn more about npm packages
$ npm install @LottieFiles/commitlint-config@3.0.0
Install via package.json:
"@LottieFiles/commitlint-config": "3.0.0"

About this version

@lottiefiles/commitlint-config

Shared commitlint configuration with Linear integration and enhanced conventional commits support.

Overview

This package provides a comprehensive commitlint configuration that enforces commit message standards with enhanced features including Linear issue validation, automatic scope detection from pnpm workspaces, and interactive commit prompts.

Key Features

  • Linear Integration: Validates issue states and references through Linear API
  • Smart Issue References: Supports Linear's magic keywords for automatic issue linking
  • Extended Commit Types: Comprehensive set of commit types beyond conventional commits
  • Interactive Prompts: Rich guided commit message creation
  • Multiple Scopes: Support for comma-separated scopes
  • Workspace Integration: Automatic scope detection from pnpm workspaces
  • Strict Validation: Comprehensive rules for consistent formatting

See GUIDE.md documentation for details and examples on writing great commit messages with this config.


Table of Contents

Installation

Prerequisites

  • Node.js ≥ 20.0.0
  • pnpm package manager
  • Git repository

1. Install Dependencies

# Install the configuration package
pnpm add -D @lottiefiles/commitlint-config

# Install commitlint CLI (if not already installed)
pnpm add -D @commitlint/cli

2. Create Configuration File

Create commitlint.config.mjs in your project root:

import { createConfig } from '@lottiefiles/commitlint-config';

export default createConfig({
  // Required: Linear team/project prefixes
  issuePrefixes: ['WEB', 'CRE'],
  
  // Optional: Enable Linear validation (defaults to 'auto')
  linearEnabled: true,
  
  // Optional: Allowed Linear issue states (defaults to ['started'])
  linearIssueStates: ['started', 'completed'],
});

3. Set Up Git Hooks

Using Husky (Recommended)

# Install husky
pnpm add -D husky

# Initialize husky
pnpm exec husky install

# Add commit-msg hook
pnpm exec husky add .husky/commit-msg 'pnpm commitlint --edit $1'

Using lint-staged

Add to your package.json:

{
  "lint-staged": {
    "*": "pnpm commitlint --edit"
  }
}

Quick Start

Basic Usage

Once configured, commitlint will automatically validate your commit messages:

# Valid commit
git commit -m "feat(auth): add OAuth2 authentication"

# Invalid commit (will be rejected)
git commit -m "Add new feature"  # Missing type format

With Linear Integration

# Set your Linear API key
export LINEAR_API_KEY="lin_api_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"

# Commit with Linear issue reference
git commit -m "feat(auth): implement SSO login

Add single sign-on authentication with SAML support.
Includes proper error handling and user feedback.

Closes WEB-123"

Interactive Commits

For guided commit creation, use with commitizen:

# Install commitizen globally
npm install -g commitizen

# Use interactive prompts
git cz

Configuration

Basic Configuration

import { createConfig } from '@lottiefiles/commitlint-config';

export default createConfig();

Advanced Configuration

import { createConfig } from '@lottiefiles/commitlint-config';

export default createConfig({
  // Linear team prefixes (required for Linear integration)
  issuePrefixes: ['WEB', 'CRE', 'DEVOP'],
  
  // Linear API configuration
  linearEnabled: true,  // or 'auto' or false
  linearApiKey: process.env.LINEAR_API_KEY,
  linearIssueStates: ['started', 'completed'],
  
  // Custom scopes (overrides pnpm workspace detection)
  scopes: ['api', 'web', 'mobile', 'docs'],
});

Linear Integration

Setup

  1. Get Linear API Key:

    • Go to Linear Settings → API
    • Create a new API key
    • Set as environment variable: LINEAR_API_KEY=lin_api_xxx...
  2. Configure Issue Prefixes:

    export default createConfig({
      issuePrefixes: ['WEB', 'CRE'], // Your Linear team keys
    });

Issue Validation

The configuration validates:

  • Issue exists in Linear
  • Issue is in allowed states (default: ['started'])
  • Reference uses valid action keywords

Supported Reference Actions

Linear magic keywords for automatic issue linking:

Action Description
closes, close, closed, closing Marks issue as completed
fixes, fix, fixed, fixing Marks issue as completed
resolves, resolve, resolved, resolving Marks issue as completed
completes, complete, completed, completing Marks issue as completed
refs, ref, references Links without state change
part of, related to, contributes to Links without state change
toward, towards Links without state change

Example with Linear References

git commit -m "feat(auth): implement OAuth2 login

Add OAuth2 authentication with Google and GitHub providers.
Includes token refresh and proper error handling.

Closes WEB-123
Refs WEB-124"

Commit Types

Supported Types

Type Description Use Case
feat New features Adding new functionality
fix Bug fixes Fixing existing issues
docs Documentation README, API docs, comments
style Code style Formatting, whitespace, semicolons
refactor Code refactoring Restructuring without functional changes
perf Performance Performance improvements
test Testing Adding or modifying tests
build Build system Webpack, npm scripts, dependencies
ci CI/CD GitHub Actions, deployment scripts
ops Operations Infrastructure, monitoring, deployment
chore Maintenance Routine tasks, dependency updates
revert Reverts Reverting previous commits
release Releases Version bumps, changelogs
merge Merges Merge conflict resolutions
wip Work in progress Incomplete features (use sparingly)

Scopes

Automatic Detection

By default, scopes are automatically detected from your pnpm-workspace.yaml:

packages:
  - 'packages/auth'
  - 'packages/api'
  - 'packages/web'

Valid scopes: auth, api, web

Custom Scopes

Override automatic detection:

export default createConfig({
  scopes: ['frontend', 'backend', 'mobile', 'docs'],
});

Multiple Scopes

Use comma-separated scopes for cross-cutting changes:

git commit -m "feat(auth, api): implement user session management"

Development

Building the Package

# Install dependencies
pnpm install

# Build TypeScript to JavaScript
pnpm build

# Build in watch mode
pnpm dev

Testing

# Run all tests
pnpm test

# Run tests in watch mode
pnpm test --watch

# Run specific test file
pnpm test examples.test.ts

Testing Configuration

# Print resolved configuration
pnpm print-config

# Test commit message
echo "feat: add new feature" | pnpm commitlint

# Test with specific config
echo "feat(scope): message" | pnpm commitlint --config ./commitlint.config.mjs

Local Development

  1. Link Package Locally:

    # In this package directory
    pnpm link --global
    
    # In your test project
    pnpm link --global @lottiefiles/commitlint-config
  2. Test Changes:

    # Make changes to src/
    pnpm build
    
    # Test in your project
    echo "feat: test message" | pnpm commitlint

Adding Custom Rules

  1. Edit Local Plugin (src/local-plugin.ts):

    const myCustomRule: SyncRule = (parsed, when = 'always') => {
      // Your validation logic
      return [isValid, errorMessage];
    };
    
    export default {
      rules: {
        'my-custom-rule': myCustomRule,
        // ... existing rules
      },
    } satisfies Plugin;
  2. Add to Configuration (src/define-config.ts):

    rules: {
      'my-custom-rule': [RuleConfigSeverity.Error, 'always'],
      // ... existing rules
    }

Troubleshooting

Common Issues

Linear API Key Issues

Problem: Linear API key must be available when linearEnabled is true

Solutions:

  1. Set environment variable: export LINEAR_API_KEY="lin_api_xxx..."
  2. Pass directly in config: linearApiKey: "lin_api_xxx..."
  3. Disable Linear: linearEnabled: false

Invalid Commit Messages

Problem: Valid-looking commits are rejected

Debug Steps:

  1. Check exact error message: pnpm commitlint --verbose
  2. Verify commit type is in allowed list
  3. Ensure scope is kebab-case: feat(user-auth): ...
  4. Check Linear issue exists and is in correct state

Scope Validation Failures

Problem: Scope not recognized in monorepo

Solutions:

  1. Verify pnpm-workspace.yaml is properly configured
  2. Use custom scopes: scopes: ['your', 'custom', 'scopes']
  3. Check scope format is kebab-case

Debug Commands

# Print full configuration
pnpm commitlint --print-config

# Verbose error output
echo "invalid message" | pnpm commitlint --verbose

# Test Linear API connection
curl -H "Authorization: Bearer $LINEAR_API_KEY" \
     -H "Content-Type: application/json" \
     https://api.linear.app/graphql \
     -d '{"query":"{ viewer { id name } }"}'

Getting Help

  1. Check Configuration: Ensure all required options are set
  2. Verify Environment: Check Node.js version and dependencies
  3. Test Incrementally: Start with basic config, add features gradually
  4. Review Examples: See GUIDE.md for comprehensive examples

API Reference

createConfig(options?: Options): UserConfig

Creates a commitlint configuration with the specified options.

Parameters

  • options (optional): Configuration options object

Returns

  • UserConfig: Complete commitlint configuration object

Options Interface

interface Options {
  issuePrefixes?: string[];
  linearApiKey?: string;
  linearEnabled?: 'auto' | boolean;
  linearIssueStates?: string[];
  scopes?: string[];
}
Option Type Default Description
issuePrefixes string[] [] Linear team/project prefixes (e.g., ['WEB', 'CRE'])
linearApiKey string process.env.LINEAR_API_KEY Linear API key for issue validation
linearEnabled 'auto' | boolean 'auto' Enable Linear validation. 'auto' enables if API key is available
linearIssueStates string[] ['started'] Allowed Linear issue states ('unstarted', 'started', 'completed', 'canceled')
scopes string[] undefined Custom scopes (overrides pnpm workspace detection)

Constants

COMMIT_TYPES

Array of all supported commit types.

REFERENCE_ACTIONS

Array of all supported Linear reference action keywords.

Details


Assets

  • commitlint-config-3.0.0.tgz

Download activity

  • Total downloads 19
  • Last 30 days 14
  • Last week 6
  • Today 0

Recent versions

View all