Skip to content

Commit 2bcc941

Browse files
committed
fix: use conventional-changelog-angular again
1 parent 6dc909e commit 2bcc941

37 files changed

+618
-560
lines changed

@commitlint/core/package.json

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -130,18 +130,19 @@
130130
"xo": "0.18.2"
131131
},
132132
"dependencies": {
133-
"babel-runtime": "6.23.0",
134-
"chalk": "1.1.3",
135-
"conventional-commits-parser": "1.3.0",
136-
"franc": "2.0.0",
137-
"git-raw-commits": "1.1.2",
138-
"git-toplevel": "1.1.1",
133+
"babel-runtime": "^6.23.0",
134+
"chalk": "^2.0.1",
135+
"conventional-changelog-angular": "^1.3.3",
136+
"conventional-commits-parser": "^1.3.0",
137+
"franc": "^2.0.0",
138+
"git-raw-commits": "^1.1.2",
139+
"git-toplevel": "^1.1.1",
139140
"import-from": "^2.1.0",
140-
"lodash": "4.17.4",
141-
"mz": "2.6.0",
141+
"lodash": "^4.17.4",
142+
"mz": "^2.6.0",
142143
"path-exists": "^3.0.0",
143-
"pos": "0.4.2",
144-
"rc": "1.1.7",
144+
"pos": "^0.4.2",
145+
"rc": "^1.1.7",
145146
"resolve-from": "^3.0.0",
146147
"semver": "^5.3.0"
147148
}

@commitlint/core/src/library/parse.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,16 @@ import {sync} from 'conventional-commits-parser';
22

33
export default parse;
44

5-
function parse(message, options, parser = sync) {
6-
const parsed = parser(message, options);
5+
async function parse(message, parser = sync) {
6+
// Prevent conventional-changelog-angular from spamming startup
7+
// TODO: Remove when https://github.com/conventional-changelog/conventional-changelog/pull/206 lands
8+
const _error = console.error;
9+
console.error = () => {};
10+
const opts = require('conventional-changelog-angular');
11+
console.error = _error;
12+
13+
const {parserOpts} = await opts;
14+
const parsed = parser(message, parserOpts);
715
parsed.raw = message;
816
return parsed;
917
}

@commitlint/core/src/library/parse.test.js

Lines changed: 54 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,78 @@ import test from 'ava';
22
import parse from './parse';
33

44
test('throws when called without params', t => {
5-
t.throws(() => parse(), /Expected a raw commit/);
5+
t.throws(parse(), /Expected a raw commit/);
66
});
77

88
test('throws when called with empty message', t => {
9-
t.throws(() => parse(''), /Expected a raw commit/);
9+
t.throws(parse(''), /Expected a raw commit/);
1010
});
1111

12-
test('returns object with raw message', t => {
12+
test('returns object with raw message', async t => {
1313
const message = 'type(scope): subject';
14-
const actual = parse(message);
14+
const actual = await parse(message);
1515
t.is(actual.raw, message);
1616
});
1717

1818
test('calls parser with message and passed options', t => {
1919
const message = 'message';
20-
const options = {};
2120

22-
parse(message, options, (m, o) => {
21+
parse(message, m => {
2322
t.is(message, m);
24-
t.is(options, o);
2523
return {};
2624
});
2725
});
2826

29-
test('passes object up from parser function', t => {
27+
test('passes object up from parser function', async t => {
3028
const message = 'message';
31-
const options = {};
3229
const result = {};
33-
const actual = parse(message, options, () => result);
30+
const actual = await parse(message, () => result);
3431
t.is(actual, result);
3532
});
33+
34+
test('returns object with expected keys', async t => {
35+
const message = 'message';
36+
const actual = await parse(message);
37+
const expected = {
38+
body: null,
39+
footer: null,
40+
header: 'message',
41+
mentions: [],
42+
merge: null,
43+
notes: [],
44+
raw: 'message',
45+
references: [],
46+
revert: null,
47+
scope: null,
48+
subject: null,
49+
type: null
50+
};
51+
t.deepEqual(actual, expected);
52+
});
53+
54+
test('uses angular grammar', async t => {
55+
const message = 'type(scope): subject';
56+
const actual = await parse(message);
57+
const expected = {
58+
body: null,
59+
footer: null,
60+
header: 'type(scope): subject',
61+
mentions: [],
62+
merge: null,
63+
notes: [],
64+
raw: 'type(scope): subject',
65+
references: [],
66+
revert: null,
67+
scope: 'scope',
68+
subject: 'subject',
69+
type: 'type'
70+
};
71+
t.deepEqual(actual, expected);
72+
});
73+
74+
test('supports scopes with /', async t => {
75+
const message = 'type(some/scope): subject';
76+
const actual = await parse(message);
77+
t.is(actual.scope, 'some/scope');
78+
t.is(actual.subject, 'subject');
79+
});

@commitlint/core/src/lint.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import isIgnored from './library/is-ignored';
33
import parse from './library/parse';
44
import implementations from './rules';
55

6-
export default (message, rules = {}) => {
6+
export default async (message, rules = {}) => {
77
// Found a wildcard match, skip
88
if (isIgnored(message)) {
99
return {
@@ -14,7 +14,7 @@ export default (message, rules = {}) => {
1414
}
1515

1616
// Parse the commit message
17-
const parsed = parse(message);
17+
const parsed = await parse(message);
1818

1919
// Validate against all rules
2020
const results = entries(rules)

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,34 @@ import test from 'ava';
22
import lint from './lint';
33

44
test('throws without params', t => {
5-
t.throws(() => lint());
5+
t.throws(lint());
66
});
77

88
test('throws with empty message', t => {
9-
t.throws(() => lint(''));
9+
t.throws(lint(''));
1010
});
1111

12-
test('positive on stub message and no rule', t => {
13-
const actual = lint('foo: bar');
12+
test('positive on stub message and no rule', async t => {
13+
const actual = await lint('foo: bar');
1414
t.true(actual.valid);
1515
});
1616

17-
test('positive on stub message and adhered rule', t => {
18-
const actual = lint('foo: bar', {
17+
test('positive on stub message and adhered rule', async t => {
18+
const actual = await lint('foo: bar', {
1919
'type-enum': [2, 'always', ['foo']]
2020
});
2121
t.true(actual.valid);
2222
});
2323

24-
test('negative on stub message and broken rule', t => {
25-
const actual = lint('foo: bar', {
24+
test('negative on stub message and broken rule', async t => {
25+
const actual = await lint('foo: bar', {
2626
'type-enum': [2, 'never', ['foo']]
2727
});
2828
t.false(actual.valid);
2929
});
3030

31-
test('positive on ignored message and broken rule', t => {
32-
const actual = lint('Revert "some bogus commit"', {
31+
test('positive on ignored message and broken rule', async t => {
32+
const actual = await lint('Revert "some bogus commit"', {
3333
'type-empty': [2, 'never']
3434
});
3535
t.true(actual.valid);

@commitlint/core/src/rules/body-case.test.js

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -16,74 +16,74 @@ const parsed = {
1616
uppercase: parse(messages.uppercase)
1717
};
1818

19-
test('with empty body should succeed for "never lowercase"', t => {
20-
const [actual] = bodyCase(parsed.empty, 'never', 'lowercase');
19+
test('with empty body should succeed for "never lowercase"', async t => {
20+
const [actual] = bodyCase(await parsed.empty, 'never', 'lowercase');
2121
const expected = true;
2222
t.is(actual, expected);
2323
});
2424

25-
test('with empty body should succeed for "always lowercase"', t => {
26-
const [actual] = bodyCase(parsed.empty, 'always', 'lowercase');
25+
test('with empty body should succeed for "always lowercase"', async t => {
26+
const [actual] = bodyCase(await parsed.empty, 'always', 'lowercase');
2727
const expected = true;
2828
t.is(actual, expected);
2929
});
3030

31-
test('with empty body should succeed for "never uppercase"', t => {
32-
const [actual] = bodyCase(parsed.empty, 'never', 'uppercase');
31+
test('with empty body should succeed for "never uppercase"', async t => {
32+
const [actual] = bodyCase(await parsed.empty, 'never', 'uppercase');
3333
const expected = true;
3434
t.is(actual, expected);
3535
});
3636

37-
test('with empty body should succeed for "always uppercase"', t => {
38-
const [actual] = bodyCase(parsed.empty, 'always', 'uppercase');
37+
test('with empty body should succeed for "always uppercase"', async t => {
38+
const [actual] = bodyCase(await parsed.empty, 'always', 'uppercase');
3939
const expected = true;
4040
t.is(actual, expected);
4141
});
4242

43-
test('with lowercase body should fail for "never lowercase"', t => {
44-
const [actual] = bodyCase(parsed.lowercase, 'never', 'lowercase');
43+
test('with lowercase body should fail for "never lowercase"', async t => {
44+
const [actual] = bodyCase(await parsed.lowercase, 'never', 'lowercase');
4545
const expected = false;
4646
t.is(actual, expected);
4747
});
4848

49-
test('with lowercase body should succeed for "always lowercase"', t => {
50-
const [actual] = bodyCase(parsed.lowercase, 'always', 'lowercase');
49+
test('with lowercase body should succeed for "always lowercase"', async t => {
50+
const [actual] = bodyCase(await parsed.lowercase, 'always', 'lowercase');
5151
const expected = true;
5252
t.is(actual, expected);
5353
});
5454

55-
test('with mixedcase body should succeed for "never lowercase"', t => {
56-
const [actual] = bodyCase(parsed.mixedcase, 'never', 'lowercase');
55+
test('with mixedcase body should succeed for "never lowercase"', async t => {
56+
const [actual] = bodyCase(await parsed.mixedcase, 'never', 'lowercase');
5757
const expected = true;
5858
t.is(actual, expected);
5959
});
6060

61-
test('with mixedcase body should fail for "always lowercase"', t => {
62-
const [actual] = bodyCase(parsed.mixedcase, 'always', 'lowercase');
61+
test('with mixedcase body should fail for "always lowercase"', async t => {
62+
const [actual] = bodyCase(await parsed.mixedcase, 'always', 'lowercase');
6363
const expected = false;
6464
t.is(actual, expected);
6565
});
6666

67-
test('with mixedcase body should succeed for "never uppercase"', t => {
68-
const [actual] = bodyCase(parsed.mixedcase, 'never', 'uppercase');
67+
test('with mixedcase body should succeed for "never uppercase"', async t => {
68+
const [actual] = bodyCase(await parsed.mixedcase, 'never', 'uppercase');
6969
const expected = true;
7070
t.is(actual, expected);
7171
});
7272

73-
test('with mixedcase body should fail for "always uppercase"', t => {
74-
const [actual] = bodyCase(parsed.mixedcase, 'always', 'uppercase');
73+
test('with mixedcase body should fail for "always uppercase"', async t => {
74+
const [actual] = bodyCase(await parsed.mixedcase, 'always', 'uppercase');
7575
const expected = false;
7676
t.is(actual, expected);
7777
});
7878

79-
test('with uppercase body should fail for "never uppercase"', t => {
80-
const [actual] = bodyCase(parsed.uppercase, 'never', 'uppercase');
79+
test('with uppercase body should fail for "never uppercase"', async t => {
80+
const [actual] = bodyCase(await parsed.uppercase, 'never', 'uppercase');
8181
const expected = false;
8282
t.is(actual, expected);
8383
});
8484

85-
test('with lowercase body should succeed for "always uppercase"', t => {
86-
const [actual] = bodyCase(parsed.uppercase, 'always', 'uppercase');
85+
test('with lowercase body should succeed for "always uppercase"', async t => {
86+
const [actual] = bodyCase(await parsed.uppercase, 'always', 'uppercase');
8787
const expected = true;
8888
t.is(actual, expected);
8989
});

@commitlint/core/src/rules/body-empty.test.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,38 +12,38 @@ const parsed = {
1212
filled: parse(messages.filled)
1313
};
1414

15-
test('with empty body should succeed for empty keyword', t => {
16-
const [actual] = bodyEmpty(parsed.empty);
15+
test('with empty body should succeed for empty keyword', async t => {
16+
const [actual] = bodyEmpty(await parsed.empty);
1717
const expected = true;
1818
t.is(actual, expected);
1919
});
2020

21-
test('with empty body should fail for "never"', t => {
22-
const [actual] = bodyEmpty(parsed.empty, 'never');
21+
test('with empty body should fail for "never"', async t => {
22+
const [actual] = bodyEmpty(await parsed.empty, 'never');
2323
const expected = false;
2424
t.is(actual, expected);
2525
});
2626

27-
test('with empty body should succeed for "always"', t => {
28-
const [actual] = bodyEmpty(parsed.empty, 'always');
27+
test('with empty body should succeed for "always"', async t => {
28+
const [actual] = bodyEmpty(await parsed.empty, 'always');
2929
const expected = true;
3030
t.is(actual, expected);
3131
});
3232

33-
test('with body should fail for empty keyword', t => {
34-
const [actual] = bodyEmpty(parsed.filled);
33+
test('with body should fail for empty keyword', async t => {
34+
const [actual] = bodyEmpty(await parsed.filled);
3535
const expected = false;
3636
t.is(actual, expected);
3737
});
3838

39-
test('with body should succeed for "never"', t => {
40-
const [actual] = bodyEmpty(parsed.filled, 'never');
39+
test('with body should succeed for "never"', async t => {
40+
const [actual] = bodyEmpty(await parsed.filled, 'never');
4141
const expected = true;
4242
t.is(actual, expected);
4343
});
4444

45-
test('with body should fail for "always"', t => {
46-
const [actual] = bodyEmpty(parsed.filled, 'always');
45+
test('with body should fail for "always"', async t => {
46+
const [actual] = bodyEmpty(await parsed.filled, 'always');
4747
const expected = false;
4848
t.is(actual, expected);
4949
});

0 commit comments

Comments
 (0)