diff --git a/@commitlint/rules/src/header-full-stop.js b/@commitlint/rules/src/header-full-stop.js index f30ce6d12c..1a7133f194 100644 --- a/@commitlint/rules/src/header-full-stop.js +++ b/@commitlint/rules/src/header-full-stop.js @@ -3,7 +3,9 @@ import message from '@commitlint/message'; export default (parsed, when, value) => { const {header} = parsed; const negated = when === 'never'; - const hasStop = header[header.length - 1] === value; + const stop = header[header.length - 1]; + const hasStop = + value.length > 1 ? new RegExp(value, 'u').test(stop) : stop === value; return [ negated ? !hasStop : hasStop, diff --git a/@commitlint/rules/src/header-full-stop.test.js b/@commitlint/rules/src/header-full-stop.test.js index 5b41da82e3..580e79789c 100644 --- a/@commitlint/rules/src/header-full-stop.test.js +++ b/@commitlint/rules/src/header-full-stop.test.js @@ -35,3 +35,27 @@ test('without against "never ." should succeed', async t => { const expected = true; t.is(actual, expected); }); + +test('with against "always [\\.0-9]" should succeed', async t => { + const [actual] = check(await parsed.with, 'always', '[\\.0-9]'); + const expected = true; + t.is(actual, expected); +}); + +test('with against "never [\\.0-9]" should fail', async t => { + const [actual] = check(await parsed.with, 'never', '[\\.0-9]'); + const expected = false; + t.is(actual, expected); +}); + +test('without against "always [\\.0-9]" should fail', async t => { + const [actual] = check(await parsed.without, 'always', '[\\.0-9]'); + const expected = false; + t.is(actual, expected); +}); + +test('without against "never [\\.0-9]" should succeed', async t => { + const [actual] = check(await parsed.without, 'never', '[\\.0-9]'); + const expected = true; + t.is(actual, expected); +}); diff --git a/@commitlint/rules/src/subject-full-stop.js b/@commitlint/rules/src/subject-full-stop.js index 010a8f4c54..d51cbaccc7 100644 --- a/@commitlint/rules/src/subject-full-stop.js +++ b/@commitlint/rules/src/subject-full-stop.js @@ -8,7 +8,9 @@ export default (parsed, when, value) => { } const negated = when === 'never'; - const hasStop = input[input.length - 1] === value; + const stop = input[input.length - 1]; + const hasStop = + value.length > 1 ? new RegExp(value, 'u').test(stop) : stop === value; return [ negated ? !hasStop : hasStop, diff --git a/@commitlint/rules/src/subject-full-stop.test.js b/@commitlint/rules/src/subject-full-stop.test.js index c86085b2ab..d44453e696 100644 --- a/@commitlint/rules/src/subject-full-stop.test.js +++ b/@commitlint/rules/src/subject-full-stop.test.js @@ -49,3 +49,27 @@ test('without against "never ." should succeed', async t => { const expected = true; t.is(actual, expected); }); + +test('with against "always [\\.0-9]" should succeed', async t => { + const [actual] = check(await parsed.with, 'always', '[\\.0-9]'); + const expected = true; + t.is(actual, expected); +}); + +test('with against "never [\\.0-9]" should fail', async t => { + const [actual] = check(await parsed.with, 'never', '[\\.0-9]'); + const expected = false; + t.is(actual, expected); +}); + +test('without against "always [\\.0-9]" should fail', async t => { + const [actual] = check(await parsed.without, 'always', '[\\.0-9]'); + const expected = false; + t.is(actual, expected); +}); + +test('without against "never [\\.0-9]" should succeed', async t => { + const [actual] = check(await parsed.without, 'never', '[\\.0-9]'); + const expected = true; + t.is(actual, expected); +}); diff --git a/docs/reference-rules.md b/docs/reference-rules.md index 90529a748c..fe272f132a 100644 --- a/docs/reference-rules.md +++ b/docs/reference-rules.md @@ -111,11 +111,12 @@ Rule configurations are either of type `array` residing on a key with the rule's ``` #### header-full-stop -* **condition**: `header` ends with `value` +* **condition**: `header` ends with `value` or `header`'s last character matches `value` string regexp * **rule**: `never` -* **value** +* **possible values** ```js - '.' + '.' // default + '[\\.0-9]' // any string regexp to match with last character ``` #### header-max-length @@ -211,11 +212,12 @@ Rule configurations are either of type `array` residing on a key with the rule's * **rule**: `never` #### subject-full-stop -* **condition**: `subject` ends with `value` +* **condition**: `subject` ends with `value` or `subject`'s last character matches `value` string regexp * **rule**: `never` -* **value** +* **possible values** ```js - '.' + '.' // default + '[\\.0-9]' // any string regexp to match with last character ``` #### subject-max-length