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

extends should be resolved from left to right #2069

Closed
1 task done
ikatyang opened this issue Aug 20, 2020 · 0 comments · Fixed by #2070
Closed
1 task done

extends should be resolved from left to right #2069

ikatyang opened this issue Aug 20, 2020 · 0 comments · Fixed by #2070

Comments

@ikatyang
Copy link
Contributor

The order of the current extends resolution is counterintuitive, extends are usually resolved from left to right, but it is currently resolved from right to left.

Expected Behavior

extends should be resolved from left to right.

Current Behavior

extends is currently resolved from right to left.

Affected packages

  • @commitlint/resolve-extends

Possible Solution

Change the order of the extends resolution.

Steps to Reproduce (for bugs)

Add the following test case to /@commitlint/resolve-extends/src/index.test.ts:

test('extends rules from left to right with overlap', () => {
  const input = {extends: ['left', 'right']};

  const require = (id: string) => {
    switch (id) {
      case 'left':
        return {rules: {a: true}};
      case 'right':
        return {rules: {a: false, b: true}};
      default:
        return {};
    }
  };

  const ctx = {resolve: id, require: jest.fn(require)} as ResolveExtendsContext;

  const actual = resolveExtends(input, ctx);

  const expected = {
    extends: ['left', 'right'],
    rules: {
      a: false,
      b: true,
    },
  };

  expect(actual).toEqual(expected);
});
● extends rules from left to right with overlap

    expect(received).toEqual(expected) // deep equality

    - Expected  - 1
    + Received  + 1

    @@ -2,9 +2,9 @@
        "extends": Array [
          "left",
          "right",
        ],
        "rules": Object {
    -     "a": false,
    +     "a": true,
          "b": true,
        },
      }

Context

I'd like to have a base config and extend it as needed, for example I want to use the base config most of the time:

{"extends": ["my-config"]}

and override it if the repository has some sharable special requirements:

{"extends": ["my-config", "my-config/special-requirements"]}

Your Environment

Executable Version
commitlint --version 9.1.2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging a pull request may close this issue.

2 participants