Skip to content

Commit

Permalink
feat(core): readd support for .conventional-changelog-lintrc
Browse files Browse the repository at this point in the history
  • Loading branch information
marionebl committed Jul 11, 2017
1 parent 856f3da commit 02e4f43
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"rules": {
"legacy": true
}
}
5 changes: 5 additions & 0 deletions @commitlint/core/fixtures/overriden-legacy/.commitlintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"rules": {
"legacy": false
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"rules": {
"legacy": true
}
}
24 changes: 23 additions & 1 deletion @commitlint/core/src/load.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const valid = input => pick(input, 'extends', 'rules');

export default async (seed = {}) => {
// Obtain config from .rc files
const raw = rc('commitlint');
const raw = file();
const found = typeof raw.config === 'string';

// Use the default extends config if there is no userConfig file found
Expand Down Expand Up @@ -58,3 +58,25 @@ export default async (seed = {}) => {
};
}, preset);
};

function file() {
const legacy = rc('conventional-changelog-lint');
const legacyFound = typeof legacy.config === 'string';

const raw = rc('commitlint');
const rawFound = typeof raw.config === 'string';

if (legacyFound && !rawFound) {
console.warn(`Using legacy ${path.relative(process.cwd(), legacy.config)}. Rename to .commitlintrc to silence this warning.`);
}

if (legacyFound && rawFound) {
console.warn(`Ignored legacy ${path.relative(process.cwd(), legacy.config)} as ${path.relative(process.cwd(), raw.config)} superseeds it. Remove .conventional-changelog-lintrc to silence this warning.`);
}

if (rawFound) {
return raw;
}

return legacy;
}
20 changes: 20 additions & 0 deletions @commitlint/core/src/load.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,26 @@ test('ignores unknow keys recursively', async t => {
});
});

test('supports legacy .conventional-changelog-lintrc', async t => {
t.context.back = chdir('fixtures/legacy');
const actual = await load();
t.deepEqual(actual, {
rules: {
legacy: true
}
});
});

test('.commitlintrc overrides .conventional-changelog-lintrc', async t => {
t.context.back = chdir('fixtures/overriden-legacy');
const actual = await load();
t.deepEqual(actual, {
rules: {
legacy: false
}
});
});

function chdir(target) {
const to = path.resolve(cwd, target.split('/').join(path.sep));
process.chdir(to);
Expand Down

0 comments on commit 02e4f43

Please sign in to comment.