diff --git a/@commitlint/ensure/src/index.test.js b/@commitlint/ensure/src/index.test.js index 4ea978e7fe..392279a4df 100644 --- a/@commitlint/ensure/src/index.test.js +++ b/@commitlint/ensure/src/index.test.js @@ -4,9 +4,9 @@ import globby from 'globby'; import {camelCase, values} from 'lodash'; import * as ensure from '.'; -test('exports all rules', async t => { - const expected = (await glob('*.js')).map(f => camelCase(f)); - const actual = Object.keys(ensure); +test('exports all checkers', async t => { + const expected = (await glob('*.js')).map(f => camelCase(f)).sort(); + const actual = Object.keys(ensure).sort(); t.deepEqual(actual, expected); }); diff --git a/@commitlint/parse/package.json b/@commitlint/parse/package.json index 4123d88c53..d590314b6b 100644 --- a/@commitlint/parse/package.json +++ b/@commitlint/parse/package.json @@ -73,6 +73,7 @@ }, "dependencies": { "conventional-changelog-angular": "^1.3.3", - "conventional-commits-parser": "^2.1.0" + "conventional-commits-parser": "^2.1.0", + "lodash": "^4.17.11" } } diff --git a/@commitlint/parse/src/index.js b/@commitlint/parse/src/index.js index 0c71d40e2f..363e81a382 100644 --- a/@commitlint/parse/src/index.js +++ b/@commitlint/parse/src/index.js @@ -1,15 +1,12 @@ import {sync} from 'conventional-commits-parser'; import defaultChangelogOpts from 'conventional-changelog-angular'; +import {merge} from 'lodash'; export default parse; async function parse(message, parser = sync, parserOpts) { - if (!parserOpts || Object.keys(parserOpts || {}).length === 0) { - const changelogOpts = await defaultChangelogOpts; - parserOpts = changelogOpts.parserOpts; - } - - const parsed = parser(message, parserOpts); + const defaultOpts = (await defaultChangelogOpts).parserOpts; + const parsed = parser(message, merge({}, defaultOpts, parserOpts)); parsed.raw = message; return parsed; } diff --git a/@commitlint/parse/src/index.test.js b/@commitlint/parse/src/index.test.js index 78d7aa7d73..29d7e49c62 100644 --- a/@commitlint/parse/src/index.test.js +++ b/@commitlint/parse/src/index.test.js @@ -164,3 +164,45 @@ test('parses custom references', async t => { repository: null }); }); + +test('uses permissive default regex without parser opts', async t => { + const message = 'chore(component,demo): bump'; + const actual = await parse(message); + + t.is(actual.scope, 'component,demo'); +}); + +test('uses permissive default regex with other parser opts', async t => { + const message = 'chore(component,demo): bump'; + const actual = await parse(message, undefined, {commentChar: '#'}); + + t.is(actual.scope, 'component,demo'); +}); + +test('uses restrictive default regex in passed parser opts', async t => { + const message = 'chore(component,demo): bump'; + const actual = await parse(message, undefined, { + headerPattern: /^(\w*)(?:\(([a-z]*)\))?: (.*)$/ + }); + + t.is(actual.subject, null); + t.is(actual.scope, null); +}); + +test('works with chinese scope by default', async t => { + const message = 'fix(面试评价): 测试'; + const actual = await parse(message, undefined, {commentChar: '#'}); + + t.not(actual.subject, null); + t.not(actual.scope, null); +}); + +test('does not work with chinese scopes with incompatible pattern', async t => { + const message = 'fix(面试评价): 测试'; + const actual = await parse(message, undefined, { + headerPattern: /^(\w*)(?:\(([a-z]*)\))?: (.*)$/ + }); + + t.is(actual.subject, null); + t.is(actual.scope, null); +}); diff --git a/yarn.lock b/yarn.lock index 7f2c91a81b..9e285ff88a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5704,7 +5704,7 @@ lodash.zip@^4.2.0: version "4.2.0" resolved "https://registry.npmjs.org/lodash.zip/-/lodash.zip-4.2.0.tgz#ec6662e4896408ed4ab6c542a3990b72cc080020" -lodash@4.17.11, lodash@^3.3.1, lodash@^4.0.0, lodash@^4.13.1, lodash@^4.17.10, lodash@^4.17.4, lodash@^4.17.5, lodash@^4.2.1, lodash@^4.3.0, lodash@^4.5.1: +lodash@4.17.11, lodash@^3.3.1, lodash@^4.0.0, lodash@^4.13.1, lodash@^4.17.10, lodash@^4.17.11, lodash@^4.17.4, lodash@^4.17.5, lodash@^4.2.1, lodash@^4.3.0, lodash@^4.5.1: version "4.17.11" resolved "https://registry.npmjs.org/lodash/-/lodash-4.17.11.tgz#b39ea6229ef607ecd89e2c8df12536891cac9b8d" integrity sha512-cQKh8igo5QUhZ7lg38DYWAxMvjSAKG0A8wGSVimP07SIUEK2UO+arSRKbRZWtelMtN5V0Hkwh5ryOto/SshYIg== @@ -7352,7 +7352,6 @@ resolve-from@^3.0.0: resolve-from@^4.0.0: version "4.0.0" resolved "https://registry.npmjs.org/resolve-from/-/resolve-from-4.0.0.tgz#4abcd852ad32dd7baabfe9b40e00a36db5f392e6" - integrity sha512-pb/MYmXstAkysRFx8piNI1tGFNQIFA3vkE3Gq4EuA1dF6gHp/+vgZqsCGJapvy8N3Q+4o7FwvquPJcnZ7RYy4g== resolve-global@^0.1.0: version "0.1.0"