-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make max length of lines configurable (#96)
The line limit is great for strict terminal use and some GUIs, but for teams that use only UIs such as GitHub Web it is an unnecessary restriction. This commit adds options to make this configurable. Signed-off-by: Luiz Ferraz <[email protected]> Co-authored-by: Marko Ristin <[email protected]>
- Loading branch information
Showing
8 changed files
with
200 additions
and
31 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
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 |
---|---|---|
|
@@ -2,7 +2,7 @@ import * as input from '../input'; | |
import * as inspection from '../inspection'; | ||
|
||
const defaultInputs: input.Inputs = input | ||
.parseInputs('', '', '', '', '') | ||
.parseInputs('', '', '', '', '', '', '') | ||
.mustInputs(); | ||
|
||
it('reports no errors on correct multi-line message.', () => { | ||
|
@@ -28,7 +28,7 @@ it('reports no errors on OK multi-line message with allowed one-liners.', () => | |
}); | ||
|
||
it('reports no errors on OK single-line message with allowed one-liners.', () => { | ||
const inputs = input.parseInputs('', '', 'true', '', '').mustInputs(); | ||
const inputs = input.parseInputs('', '', 'true', '', '', '', '').mustInputs(); | ||
|
||
const message = 'Change SomeClass to OtherClass'; | ||
|
||
|
@@ -63,12 +63,14 @@ it('reports no errors on any message when body check is disabled.', () => { | |
'since Some class was deprecated. This is long message should not ' + | ||
'be checked.'; | ||
|
||
const inputCheckingBody = input.parseInputs('', '', '', '', '').mustInputs(); | ||
const inputCheckingBody = input | ||
.parseInputs('', '', '', '', '', '', '') | ||
.mustInputs(); | ||
|
||
expect(inspection.check(message, inputCheckingBody)).not.toEqual([]); | ||
|
||
const inputNotCheckingBody = input | ||
.parseInputs('', '', '', '', 'true') | ||
.parseInputs('', '', '', '', '', '', 'true') | ||
.mustInputs(); | ||
|
||
expect(inspection.check(message, inputNotCheckingBody)).toEqual([]); | ||
|
@@ -81,7 +83,7 @@ it('reports missing body with disallowed one-liners.', () => { | |
}); | ||
|
||
it('reports missing body with allowed one-liners.', () => { | ||
const inputs = input.parseInputs('', '', 'true', '', '').mustInputs(); | ||
const inputs = input.parseInputs('', '', 'true', '', '', '', '').mustInputs(); | ||
|
||
const message = 'Change SomeClass to OtherClass\n'; | ||
const errors = inspection.check(message, inputs); | ||
|
@@ -167,7 +169,9 @@ it( | |
'reports the subject starting with a non-verb ' + | ||
'with additional verbs given as direct input.', | ||
() => { | ||
const inputs = input.parseInputs('table', '', 'false', '', '').mustInputs(); | ||
const inputs = input | ||
.parseInputs('table', '', 'false', '', '', '', '') | ||
.mustInputs(); | ||
|
||
const message = | ||
'Replaced SomeClass to OtherClass\n' + | ||
|
@@ -205,6 +209,8 @@ it( | |
'/some/path', | ||
false, | ||
new Set<string>('table'), | ||
50, | ||
72, | ||
false, | ||
false | ||
); | ||
|
@@ -237,7 +243,9 @@ it( | |
); | ||
|
||
it('accepts the subject starting with an additional verb.', () => { | ||
const inputs = input.parseInputs('table', '', 'false', '', '').mustInputs(); | ||
const inputs = input | ||
.parseInputs('table', '', 'false', '', '', '', '') | ||
.mustInputs(); | ||
|
||
const message = 'Table that for me\n\nThis is a dummy commit.'; | ||
const errors = inspection.check(message, inputs); | ||
|
@@ -259,7 +267,7 @@ it('reports the subject ending in a dot.', () => { | |
}); | ||
|
||
it('reports an incorrect one-line message with allowed one-liners.', () => { | ||
const inputs = input.parseInputs('', '', 'true', '', '').mustInputs(); | ||
const inputs = input.parseInputs('', '', 'true', '', '', '', '').mustInputs(); | ||
|
||
const message = 'Change SomeClass to OtherClass.'; | ||
|
||
|
@@ -270,6 +278,38 @@ it('reports an incorrect one-line message with allowed one-liners.', () => { | |
]); | ||
}); | ||
|
||
it('reports too long a subject line.', () => { | ||
const message = | ||
'Change SomeClass to OtherClass in order to handle upstream deprecation\n' + | ||
'\n' + | ||
'This replaces the SomeClass with OtherClass in all of the module\n' + | ||
'since Some class was deprecated.'; | ||
|
||
const errors = inspection.check(message, defaultInputs); | ||
expect(errors).toEqual([ | ||
`The subject exceeds the limit of 50 characters ` + | ||
`(got: 70, JSON: "Change SomeClass to OtherClass in order to handle upstream deprecation").` + | ||
'Please shorten the subject to make it more succinct.' | ||
]); | ||
}); | ||
|
||
it('reports too long a subject line with custom max length.', () => { | ||
const message = | ||
'Change SomeClass to OtherClass in order to handle upstream deprecation\n' + | ||
'\n' + | ||
'This replaces the SomeClass with OtherClass in all of the module\n' + | ||
'since Some class was deprecated.'; | ||
|
||
const inputs = input.parseInputs('', '', '', '60', '', '', '').mustInputs(); | ||
|
||
const errors = inspection.check(message, inputs); | ||
expect(errors).toEqual([ | ||
`The subject exceeds the limit of 60 characters ` + | ||
`(got: 70, JSON: "Change SomeClass to OtherClass in order to handle upstream deprecation").` + | ||
'Please shorten the subject to make it more succinct.' | ||
]); | ||
}); | ||
|
||
it('reports too long a body line.', () => { | ||
const message = | ||
'Change SomeClass to OtherClass\n' + | ||
|
@@ -287,6 +327,25 @@ it('reports too long a body line.', () => { | |
]); | ||
}); | ||
|
||
it('reports too long a body line with custom max length.', () => { | ||
const message = | ||
'Change SomeClass to OtherClass\n' + | ||
'\n' + | ||
'This replaces the SomeClass with OtherClass in all of the module ' + | ||
'since Some class was deprecated.'; | ||
|
||
const inputs = input.parseInputs('', '', '', '', '90', '', '').mustInputs(); | ||
|
||
const errors = inspection.check(message, inputs); | ||
expect(errors).toEqual([ | ||
'The line 3 of the message (line 1 of the body) exceeds the limit of ' + | ||
'90 characters. The line contains 97 characters: ' + | ||
'"This replaces the SomeClass with OtherClass in all of the module since ' + | ||
'Some class was deprecated.". ' + | ||
'Please reformat the body so that all the lines fit 90 characters.' | ||
]); | ||
}); | ||
|
||
it('accepts a body line of exactly 72 characters.', () => { | ||
const message = | ||
'Do something\n' + | ||
|
@@ -434,7 +493,7 @@ The ${long} line is too long.`; | |
}); | ||
|
||
it('accepts the valid body when enforcing the sign-off.', () => { | ||
const inputs = input.parseInputs('', '', '', 'true', '').mustInputs(); | ||
const inputs = input.parseInputs('', '', '', '', '', 'true', '').mustInputs(); | ||
|
||
const message = `Do something | ||
|
@@ -453,7 +512,7 @@ Signed-off-by: Somebody Else <[email protected]> | |
}); | ||
|
||
it('rejects invalid sign-offs.', () => { | ||
const inputs = input.parseInputs('', '', '', 'true', '').mustInputs(); | ||
const inputs = input.parseInputs('', '', '', '', '', 'true', '').mustInputs(); | ||
|
||
const message = `Do something | ||
|
Oops, something went wrong.