Skip to content

Commit

Permalink
fix(resolve-extends): override array on extending rules (#470) (#539)
Browse files Browse the repository at this point in the history
  • Loading branch information
Oleg Ulyanov authored and marionebl committed Jan 27, 2019
1 parent 5a6a4a8 commit b35000c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
9 changes: 7 additions & 2 deletions @commitlint/resolve-extends/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,18 @@ import path from 'path';
import 'resolve-global'; // eslint-disable-line import/no-unassigned-import
import requireUncached from 'require-uncached';
import resolveFrom from 'resolve-from';
import {merge, omit} from 'lodash';
import {isArray, merge, mergeWith, omit} from 'lodash';

// Resolve extend configs
export default function resolveExtends(config = {}, context = {}) {
const {extends: e} = config;
const extended = loadExtends(config, context).reduceRight(
(r, c) => merge(r, omit(c, 'extends')),
(r, c) =>
mergeWith(r, omit(c, 'extends'), (objValue, srcValue) => {
if (isArray(objValue)) {
return srcValue;
}
}),
e ? {extends: e} : {}
);

Expand Down
28 changes: 28 additions & 0 deletions @commitlint/resolve-extends/src/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,34 @@ test('propagates contents recursively', t => {
t.deepEqual(actual, expected);
});

test('propagates contents recursively with overlap', t => {
const input = {extends: ['extender-name']};

const actual = resolveExtends(input, {
resolve: id,
require(id) {
if (id === 'extender-name') {
return {
extends: ['recursive-extender-name'],
rules: {rule: ['zero', 'one']}
};
}
if (id === 'recursive-extender-name') {
return {rules: {rule: ['two', 'three', 'four']}};
}
}
});

const expected = {
extends: ['extender-name'],
rules: {
rule: ['zero', 'one']
}
};

t.deepEqual(actual, expected);
});

test('extending contents should take precedence', t => {
const input = {extends: ['extender-name'], zero: 'root'};

Expand Down

0 comments on commit b35000c

Please sign in to comment.