-
Notifications
You must be signed in to change notification settings - Fork 919
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add max line length to body/footer
- Loading branch information
Showing
9 changed files
with
214 additions
and
1 deletion.
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 |
---|---|---|
@@ -1,9 +1,10 @@ | ||
import ensureCase from './case'; | ||
import ensureEnum from './enum'; | ||
import maxLength from './max-length'; | ||
import maxLineLength from './max-line-length'; | ||
import minLength from './min-length'; | ||
import notEmpty from './not-empty'; | ||
|
||
export {ensureCase as case}; | ||
export {ensureEnum as enum}; | ||
export {maxLength, minLength, notEmpty}; | ||
export {maxLength, maxLineLength, minLength, notEmpty}; |
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,5 @@ | ||
import ensure from './max-length'; | ||
|
||
export default (value, max) => | ||
typeof value === 'string' && | ||
value.split(/\r?\n/).every(line => ensure(line, max)); |
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,49 @@ | ||
import test from 'ava'; | ||
import ensure from './max-line-length'; | ||
|
||
test('false for no params', t => { | ||
const actual = ensure(); | ||
t.is(actual, false); | ||
}); | ||
|
||
test('true for a against 1', t => { | ||
const actual = ensure('a', 1); | ||
t.is(actual, true); | ||
}); | ||
|
||
test('false for ab against 0', t => { | ||
const actual = ensure('a', 0); | ||
t.is(actual, false); | ||
}); | ||
|
||
test('true for a against 2', t => { | ||
const actual = ensure('a', 2); | ||
t.is(actual, true); | ||
}); | ||
|
||
test('true for ab against 2', t => { | ||
const actual = ensure('ab', 2); | ||
t.is(actual, true); | ||
}); | ||
|
||
test('false for ab/\nab/\nab 1', t => { | ||
const actual = ensure( | ||
`ab | ||
ab | ||
ab`, | ||
2 | ||
); | ||
|
||
t.is(actual, true); | ||
}); | ||
|
||
test('true for ab/\nab/\nab 2', t => { | ||
const actual = ensure( | ||
`ab | ||
ab | ||
ab`, | ||
2 | ||
); | ||
|
||
t.is(actual, true); | ||
}); |
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,14 @@ | ||
import {maxLineLength} from '@commitlint/ensure'; | ||
|
||
export default (parsed, when, value) => { | ||
const input = parsed.body; | ||
|
||
if (!input) { | ||
return [true]; | ||
} | ||
|
||
return [ | ||
maxLineLength(input, value), | ||
`body's lines must not be longer than ${value} 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import test from 'ava'; | ||
import parse from '@commitlint/parse'; | ||
import check from './body-max-line-length'; | ||
|
||
const short = 'a'; | ||
const long = 'ab'; | ||
|
||
const value = short.length; | ||
|
||
const messages = { | ||
empty: 'test: subject', | ||
short: `test: subject\n${short}`, | ||
long: `test: subject\n${long}`, | ||
shortMultipleLines: `test:subject\n${short}\n${short}\n${short}`, | ||
longMultipleLines: `test:subject\n${short}\n${long}\n${short}` | ||
}; | ||
|
||
const parsed = { | ||
empty: parse(messages.empty), | ||
short: parse(messages.short), | ||
long: parse(messages.long) | ||
}; | ||
|
||
test('with empty should succeed', async t => { | ||
const [actual] = check(await parsed.empty, '', value); | ||
const expected = true; | ||
t.is(actual, expected); | ||
}); | ||
|
||
test('with short should succeed', async t => { | ||
const [actual] = check(await parsed.short, '', value); | ||
const expected = true; | ||
t.is(actual, expected); | ||
}); | ||
|
||
test('with long should fail', async t => { | ||
const [actual] = check(await parsed.long, '', value); | ||
const expected = false; | ||
t.is(actual, expected); | ||
}); | ||
|
||
test('with short with multiple lines should succeed', async t => { | ||
const [actual] = check(await parsed.short, '', value); | ||
const expected = true; | ||
t.is(actual, expected); | ||
}); | ||
|
||
test('with long with multiple lines should fail', async t => { | ||
const [actual] = check(await parsed.long, '', value); | ||
const expected = false; | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import {maxLineLength} from '@commitlint/ensure'; | ||
|
||
export default (parsed, when, value) => { | ||
const input = parsed.footer; | ||
|
||
if (!input) { | ||
return [true]; | ||
} | ||
|
||
return [ | ||
maxLineLength(input, value), | ||
`footer's lines must not be longer than ${value} 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import test from 'ava'; | ||
import parse from '@commitlint/parse'; | ||
import check from './footer-max-line-length'; | ||
|
||
const short = 'BREAKING CHANGE: a'; | ||
const long = 'BREAKING CHANGE: ab'; | ||
|
||
const value = short.length; | ||
|
||
const messages = { | ||
simple: 'test: subject', | ||
empty: 'test: subject\nbody', | ||
short: `test: subject\n${short}`, | ||
long: `test: subject\n${long}`, | ||
shortMultipleLines: `test:subject\n${short}\n${short}\n${short}`, | ||
longMultipleLines: `test:subject\n${short}\n${long}\n${short}` | ||
}; | ||
|
||
const parsed = { | ||
simple: parse(messages.simple), | ||
empty: parse(messages.empty), | ||
short: parse(messages.short), | ||
long: parse(messages.long) | ||
}; | ||
|
||
test('with simple should succeed', async t => { | ||
const [actual] = check(await parsed.simple, '', value); | ||
const expected = true; | ||
t.is(actual, expected); | ||
}); | ||
|
||
test('with empty should succeed', async t => { | ||
const [actual] = check(await parsed.empty, '', value); | ||
const expected = true; | ||
t.is(actual, expected); | ||
}); | ||
|
||
test('with short should succeed', async t => { | ||
const [actual] = check(await parsed.short, '', value); | ||
const expected = true; | ||
t.is(actual, expected); | ||
}); | ||
|
||
test('with long should fail', async t => { | ||
const [actual] = check(await parsed.long, '', value); | ||
const expected = false; | ||
t.is(actual, expected); | ||
}); | ||
|
||
test('with short with multiple lines should succeed', async t => { | ||
const [actual] = check(await parsed.short, '', value); | ||
const expected = true; | ||
t.is(actual, expected); | ||
}); | ||
|
||
test('with long with multiple lines should fail', async t => { | ||
const [actual] = check(await parsed.long, '', value); | ||
const expected = false; | ||
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
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