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

Enable "all"/* scopes in commit message #91

Closed
morewry opened this issue Oct 13, 2017 · 4 comments
Closed

Enable "all"/* scopes in commit message #91

morewry opened this issue Oct 13, 2017 · 4 comments

Comments

@morewry
Copy link

morewry commented Oct 13, 2017

Along similar lines of https://github.com/marionebl/commitlint/issues/75 (especially in a multi-repo) I think it is useful to have a scope for "everything." For example, I am setting up commitlint in an early-stage Lerna multi-repo, which means making commits to add commitlint. I am not adding commitlint to specific packages, but rather to the project, so the change affects all the possible scopes supported by config-lerna-scopes.

I can obviously bypass validation for this type of commit in the meantime, but if that becomes a habit for the team, other types of errors could creep in unless we all ensure we run once to verify the output's only error is scope related. Just overall seems like a better experience to have a way to make these types of commits with accurate messages without getting an error (especially given the superfluous warnings I am also getting, mentioned in other issues).

I've seen some projects use * or all, maybe config-lerna-scopes could add a valid scope along those lines or allow a configuration to define some additional valid scopes that don't directly map to module names?

⧗   input: chore(*): add commitlint
✖   scope must be one of [..., ..., ..., ..., ..., ..., ..., ..., ..., ..., ..., ..., ...] [scope-enum]
⚠   ...
⚠   ...
✖   found 1 problems, 2 warnings
@marionebl
Copy link
Contributor

marionebl commented Oct 13, 2017

Currently there is no mechanism in place for passing configuration to shareablecommitlint config.

You could take advantage of the fact commitlint.config.js is arbitrary JavaScript, like e.g. cybernaut is doing:

const {getPackages} = require('@commitlint/config-lerna-scopes').utils;

module.exports = {
  extends: ['@commitlint/config-angular'],
  rules: {
    'scope-enum': () => [2, 'always', [...getPackages(), '*']]
  }
};

For the time being I'd prefer documenting this as a pattern with config-lerna-scopes, although it has the disadvantage of working only with the .js config format.

We als should standardise this as optional API across all shareable config, will have to think about the best way to do that.

@morewry
Copy link
Author

morewry commented Nov 1, 2017

Thanks for the advice! I did end up doing something similar. In case it's useful to anyone else:

I'm using commitlint in combination with Commitizen. Originally I was using Commitizen's cz-conventional-changelog, but I wanted a few adjustments to that series of prompts. Thought about checking out commitlint's prompts, but tried out cz-customizable first due to having read an issue here that suggested commitlint wouldn't currently support a selection prompt for scopes (which I wanted), but knowing cz-customizable would. Then I came across commitlint-config-cz which will read from the same .cz-config.js configuration file and use it to set up commitlint rules.

.cz-config.js

Relevant parts include...

const scopes = JSON.parse(shelljs.exec('lerna ls --json', { silent: true }).stdout)
  .map(function(scope) {
    return { name: scope.name };
  });

const czCustomizableConfig = {

  scopes: [{ name: '*' }].concat(scopes)

};

module.exports = czCustomizableConfig;

I definitely like that I can share the same config between the two this way; I'd previously been using distinct configuration plugins for each tool.

@marionebl
Copy link
Contributor

Closing this, I think the current patterns suffice to cater this use case.

bpedersen pushed a commit to bpedersen/commitlint that referenced this issue Oct 15, 2019
@chr-ge
Copy link

chr-ge commented Jan 24, 2022

I got it to work like this:

const { getPackages } = require('@commitlint/config-lerna-scopes').utils

module.exports = {
  extends: ['@commitlint/config-conventional'],
  rules: {
    'scope-enum': ctx => getPackages(ctx).then(packages => [2, 'always', ['all', ...packages]]),
  },
}

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

No branches or pull requests

3 participants