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

[Proposal] additional features for type-enum scope-enum #627

Open
3 of 4 tasks
xCykrix opened this issue Apr 20, 2019 · 7 comments
Open
3 of 4 tasks

[Proposal] additional features for type-enum scope-enum #627

xCykrix opened this issue Apr 20, 2019 · 7 comments

Comments

@xCykrix
Copy link

xCykrix commented Apr 20, 2019

Proposal

Hello! I was recently working with commitlint and noticed that "scope-enum" did not offer everything I would have liked. I made a PoC for the suggestion at https://www.npmjs.com/package/commitlint-scope .

The idea is to essentially allow each type to only allow specific scopes, and each scope to only allow specific values inside the brackets. Allowing each scope to have a blob or path to restrict which files may be commit-ed to the valu inside the brackets.

If this is something your team would be up to supporting natively, I would be more then willing to help where I can to integrate it.

"Addon" commitlint.config.js

module.exports = {
  extends: [ '@commitlint/config-conventional' ],
  scopes: {
    'yarn': { files: [ 'package.json', 'yarn.lock', '.yarnclean' ] },
    'lint': { files: [ '.eslintrc', '.huskyrc.js', '.editorconfig', 'commitlint.config.js' ] },
    'repo': { files: [ '*.md', 'LICENSE', '.gitignore' ] },
    'source': { files: [ 'src/*', 'src/**' ] },
    'engine': { files: [ 'index.js' ] },
    'staged': { files: [ '**', '**/*' ] }
  }
}

"Addon" Behavior

Good Commit

git add package.json
git commit -m "chore(yarn): updating package.json"

⧗   input: chore(yarn): updating package.json
✔   found 0 problems, 0 warnings
    (Need help? -> https://github.com/conventional-changelog/commitlint#what-is-commitlint )

Bad Commit

git add eslintrc package.json
git commit -m "chore(yarn): updating package.json"

⧗   input: chore(yarn): update package.json
✖   file '.eslintrc' was not allowed in selected scope [file-forbidden]
✖   found 1 problems, 0 warnings
    (Need help? -> https://github.com/conventional-changelog/commitlint#what-is-commitlint 

Unconfigured Scope

git add package.json
git commit -m "chore(bla): updating package.json"

⧗   input: chore(bla): update package.json
✖   detected commit scope not found in commitlint.config.js [no-detect]
✖   found 1 problems, 0 warnings
    (Need help? -> https://github.com/conventional-changelog/commitlint#what-is-commitlint )

Affected packages

  • cli
  • core
  • prompt
  • config-angular

Context

I created this PoC to allow more control over the specific components that commitlint will control by allowing globs and paths to be used to restrict which files can be commit-ed in which type and scopes.
Executing git diff --name-only --cached will allow you to fetch the current staged list of files to be commit-ed. Which is the main leverage for the PoC to be available.

#395 may be applicable to improving to the request too, allowing dynamic building of the lerna packages

@xCykrix xCykrix changed the title [Proposal] Extendable scope-enum [Proposal] Extendable type-enum scope-enum Apr 20, 2019
@xCykrix xCykrix changed the title [Proposal] Extendable type-enum scope-enum [Proposal] additional features for type-enum scope-enum Apr 20, 2019
@escapedcat
Copy link
Member

Hey @xCykrix ,
thx for your efforts! I could imagine to add this to the core. Let's see what @marionebl @byCedric think about it.

@xCykrix
Copy link
Author

xCykrix commented Apr 24, 2019

@escapedcat thanks! I wanted a little more fine tuned control and couldn't find a way to restrict the exact files allowed. I figured an official feature set would be more suitable and used over one that just hooks into the config and API with another CLI program.
Would also allow it not to have a duplicate prompt output, so it is all contained in one nice and neat one.

@xCykrix
Copy link
Author

xCykrix commented Apr 26, 2019

@escapedcat i'm working on building a better proof of concept that will actually integrate to the rules, perhaps to give a better idea to anyone else and to allow it to be easier to integrate since it will use the official shareable config loader.

@escapedcat
Copy link
Member

@xCykrix plugins just got merged: #588
I feel like that we might tend to not move this into core but let people use a plugin to achieve such rule. Let me confirm with the others.

@xCykrix
Copy link
Author

xCykrix commented Apr 28, 2019

@escapedcat alright, let me know! I'd be more then happy to create it as a plugin and maintain it.

@bobbui
Copy link

bobbui commented Nov 8, 2019

love to have that as well.

@xCykrix
Copy link
Author

xCykrix commented Nov 14, 2019

@thangbn I've just been getting back into using commit linting on my projects. I'll end up taking a look at the API for plugins and work from there. When I get started I'll pass a link regarding the plugin if does not already exist. 🙂

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

No branches or pull requests

4 participants