Skip to content

Didn't work? #38

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
xieyezi opened this issue Dec 4, 2019 · 8 comments
Closed

Didn't work? #38

xieyezi opened this issue Dec 4, 2019 · 8 comments

Comments

@xieyezi
Copy link

xieyezi commented Dec 4, 2019

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

@whizark
Copy link
Owner

whizark commented Dec 4, 2019

@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
Copy link
Author

xieyezi commented Dec 4, 2019

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

@xieyezi
Copy link
Author

xieyezi commented Dec 4, 2019

@whizark :this is my repository

@whizark
Copy link
Owner

whizark commented Dec 4, 2019

@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
Copy link
Author

xieyezi commented Dec 5, 2019

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

repository

@xieyezi
Copy link
Author

xieyezi commented Dec 5, 2019

@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!!!🤗

@xieyezi xieyezi closed this as completed Dec 5, 2019
@youngjuning
Copy link

Why not build it in?

@elton11220
Copy link

@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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants