Skip to content
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

Enforcing a single whitespace between colon and commit subject #1697

Open
x87 opened this issue May 18, 2020 · 3 comments
Open

Enforcing a single whitespace between colon and commit subject #1697

x87 opened this issue May 18, 2020 · 3 comments
Labels

Comments

@x87
Copy link

x87 commented May 18, 2020

Hey there!

Commitlint's recommended rules include subject-case checking that the subject is not sentence-case, start-case, pascal-case, upper-case. However this rule is easy to bypass by adding a leading whitespace in the subject. From the user perspective it's almost impossible to see if there are one or two whitespaces:

feat: MY SUBJECT // two whitespaces between feat: and MY, bypassing subject-case

and it discards the benefits of the subject-case rule.

Please consider adding an extra rule that enforces that subject must not start with a whitespace.

@x87 x87 changed the title Enforcing a single whitespace before colon and commit subject Enforcing a single whitespace between colon and commit subject May 18, 2020
@Relsoul

This comment was marked as off-topic.

@escapedcat

This comment was marked as off-topic.

@Relsoul
Copy link

Relsoul commented Apr 18, 2022

@escapedcat
I mean found the problem of consent. But I have now found a solution
The default parser of commitlint is that there must be a space after the type, and then the subject will be read

//  node_modules/conventional-commits-parser/index.js
headerPattern: /^(\w*)(?:\(([\w$.\-*/ ]*)\))?: (.*)$/,

If you want to solve this problem, you only need to configure @x87

//commitlint.config.ts

 parserPreset: {
    parserOpts: {
      headerPattern: /^(\w*)(?:\(([\w$.\-*/ ]*)\))?:(.*)$/,
    },
  },

and I suggest you to customize the rules

rules: {
    'header-type-aliflow': [2, 'always'],
  },
  plugins: [
    {
      rules: {
        'header-type-aliflow'(arg) {
          const { raw } = arg;
          let pass = true;
          const msg =
            ' ^(feat|fix):\\#[A-Z]+\\-[0-9]+.*|^(docs|test|style|refactor|chore):\\S+|(Merge branch.*)。     ';
          const reg =
            /^(feat|fix):#[A-Z]+\-[0-9]+.*|^(docs|test|style|refactor|chore):\S+|(Merge branch.*)/;
          if (!reg.test(raw)) {
            pass = false;
          }
          const resdata: RuleOutcome = [pass, msg];
          return resdata;
        },
      },
    },

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

3 participants