Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 10 additions & 18 deletions @commitlint/rules/src/header-trim.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,19 @@ import { SyncRule } from "@commitlint/types";
export const headerTrim: SyncRule = (parsed) => {
const { header } = parsed;

if (!header) {
return [true];
}
if (!header) return [true];

const startsWithWhiteSpace = header !== header.trimStart();
const endsWithWhiteSpace = header !== header.trimEnd();
const startsWithWhiteSpace = header.length > header.trimStart().length;
const endsWithWhiteSpace = header.length > header.trimEnd().length;

switch (true) {
case startsWithWhiteSpace && endsWithWhiteSpace:
return [
false,
message(["header", "must not be surrounded by whitespace"]),
];
if (startsWithWhiteSpace && endsWithWhiteSpace)
return [false, message(["header", "must not be surrounded by whitespace"])];

case startsWithWhiteSpace:
return [false, message(["header", "must not start with whitespace"])];
if (startsWithWhiteSpace)
return [false, message(["header", "must not start with whitespace"])];

case endsWithWhiteSpace:
return [false, message(["header", "must not end with whitespace"])];
if (endsWithWhiteSpace)
return [false, message(["header", "must not end with whitespace"])];

default:
return [true];
}
return [true];
};