Skip to content

fix: Commitlint ignoring config file #3599

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
2 of 4 tasks
enrique-ramirez opened this issue Apr 27, 2023 · 1 comment
Closed
2 of 4 tasks

fix: Commitlint ignoring config file #3599

enrique-ramirez opened this issue Apr 27, 2023 · 1 comment
Labels

Comments

@enrique-ramirez
Copy link

enrique-ramirez commented Apr 27, 2023

Expected Behavior

I want to change the questions text (mostly for translation purposes) as well as other settings.

Current Behavior

Commitlint seems to be ignoring my commitlint.config.js file completely.

Affected packages

  • cli
  • core
  • prompt
  • config-angular

Possible Solution

I'm sure I'm doing something wrong, but I can't figure out what exactly it is. I've delved through the documentation but couldn't find anything. It seems commitlint should be reading the config.js file automagically. What I do believe is I'm either very dumb or we need better documentation regarding this file?

Steps to Reproduce

My repo is private, but here's what I have right now:

// package.json
{
  "devDependencies": {
    "@commitlint/cli": "17.6.1",
    "@commitlint/config-conventional": "17.6.1",
    "@commitlint/cz-commitlint": "17.5.0",
    "@mento/eslint-config-mento": "workspace:*",
    "commitizen": "4.3.0",
    "cz-conventional-changelog": "3.3.0",
    "husky": "8.0.3",
  },
  "engines": {
    "node": "^18.15.0",
    "pnpm": "^8.1.1"
  },
  "config": {
    "commitizen": {
      "path": "./node_modules/cz-conventional-changelog"
    }
  },
}

Then, my commitlint looks like this. It's basically a copy-paste of @commitlint/config-conventional but with the questions.scope.description text slightly altered, this is the change I do not see when I do git commit.

// commitlint.config.js (have tried with .commitlintrc as well)
/* eslint-disable sort-keys */
module.exports = {
  extends: ['@commitlint/config-conventional'],
  prompt: {
    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. packages/ui or app/web)',
      },
      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".)',
      },
    },
  },
};

Here's my .husky/commit-msg hook as well. I've tried without the --config commitlint.config.js as well to no avail.

#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

pnpm exec commitlint --config commitlint.config.js --edit "$1"

Context

I'm trying with a small change just to test. All I really want is to adapt the text of the questions from @commitlint/config-conventional to better fit my team, but can't figure out what I'm doing wrong.

This is a monorepo and I want my commit titles to have a scope like:

feature(apps/web): Add new login hooks.

Hence why I want to change the hint text of the scope question. I also want to possibly translate these messages to a different language and give better hints to my team.

commitlint --version

17.9.0

git --version

2.38.0

node --version

18.15.0

@enrique-ramirez
Copy link
Author

Rubber duck debugging. While typing this a lightbulb went on on my head. I messed up. The problem was on my package.json file:

{
  "config": {
    "commitizen": {
      "path": "./node_modules/cz-conventional-changelog"
    }
  },
}

Should be:

{
  "config": {
    "commitizen": {
      "path": "@commitlint/cz-commitlint"
    }
  },
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

1 participant