Skip to content

Commit 030298e

Browse files
committed
feat(core): readd support for .conventional-changelog-lintrc
1 parent bc460c8 commit 030298e

File tree

5 files changed

+58
-1
lines changed

5 files changed

+58
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"rules": {
3+
"legacy": true
4+
}
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"rules": {
3+
"legacy": false
4+
}
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"rules": {
3+
"legacy": true
4+
}
5+
}

@commitlint/core/src/load.js

+23-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const valid = input => pick(input, 'extends', 'rules');
1010

1111
export default async (seed = {}) => {
1212
// Obtain config from .rc files
13-
const raw = rc('commitlint');
13+
const raw = file();
1414
const found = typeof raw.config === 'string';
1515

1616
// Use the default extends config if there is no userConfig file found
@@ -58,3 +58,25 @@ export default async (seed = {}) => {
5858
};
5959
}, preset);
6060
};
61+
62+
function file() {
63+
const legacy = rc('conventional-changelog-lint');
64+
const legacyFound = typeof legacy.config === 'string';
65+
66+
const raw = rc('commitlint');
67+
const rawFound = typeof raw.config === 'string';
68+
69+
if (legacyFound && !rawFound) {
70+
console.warn(`Using legacy ${path.relative(process.cwd(), legacy.config)}. Rename to .commitlintrc to silence this warning.`);
71+
}
72+
73+
if (legacyFound && rawFound) {
74+
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.`);
75+
}
76+
77+
if (rawFound) {
78+
return raw;
79+
}
80+
81+
return legacy;
82+
}

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

+20
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,26 @@ test('ignores unknow keys recursively', async t => {
7474
});
7575
});
7676

77+
test('supports legacy .conventional-changelog-lintrc', async t => {
78+
t.context.back = chdir('fixtures/legacy');
79+
const actual = await load();
80+
t.deepEqual(actual, {
81+
rules: {
82+
legacy: true
83+
}
84+
});
85+
});
86+
87+
test('.commitlintrc overrides .conventional-changelog-lintrc', async t => {
88+
t.context.back = chdir('fixtures/overriden-legacy');
89+
const actual = await load();
90+
t.deepEqual(actual, {
91+
rules: {
92+
legacy: false
93+
}
94+
});
95+
});
96+
7797
function chdir(target) {
7898
const to = path.resolve(cwd, target.split('/').join(path.sep));
7999
process.chdir(to);

0 commit comments

Comments
 (0)