-
Notifications
You must be signed in to change notification settings - Fork 913
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(rules): add body-full-stop rule (#2144)
- Loading branch information
1 parent
00e9241
commit 7767ca2
Showing
5 changed files
with
85 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import parse from '@commitlint/parse'; | ||
import {bodyFullStop} from './body-full-stop'; | ||
|
||
const messages = { | ||
empty: 'test:\n', | ||
with: `test: subject\n\nbody.`, | ||
without: `test: subject\n\nbody`, | ||
}; | ||
|
||
const parsed = { | ||
empty: parse(messages.empty), | ||
with: parse(messages.with), | ||
without: parse(messages.without), | ||
}; | ||
|
||
test('empty against "always" should succeed', async () => { | ||
const [actual] = bodyFullStop(await parsed.empty, 'always', '.'); | ||
const expected = true; | ||
expect(actual).toEqual(expected); | ||
}); | ||
|
||
test('empty against "never ." should succeed', async () => { | ||
const [actual] = bodyFullStop(await parsed.empty, 'never', '.'); | ||
const expected = true; | ||
expect(actual).toEqual(expected); | ||
}); | ||
|
||
test('with against "always ." should succeed', async () => { | ||
const [actual] = bodyFullStop(await parsed.with, 'always', '.'); | ||
const expected = true; | ||
expect(actual).toEqual(expected); | ||
}); | ||
|
||
test('with against "never ." should fail', async () => { | ||
const [actual] = bodyFullStop(await parsed.with, 'never', '.'); | ||
const expected = false; | ||
expect(actual).toEqual(expected); | ||
}); | ||
|
||
test('without against "always ." should fail', async () => { | ||
const [actual] = bodyFullStop(await parsed.without, 'always', '.'); | ||
const expected = false; | ||
expect(actual).toEqual(expected); | ||
}); | ||
|
||
test('without against "never ." should succeed', async () => { | ||
const [actual] = bodyFullStop(await parsed.without, 'never', '.'); | ||
const expected = true; | ||
expect(actual).toEqual(expected); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import message from '@commitlint/message'; | ||
import {SyncRule} from '@commitlint/types'; | ||
|
||
export const bodyFullStop: SyncRule<string> = ( | ||
parsed, | ||
when = 'always', | ||
value = '.' | ||
) => { | ||
const input = parsed.body; | ||
|
||
if (!input) { | ||
return [true]; | ||
} | ||
|
||
const negated = when === 'never'; | ||
const hasStop = input[input.length - 1] === value; | ||
|
||
return [ | ||
negated ? !hasStop : hasStop, | ||
message(['body', negated ? 'may not' : 'must', 'end with full stop']), | ||
]; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters