Skip to content

Commit b0e63d9

Browse files
byCedricmarionebl
authored andcommitted
feat(load): add formatter option with default value
1 parent 253d1ce commit b0e63d9

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
formatter: 'commitlint-junit'
3+
};

@commitlint/load/src/index.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,19 @@ import pick from 'lodash.pick';
99
import resolveFrom from 'resolve-from';
1010

1111
const w = (a, b) => (Array.isArray(b) ? b : undefined);
12-
const valid = input => pick(input, 'extends', 'rules', 'parserPreset');
12+
const valid = input =>
13+
pick(input, 'extends', 'rules', 'parserPreset', 'formatter');
1314

1415
export default async (seed = {}, options = {cwd: process.cwd()}) => {
1516
const loaded = await loadConfig(options.cwd, options.file);
1617
const base = loaded.filepath ? path.dirname(loaded.filepath) : options.cwd;
1718

1819
// Merge passed config with file based options
1920
const config = valid(merge(loaded.config, seed));
20-
const opts = merge({extends: [], rules: {}}, pick(config, 'extends'));
21+
const opts = merge(
22+
{extends: [], rules: {}, formatter: '@commitlint/format'},
23+
pick(config, 'extends')
24+
);
2125

2226
// Resolve parserPreset key
2327
if (typeof config.parserPreset === 'string') {

@commitlint/load/src/index.test.js

+21
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ test('respects cwd option', async t => {
5858
const cwd = await git.bootstrap('fixtures/recursive-extends/first-extended');
5959
const actual = await load({}, {cwd});
6060
t.deepEqual(actual, {
61+
formatter: '@commitlint/format',
6162
extends: ['./second-extended'],
6263
rules: {
6364
one: 1,
@@ -70,6 +71,7 @@ test('recursive extends', async t => {
7071
const cwd = await git.bootstrap('fixtures/recursive-extends');
7172
const actual = await load({}, {cwd});
7273
t.deepEqual(actual, {
74+
formatter: '@commitlint/format',
7375
extends: ['./first-extended'],
7476
rules: {
7577
zero: 0,
@@ -84,6 +86,7 @@ test('recursive extends with json file', async t => {
8486
const actual = await load({}, {cwd});
8587

8688
t.deepEqual(actual, {
89+
formatter: '@commitlint/format',
8790
extends: ['./first-extended'],
8891
rules: {
8992
zero: 0,
@@ -98,6 +101,7 @@ test('recursive extends with yaml file', async t => {
98101
const actual = await load({}, {cwd});
99102

100103
t.deepEqual(actual, {
104+
formatter: '@commitlint/format',
101105
extends: ['./first-extended'],
102106
rules: {
103107
zero: 0,
@@ -112,6 +116,7 @@ test('recursive extends with js file', async t => {
112116
const actual = await load({}, {cwd});
113117

114118
t.deepEqual(actual, {
119+
formatter: '@commitlint/format',
115120
extends: ['./first-extended'],
116121
rules: {
117122
zero: 0,
@@ -126,6 +131,7 @@ test('recursive extends with package.json file', async t => {
126131
const actual = await load({}, {cwd});
127132

128133
t.deepEqual(actual, {
134+
formatter: '@commitlint/format',
129135
extends: ['./first-extended'],
130136
rules: {
131137
zero: 0,
@@ -160,6 +166,7 @@ test('ignores unknow keys', async t => {
160166
const actual = await load({}, {cwd});
161167

162168
t.deepEqual(actual, {
169+
formatter: '@commitlint/format',
163170
extends: [],
164171
rules: {
165172
foo: 'bar',
@@ -173,6 +180,7 @@ test('ignores unknow keys recursively', async t => {
173180
const actual = await load({}, {cwd});
174181

175182
t.deepEqual(actual, {
183+
formatter: '@commitlint/format',
176184
extends: ['./one'],
177185
rules: {
178186
zero: 0,
@@ -189,6 +197,7 @@ test('find up from given cwd', async t => {
189197
const actual = await load({}, {cwd});
190198

191199
t.deepEqual(actual, {
200+
formatter: '@commitlint/format',
192201
extends: [],
193202
rules: {
194203
child: true,
@@ -204,6 +213,7 @@ test('find up config from outside current git repo', async t => {
204213
const actual = await load({}, {cwd});
205214

206215
t.deepEqual(actual, {
216+
formatter: '@commitlint/format',
207217
extends: [],
208218
rules: {
209219
child: false,
@@ -212,3 +222,14 @@ test('find up config from outside current git repo', async t => {
212222
}
213223
});
214224
});
225+
226+
test('respects formatter option', async t => {
227+
const cwd = await git.bootstrap('fixtures/formatter');
228+
const actual = await load({}, {cwd});
229+
230+
t.deepEqual(actual, {
231+
formatter: 'commitlint-junit',
232+
extends: [],
233+
rules: {}
234+
});
235+
});

0 commit comments

Comments
 (0)