-
Notifications
You must be signed in to change notification settings - Fork 917
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(config-conventional): footer/body-max-line
update config-conventional with all the configurations add footer and body max line length rule with the value 100 add tests to all the rules of config-conventional
- Loading branch information
Showing
4 changed files
with
325 additions
and
3 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,214 @@ | ||
import test from 'ava'; | ||
import lint from '@commitlint/lint'; | ||
import {rules} from '.'; | ||
|
||
const messages = { | ||
invalidTypeEnum: 'foo: some message', | ||
invalidTypeCase: 'FIX: some message', | ||
invalidTypeEmpty: ': some message', | ||
invalidScopeCase: 'fix(SCOPE): some message', | ||
invalidSubjectCases: [ | ||
'fix(scope): Some message', | ||
'fix(scope): Some Message', | ||
'fix(scope): SomeMessage', | ||
'fix(scope): SOMEMESSAGE' | ||
], | ||
invalidSubjectEmpty: 'fix:', | ||
invalidSubjectFullStop: 'fix: some message.', | ||
invalidHeaderMaxLength: | ||
'fix: some message that is way too long and breaks the line max-length by several characters', | ||
warningFooterLeadingBlank: | ||
'fix: some message\n\nbody\nBREAKING CHANGE: It will be significant', | ||
invalidFooterMaxLineLength: | ||
'fix: some message\n\nbody\n\nBREAKING CHANGE: footer with multiple lines\nhas a message that is way too long and will break the line rule "line-max-length" by several characters', | ||
warningBodyLeadingBlank: 'fix: some message\nbody', | ||
invalidBodyMaxLineLength: | ||
'fix: some message\n\nbody with multiple lines\nhas a message that is way too long and will break the line rule "line-max-length" by several characters', | ||
validMessages: [ | ||
'fix: some message', | ||
'fix(scope): some message', | ||
'fix(scope): some Message', | ||
'fix(scope): some message\n\nBREAKING CHANGE: it will be significant!', | ||
'fix(scope): some message\n\nbody' | ||
] | ||
}; | ||
|
||
const errors = { | ||
typeEnum: { | ||
level: 2, | ||
message: | ||
'type must be one of [build, chore, ci, docs, feat, fix, perf, refactor, revert, style, test]', | ||
name: 'type-enum', | ||
valid: false | ||
}, | ||
typeCase: { | ||
level: 2, | ||
message: 'type must be lower-case', | ||
name: 'type-case', | ||
valid: false | ||
}, | ||
typeEmpty: { | ||
level: 2, | ||
message: 'type may not be empty', | ||
name: 'type-empty', | ||
valid: false | ||
}, | ||
scopeCase: { | ||
level: 2, | ||
message: 'scope must be lower-case', | ||
name: 'scope-case', | ||
valid: false | ||
}, | ||
subjectCase: { | ||
level: 2, | ||
message: | ||
'subject must not be sentence-case, start-case, pascal-case, upper-case', | ||
name: 'subject-case', | ||
valid: false | ||
}, | ||
subjectEmpty: { | ||
level: 2, | ||
message: 'message may not be empty', | ||
name: 'subject-empty', | ||
valid: false | ||
}, | ||
subjectFullStop: { | ||
level: 2, | ||
message: 'message may not end with full stop', | ||
name: 'subject-full-stop', | ||
valid: false | ||
}, | ||
headerMaxLength: { | ||
level: 2, | ||
message: 'header must not be longer than 72 characters', | ||
name: 'header-max-length', | ||
valid: false | ||
}, | ||
footerMaxLineLength: { | ||
level: 2, | ||
message: "footer's lines must not be longer than 100 characters", | ||
name: 'footer-max-line-length', | ||
valid: false | ||
}, | ||
bodyMaxLineLength: { | ||
level: 2, | ||
message: "body's lines must not be longer than 100 characters", | ||
name: 'body-max-line-length', | ||
valid: false | ||
} | ||
}; | ||
|
||
const warnings = { | ||
footerLeadingBlank: { | ||
level: 1, | ||
message: 'footer must have leading blank line', | ||
name: 'footer-leading-blank', | ||
valid: false | ||
}, | ||
bodyLeadingBlank: { | ||
level: 1, | ||
message: 'body must have leading blank line', | ||
name: 'body-leading-blank', | ||
valid: false | ||
} | ||
}; | ||
|
||
test('type-enum', async t => { | ||
const result = await lint(messages.invalidTypeEnum, rules); | ||
|
||
t.is(result.valid, false); | ||
t.deepEqual(result.errors, [errors.typeEnum]); | ||
}); | ||
|
||
test('type-case', async t => { | ||
const result = await lint(messages.invalidTypeCase, rules); | ||
|
||
t.is(result.valid, false); | ||
t.deepEqual(result.errors, [errors.typeCase, errors.typeEnum]); | ||
}); | ||
|
||
test('type-empty', async t => { | ||
const result = await lint(messages.invalidTypeEmpty, rules); | ||
|
||
t.is(result.valid, false); | ||
t.deepEqual(result.errors, [errors.typeEmpty]); | ||
}); | ||
|
||
test('scope-case', async t => { | ||
const result = await lint(messages.invalidScopeCase, rules); | ||
|
||
t.is(result.valid, false); | ||
t.deepEqual(result.errors, [errors.scopeCase]); | ||
}); | ||
|
||
test('subject-case', async t => { | ||
const invalidInputs = await Promise.all( | ||
messages.invalidSubjectCases.map(invalidInput => lint(invalidInput, rules)) | ||
); | ||
|
||
invalidInputs.forEach(result => { | ||
t.is(result.valid, false); | ||
t.deepEqual(result.errors, [errors.subjectCase]); | ||
}); | ||
}); | ||
|
||
test('subject-empty', async t => { | ||
const result = await lint(messages.invalidSubjectEmpty, rules); | ||
|
||
t.is(result.valid, false); | ||
t.deepEqual(result.errors, [errors.subjectEmpty, errors.typeEmpty]); | ||
}); | ||
|
||
test('subject-full-stop', async t => { | ||
const result = await lint(messages.invalidSubjectFullStop, rules); | ||
|
||
t.is(result.valid, false); | ||
t.deepEqual(result.errors, [errors.subjectFullStop]); | ||
}); | ||
|
||
test('header-max-length', async t => { | ||
const result = await lint(messages.invalidHeaderMaxLength, rules); | ||
|
||
t.is(result.valid, false); | ||
t.deepEqual(result.errors, [errors.headerMaxLength]); | ||
}); | ||
|
||
test('footer-leading-blank', async t => { | ||
const result = await lint(messages.warningFooterLeadingBlank, rules); | ||
|
||
t.is(result.valid, true); | ||
t.deepEqual(result.warnings, [warnings.footerLeadingBlank]); | ||
}); | ||
|
||
test('footer-max-line-length', async t => { | ||
const result = await lint(messages.invalidFooterMaxLineLength, rules); | ||
|
||
t.is(result.valid, false); | ||
t.deepEqual(result.errors, [errors.footerMaxLineLength]); | ||
}); | ||
|
||
test('body-leading-blank', async t => { | ||
const result = await lint(messages.warningBodyLeadingBlank, rules); | ||
|
||
t.is(result.valid, true); | ||
t.deepEqual(result.warnings, [warnings.bodyLeadingBlank]); | ||
}); | ||
|
||
test('body-max-line-length', async t => { | ||
const result = await lint(messages.invalidBodyMaxLineLength, rules); | ||
|
||
t.is(result.valid, false); | ||
t.deepEqual(result.errors, [errors.bodyMaxLineLength]); | ||
}); | ||
|
||
test('valid messages', async t => { | ||
const validInputs = await Promise.all( | ||
messages.validMessages.map(input => lint(input, rules)) | ||
); | ||
|
||
validInputs.forEach(result => { | ||
t.is(result.valid, true); | ||
t.deepEqual(result.errors, []); | ||
t.deepEqual(result.warnings, []); | ||
}); | ||
}); |
Oops, something went wrong.