Skip to content

Didn't work? #38

Closed
Closed
@xieyezi

Description

@xieyezi

version:

"commitlint-config-cz": "^0.12.1"

bug:

I use npm install commitlint-config-cz --save-dev install commitlint-config-cz,and I use it with commitizen and cz-customizable, but it not work.

this is my project.json:

 "config": {
    "commitizen": {
      "path": "node_modules/cz-customizable"
    }
  },
  "cz-customizable": {
    "config": "cz-config.js"
  },
  "husky": {
    "hooks": {
      "pre-commit": "lint-staged"
    }
  },
  "lint-staged": {
    "*.{ts,tsx}": [
      "npm run lint:ts",
      "npm run format",
      "git add"
    ]
  }
}

this is my commitlint.config.js:

module.exports = {
    extends: [
        'cz'
    ]
};

this is my .cz-config.js:

module.exports = {
  types: [
    { value: 'feat✨', name: '特性: 一个新的特性' },
    { value: 'fix🐞', name: '修复: 修复一个Bug' },
    { value: 'docs📚', name: '文档: 变更的只有文档' },
    { value: 'style💅', name: '格式: 空格, 分号等格式修复' },
    { value: 'refactor🛠', name: '重构: 代码重构,注意和特性、修复区分开' },
    { value: 'perf🐎', name: '性能: 提升性能' },
    { value: 'test🏁', name: '测试: 添加一个测试' },
    { value: 'revert⏪', name: '回滚: 代码回退' },
    { value: 'chore🗯', name: '工具:开发工具变动(构建、脚手架工具等)' }
  ],
  messages: {
    type: '选择一种你的提交类型:',
    customScope: '请输入修改范围(可选):',
    subject: '短说明:',
    body: '长说明,使用"|"换行(可选):',
    footer: '关联关闭的issue,例如:#31, #34(可选):',
    confirmCommit: '确定提交说明?'
  },
  allowCustomScopes: true,
  allowBreakingChanges: ['特性', '修复'],
  subjectLimit: 100
}

What's Happening

after i write those,I use git commit -m "xxxx" directly to commit, it's still pass the check,i don't konw why,hope got you resolve! thank you!

repository

this is my repository

Activity

whizark

whizark commented on Dec 4, 2019

@whizark
Owner

@xieyezi Hi, thanks for your detailed report. At first, it seems you need separately install & setup commitlint. It should be as followings:

  1. install @commitlint/cli.
    npm install --save-dev @commitlint/cli
    or
    yarn add --dev @commitlint/cli
  2. add Husky's commit-msg hook in your package.json:
      "husky": {
        "hooks": {
          "commit-msg": "commitlint -E HUSKY_GIT_PARAMS",
          "pre-commit": "lint-staged"
        }
      },
    

Commitlint works now with the following config.

{
        "rules": {
                "type-enum": [
                        2,
                        "always",
                        [
                                "feat✨",
                                "fix🐞",
                                "docs📚",
                                "style💅",
                                "refactor🛠",
                                "perf🐎",
                                "test🏁",
                                "revert⏪",
                                "chore🗯"
                        ]
                ]
        }
}

In addition, your config file for cz-customizable is not cz-config.js but .cz-config.js, right? You might also need to fix the follwoing lines in your package.json.

  "cz-customizable": {
    "config": ".cz-config.js"
  },

BTW, commitlint-config-cz adds only type-enum, scope-enum rules as above (which are read from your cz-customizable config).
This means commitlnt allows you to commit with empty type, empty subject by the default, so you might also want to add type-empty, subject-empty rules to your commitlint.config.js (see also scope-empty).

module.exports = {
    extends: [
        'cz'
    ],
    rules: {
        'type-empty': [2, 'never'],
        'type-subject': [2, 'never']
    }
};

I hope this solves issues 😃

xieyezi

xieyezi commented on Dec 4, 2019

@xieyezi
Author

@whizark thanks got your reply , I do what you said,but still have this problem?

xieyezi

xieyezi commented on Dec 4, 2019

@xieyezi
Author

@whizark :this is my repository

whizark

whizark commented on Dec 4, 2019

@whizark
Owner

@xieyezi Ah, sorry for my typo in commitlint.config.js. subject-empty is the correct rule name, so the following config should work.

module.exports = {
    extends: [
        'cz'
    ],
    rules: {
        'type-empty': [2, 'never'],
        'subject-empty': [2, 'never']
    }
};
xieyezi

xieyezi commented on Dec 5, 2019

@xieyezi
Author

@whizark hi, I try you said,but it's still like before?

repository

xieyezi

xieyezi commented on Dec 5, 2019

@xieyezi
Author

@whizark hi, maybe some files not changes,so I delete node_modules files, and reinstall , it works normal finally!
so thank your help ,best wishes with you!!!🤗

youngjuning

youngjuning commented on Aug 11, 2021

@youngjuning

Why not build it in?

elton11220

elton11220 commented on Jun 7, 2023

@elton11220

@xieyezi Ah, sorry for my typo in commitlint.config.js. subject-empty is the correct rule name, so the following config should work.

module.exports = {
    extends: [
        'cz'
    ],
    rules: {
        'type-empty': [2, 'never'],
        'subject-empty': [2, 'never']
    }
};

Excellent!

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @whizark@youngjuning@xieyezi@elton11220

        Issue actions

          Didn't work? · Issue #38 · whizark/commitlint-config-cz