-
Notifications
You must be signed in to change notification settings - Fork 915
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(rules): create header-full-stop rule
This is a simplified version of the subject-full-stop rule. Headers are always present, so we don’t need to check for empty-ness. If headers are not defined, the parser will throw with an error “expecting raw commit”.
- Loading branch information
Showing
3 changed files
with
50 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,12 @@ | ||
import message from '@commitlint/message'; | ||
|
||
export default (parsed, when, value) => { | ||
const {header} = parsed; | ||
const negated = when === 'never'; | ||
const hasStop = header[header.length - 1] === value; | ||
|
||
return [ | ||
negated ? !hasStop : hasStop, | ||
message(['header', 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import test from 'ava'; | ||
import parse from '@commitlint/parse'; | ||
import check from './header-full-stop'; | ||
|
||
const messages = { | ||
with: `header.\n`, | ||
without: `header\n` | ||
}; | ||
|
||
const parsed = { | ||
with: parse(messages.with), | ||
without: parse(messages.without) | ||
}; | ||
|
||
test('with against "always ." should succeed', async t => { | ||
const [actual] = check(await parsed.with, 'always', '.'); | ||
const expected = true; | ||
t.is(actual, expected); | ||
}); | ||
|
||
test('with against "never ." should fail', async t => { | ||
const [actual] = check(await parsed.with, 'never', '.'); | ||
const expected = false; | ||
t.is(actual, expected); | ||
}); | ||
|
||
test('without against "always ." should fail', async t => { | ||
const [actual] = check(await parsed.without, 'always', '.'); | ||
const expected = false; | ||
t.is(actual, expected); | ||
}); | ||
|
||
test('without against "never ." should succeed', async t => { | ||
const [actual] = check(await parsed.without, 'never', '.'); | ||
const expected = true; | ||
t.is(actual, 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