-
Notifications
You must be signed in to change notification settings - Fork 905
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): Implement footer-contains rules
- Loading branch information
Showing
5 changed files
with
80 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,9 @@ | ||
export default (value, regex) => { | ||
if (value === undefined) { | ||
return false; | ||
} | ||
if (!regex instanceof RegExp) { | ||
return false; | ||
} | ||
return regex.test(value); | ||
}; |
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,17 @@ | ||
import test from 'ava'; | ||
import ensure from './ensure-contains'; | ||
|
||
test('false for no params', t => { | ||
const actual = ensure(); | ||
t.is(actual, false); | ||
}); | ||
|
||
test('true for /^foo/gi against foo', t => { | ||
const actual = ensure('foo', /^foo/gi); | ||
t.is(actual, true); | ||
}); | ||
|
||
test('false for /^foo/gi against notfoo', t => { | ||
const actual = ensure('notfoo', /^foo/gi); | ||
t.is(actual, false); | ||
}); |
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,20 @@ | ||
import ensureContains from '../library/ensure-contains'; | ||
import message from '../library/message'; | ||
|
||
export default (parsed, when, value) => { | ||
if (!parsed.scope) { | ||
return [true, '']; | ||
} | ||
|
||
const negated = when === 'never'; | ||
const result = value.length === 0 || ensureContains(parsed.scope, value); | ||
|
||
return [ | ||
negated ? !result : result, | ||
message([ | ||
`footer content must`, | ||
negated ? `not` : null, | ||
`pass the regular expression: ${value.toString()}` | ||
]) | ||
]; | ||
}; |
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,33 @@ | ||
import test from 'ava'; | ||
import parse from '../library/parse'; | ||
import footerContains from './footer-contains'; | ||
|
||
const messages = { | ||
empty: 'foo(bar): baz', | ||
matched: 'foo(bar): baz\n\nbody\n\nqux', | ||
unmatched: 'foo(bar): baz\n\nbody\n\nquux' | ||
}; | ||
|
||
const parsed = { | ||
empty: parse(messages.empty), | ||
matched: parse(messages.matched), | ||
unmatched: parse(messages.unmatched) | ||
}; | ||
|
||
test('footer-contains with no footer should not succeed', async t => { | ||
const [actual] = footerContains(await parsed.empty, 'always', []); | ||
const expected = false; | ||
t.deepEqual(actual, expected); | ||
}); | ||
|
||
test('footer-contains with matching footer should succeed', async t => { | ||
const [actual] = footerContains(await parsed.matched, 'never', []); | ||
const expected = true; | ||
t.deepEqual(actual, expected); | ||
}); | ||
|
||
test('footer-contains with non-matching footer should not succeed', async t => { | ||
const [actual] = footerContains(await parsed.unmatched, 'never', []); | ||
const expected = false; | ||
t.deepEqual(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