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

extended configurations do not concatenate scope-enum #528

Open
4 tasks done
theetrain opened this issue Dec 22, 2018 · 4 comments
Open
4 tasks done

extended configurations do not concatenate scope-enum #528

theetrain opened this issue Dec 22, 2018 · 4 comments

Comments

@theetrain
Copy link

Thank you for maintaining commitlint.

When extending multiple configurations, whether local or package-based, the scope-enum option does not concatenate the scope-enum options from every extended configuration. I am unsure if this is intentional behaviour of commitlint.

Expected Behavior

When using the extends configuration option, the scope-enum sub option concatenates or merges all imported configs.

Current Behavior

When using the extends configuration option, the scope-enum sub option does not concatenate and only the left-most array item in the extends value has their scope-enum sub option resolved.

Affected packages

  • cli
  • core
  • config-lerna-scopes
  • resolve-extends

Possible Solution

Depending on the intent of commitlint, the answer lies somewhere in resolve-extends. I'd be happy to contribute in any case.

Steps to Reproduce (for bugs)

Here is a minimal example using only local configs: https://repl.it/@EnricoSacchetti/Commitlint-Extends-concatenation

To reproduce:

  1. Open link above
  2. Click 'run' at the top
  3. Observe the output of 'Base config' that shows values from base.js
  4. Observe the output of 'Extended config' that shows values from custom.js, but not base.js

Sample output:

base.js {"rules":{"scope-enum":[2,"always",["chore","test"]]}}
base config {"extends":["./base.js"]}
Resolved base config:  [ 2, 'always', [ 'chore', 'test' ] ]

custom.js {"rules":{"scope-enum":[2,"always",["package-one","package-two"]]}}
extended config {"extends":["./custom.js","./base.js"]}
Resolved extended config:  [ 2, 'always', [ 'package-one', 'package-two' ] ]

Context

I am a maintainer of the telus/tds-core repository that uses lerna, and @commitlint/config-lerna-scopes. My goal is to set up custom scopes as well as the scopes gathered by config-lerna-scopes, but concatenation has become an issue.

As a workaround, I concatenated my scopes manually by using the @commitlint/config-lerna-scopes package API, but this is a brittle solution since it is not meant to be used this way. Importing scopes using @commitlint/config-lerna-scopes@7.0.0 is synchronous, and @commitlint/config-lerna-scopes@7.2.1 is asynchronous. I want to make proper use of extends or @commitlint/load.

If this non-concatenation behaviour of extends is a bug, then resolving the bug and using extends for conatenating options may be the best solution.

Your Environment

Executable Version
commitlint --version 7.2.1
git --version 2.19.2
node --version 8.11.3
@lrdxg1
Copy link

lrdxg1 commented Jan 3, 2019

I faced the same problem and had to manually load the utility provided by config-lerna-scopes to add my own scopes. Here is my commitlint.config.js:

const lernaScopesConfig = require('@commitlint/config-lerna-scopes');

const scopes = ['release', 'tooling'];

const getScopes = (initialEnum = []) => (ctx) =>
  lernaScopesConfig.utils
    .getPackages()
    .then((packageList) => initialEnum.concat(packageList))
    .then((scopeList) => [2, 'always', scopeList]);

module.exports = {
  extends: ['@commitlint/config-conventional'],
  rules: {
    'scope-enum': (ctx) => getScopes(scopes)(ctx),
  },
};

@marionebl
Copy link
Contributor

Thanks for raising this. The maintainers had some ideas about this and an ongoing discussion on our Slack channel: https://devtoolscommunity.herokuapp.com/

@frbuceta
Copy link

How is this going?

@escapedcat
Copy link
Member

I don't think there was an outcome or a plan. If you're interested you can join the slack and restart the discussion.

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

No branches or pull requests

5 participants