Skip to content

Commit

Permalink
feat(load): add formatter option with default value
Browse files Browse the repository at this point in the history
  • Loading branch information
byCedric authored and marionebl committed Oct 5, 2018
1 parent 253d1ce commit b0e63d9
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
3 changes: 3 additions & 0 deletions @commitlint/load/fixtures/formatter/commitlint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
formatter: 'commitlint-junit'
};
8 changes: 6 additions & 2 deletions @commitlint/load/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,19 @@ import pick from 'lodash.pick';
import resolveFrom from 'resolve-from';

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

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

// Merge passed config with file based options
const config = valid(merge(loaded.config, seed));
const opts = merge({extends: [], rules: {}}, pick(config, 'extends'));
const opts = merge(
{extends: [], rules: {}, formatter: '@commitlint/format'},
pick(config, 'extends')
);

// Resolve parserPreset key
if (typeof config.parserPreset === 'string') {
Expand Down
21 changes: 21 additions & 0 deletions @commitlint/load/src/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ test('respects cwd option', async t => {
const cwd = await git.bootstrap('fixtures/recursive-extends/first-extended');
const actual = await load({}, {cwd});
t.deepEqual(actual, {
formatter: '@commitlint/format',
extends: ['./second-extended'],
rules: {
one: 1,
Expand All @@ -70,6 +71,7 @@ test('recursive extends', async t => {
const cwd = await git.bootstrap('fixtures/recursive-extends');
const actual = await load({}, {cwd});
t.deepEqual(actual, {
formatter: '@commitlint/format',
extends: ['./first-extended'],
rules: {
zero: 0,
Expand All @@ -84,6 +86,7 @@ test('recursive extends with json file', async t => {
const actual = await load({}, {cwd});

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

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

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

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

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

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

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

t.deepEqual(actual, {
formatter: '@commitlint/format',
extends: [],
rules: {
child: false,
Expand All @@ -212,3 +222,14 @@ test('find up config from outside current git repo', async t => {
}
});
});

test('respects formatter option', async t => {
const cwd = await git.bootstrap('fixtures/formatter');
const actual = await load({}, {cwd});

t.deepEqual(actual, {
formatter: 'commitlint-junit',
extends: [],
rules: {}
});
});

0 comments on commit b0e63d9

Please sign in to comment.