💄 cleanup git input validation rules

#60407
This commit is contained in:
Joao Moreno 2019-01-04 17:03:11 +01:00
parent e6878ce54f
commit 2f82209adf
3 changed files with 38 additions and 16 deletions

View file

@ -1173,18 +1173,16 @@
},
"git.inputValidationLength": {
"type": "number",
"default": 50,
"default": 72,
"description": "%config.inputValidationLength%"
},
"git.subjectValidationLength": {
"type": "number",
"default": 50,
"description": "%config.subjectValidationLength%"
},
"git.bodyValidationLength": {
"type": "number",
"default": 72,
"description": "%config.bodyValidationLength%"
"git.inputValidationSubjectLength": {
"type": [
"number",
"null"
],
"default": null,
"description": "%config.inputValidationSubjectLength%"
},
"git.detectSubmodules": {
"type": "boolean",

View file

@ -98,8 +98,7 @@
"config.showPushSuccessNotification": "Controls whether to show a notification when a push is successful.",
"config.inputValidation": "Controls when to show commit message input validation.",
"config.inputValidationLength": "Controls the commit message length threshold for showing a warning.",
"config.subjectValidationLength": "Controls the commit message subject length threshold for showing a warning.",
"config.bodyValidationLength": "Controls the commit message body length threshold for showing a warning.",
"config.inputValidationSubjectLength": "Controls the commit message subject length threshold for showing a warning. Unset it to inherit the value of `config.inputValidationLength`.",
"config.detectSubmodules": "Controls whether to automatically detect git submodules.",
"config.detectSubmodulesLimit": "Controls the limit of git submodules detected.",
"config.alwaysShowStagedChangesResourceGroup": "Always show the Staged Changes resource group.",

View file

@ -647,31 +647,56 @@ export class Repository implements Disposable {
};
}
let lineNumber = 0;
let start = 0, end;
let match: RegExpExecArray | null;
const regex = /\r?\n/g;
while ((match = regex.exec(text)) && position > match.index) {
start = match.index + match[0].length;
lineNumber++;
}
end = match ? match.index : text.length;
const line = text.substring(start, end);
const subjectThreshold = Math.max(config.get<number>('inputValidationLength') || 50, config.get<number>('subjectValidationLength') || 50, 0) || 50;
if (line.length <= subjectThreshold) {
let threshold = config.get<number>('inputValidationLength', 50);
if (lineNumber === 0) {
const inputValidationSubjectLength = config.get<number | null>('inputValidationSubjectLength', null);
if (inputValidationSubjectLength !== null) {
threshold = inputValidationSubjectLength;
}
}
// const subjectThreshold =
// Math.max(config.get<number>('inputValidationLength') || 50, config.get<number>('subjectValidationLength') || 50, 0) || 50;
if (line.length <= threshold) {
if (setting !== 'always') {
return;
}
return {
message: localize('commitMessageCountdown', "{0} characters left in current line", subjectThreshold - line.length),
message: localize('commitMessageCountdown', "{0} characters left in current line", threshold - line.length),
type: SourceControlInputBoxValidationType.Information
};
} else {
return {
message: localize('commitMessageWarning', "{0} characters over {1} in current line", line.length - subjectThreshold, subjectThreshold),
message: localize('commitMessageWarning', "{0} characters over {1} in current line", line.length - threshold, threshold),
type: SourceControlInputBoxValidationType.Warning
};
}