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

feat(core): Implement footer-contains rules #76

Closed
wants to merge 15 commits into from

Conversation

nhodges
Copy link

@nhodges nhodges commented Sep 19, 2017

No description provided.

@marionebl
Copy link
Contributor

Thanks a lot for the PR!
I'll have a thorough look at it tomorrow.

Could you write a short description with examples for the use cases you had in mind?

@nhodges
Copy link
Author

nhodges commented Sep 20, 2017

@marionebl I'd specifically like to enforce the presence of issue references in the footer with a rule like this:

rules: {
  'footer-contains': /PROJECT-(\d+)$/gi
}

@marionebl
Copy link
Contributor

I am on vacation till 3th Oct, will make an effort to merge it then!

@marionebl
Copy link
Contributor

Thanks for your work. Checking for the presence of an issue ticket id is a common use case. I am reluctant to merge this, because

  • I'd like to keep parsing/custom pattern matching out of commitlint and let conventional-commits-parser concern itself with that. That is also the reason there is no other RegEx based rule yet in core
  • conventional-commits-parser supports the issuePrefixes option, which defaults to ['#']. A rule enforcing the presence of issues (does not exist yet) plus custom parserOpts could do the trick in a safer manner

Pseudo code

// commitlint.config.js
module.exports = {
  parserPreset: './parser-preset',
  rules: {
     'references-empty': [2, 'never'],
     // extended use case, check if id is present
     'references-enum': getIssueIds().then((ids) => [2, 'always', ids])
  }
}

// parser-preset
module.exports = {
  paserOpts: {
    issuePrefixes: ['PROJECT-']
  }
};

What do you think?

@marionebl marionebl mentioned this pull request Oct 17, 2017
@marionebl
Copy link
Contributor

Thanks for your contribution. I'll released the alternative references-empty via 4.3, this should fit the same usecase

@marionebl marionebl closed this Nov 8, 2017
@jribeiro
Copy link

Hi guys, I realise this issue is closed but I noticed that this only seems to work if the ticket reference is placed on the footer. Any plans of supporting this validation on the subject or as another field between the type and the subject?

Ideally I'd like to achieve: type(scope): TICKET-ID Subject line.... What do you think? Happy to contribute if it makes sense.

@marionebl
Copy link
Contributor

Hey @jribeiro, please refer to the examples provided via #95.

Currently you can only check for the presence of a ticket id in the entire commit, not if it is present at a certain position.

@jribeiro
Copy link

Hi @marionebl, thanks for that! I've followed the examples and I couldn't get it to work. Maybe you can help?

// commitlint.config.js

module.exports = {
  'extends': [
    '@commitlint/config-angular',
    '@commitlint/config-lerna-scopes'
  ],
  'parserPreset': './parser-preset',
  'rules': {
    'references-empty': [2, 'never'],
  }
}

// parser-preset.js

module.exports = {
    parserOpts: {
        issuePrefixes: ['TEST-']
    }
};

When I run

echo "chore: TEST-1 Test Message" | ./node_modules/.bin/commitlint

I get ✖ references may not be empty [references-empty]

And when I add 'references-enum': [2, 'always', 'TEST-1'] to the rules section I get an exception.

TypeError: rule is not a function
    at .../node_modules/@commitlint/core/lib/lint.js:72:18
    at Array.map (<anonymous>)
    at Object.<anonymous> (.../node_modules/@commitlint/core/lib/lint.js:53:8)
    at <anonymous>

Any thoughts?

@marionebl
Copy link
Contributor

marionebl commented Nov 13, 2017

Let's take this to a distinct issue at #115

@conventional-changelog conventional-changelog locked and limited conversation to collaborators Nov 13, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants