Skip to content

Commit c0a86f5

Browse files
authored
fix(resolve-extends): extends field should be resolved from left to right (#2070)
* test: add failing test * fix(resolve-extends): `extends` field should be resolved from left to right BREAKING CHANGE: The order of the `extends` resolution is changed from right-to-left to left-to-right
1 parent 9e5d9bf commit c0a86f5

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

@commitlint/resolve-extends/src/index.test.ts

+29
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,35 @@ test('propagates contents recursively with overlap', () => {
243243
expect(actual).toEqual(expected);
244244
});
245245

246+
test('extends rules from left to right with overlap', () => {
247+
const input = {extends: ['left', 'right']};
248+
249+
const require = (id: string) => {
250+
switch (id) {
251+
case 'left':
252+
return {rules: {a: true}};
253+
case 'right':
254+
return {rules: {a: false, b: true}};
255+
default:
256+
return {};
257+
}
258+
};
259+
260+
const ctx = {resolve: id, require: jest.fn(require)} as ResolveExtendsContext;
261+
262+
const actual = resolveExtends(input, ctx);
263+
264+
const expected = {
265+
extends: ['left', 'right'],
266+
rules: {
267+
a: false,
268+
b: true,
269+
},
270+
};
271+
272+
expect(actual).toEqual(expected);
273+
});
274+
246275
test('extending contents should take precedence', () => {
247276
const input = {extends: ['extender-name'], zero: 'root'};
248277

@commitlint/resolve-extends/src/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export default function resolveExtends(
3232
context: ResolveExtendsContext = {}
3333
) {
3434
const {extends: e} = config;
35-
const extended = loadExtends(config, context).reduceRight(
35+
const extended = loadExtends(config, context).reduce(
3636
(r, {extends: _, ...c}) =>
3737
mergeWith(r, c, (objValue, srcValue) => {
3838
if (Array.isArray(objValue)) {
@@ -78,7 +78,7 @@ function loadExtends(
7878
config.parserPreset = parserPreset;
7979
}
8080

81-
return [...configs, c, ...loadExtends(c, ctx)];
81+
return [...configs, ...loadExtends(c, ctx), c];
8282
}, []);
8383
}
8484

0 commit comments

Comments
 (0)