Skip to content

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

Open
@xCykrix

Description

@xCykrix

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions