Skip to content

Commit 8d7955a

Browse files
committed
Include the LintCommit configuration in IConfig
This way, the maximal number of columns can be configured freely per project, via the project-specific config. To reduce friction for on-boarding new projects by not having to look in multiple locations when creating a config file, the definition of the `ILintCommitConfig` interface is moved to `project-config.ts`, where all the other project-specific interfaces live already. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
1 parent fe54a84 commit 8d7955a

4 files changed

Lines changed: 11 additions & 8 deletions

File tree

lib/ci-helper.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1037,7 +1037,7 @@ export class CIHelper {
10371037

10381038
if (result) {
10391039
const results = commits.map((commit: IPRCommit) => {
1040-
const linter = new LintCommit(commit);
1040+
const linter = new LintCommit(commit, this.config.lint.commitLintOptions);
10411041
return linter.lint();
10421042
});
10431043

lib/commit-lint.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
import { IPRCommit } from "./github-glue.js";
2+
import { ILintCommitConfig } from "./project-config.js";
23

34
export interface ILintError {
45
checkFailed: boolean; // true if check failed
56
message: string;
67
}
78

8-
export interface ILintOptions {
9-
maxColumns?: number | undefined; // max line length
10-
}
11-
129
/*
1310
* Simple single use class to drive lint tests on commit messages.
1411
*/
@@ -19,7 +16,7 @@ export class LintCommit {
1916
private messages: string[] = [];
2017
private maxColumns = 76;
2118

22-
public constructor(patch: IPRCommit, options?: ILintOptions) {
19+
public constructor(patch: IPRCommit, options?: ILintCommitConfig) {
2320
this.blocked = false;
2421
this.lines = patch.message.split("\n");
2522
this.patch = patch;

lib/project-config.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,14 @@ export interface IAppConfig {
4848
altname: string | undefined; // is this even needed?
4949
}
5050

51+
export interface ILintCommitConfig {
52+
maxColumns?: number | undefined; // max line length
53+
}
54+
5155
export interface ILintConfig {
5256
maxCommitsIgnore?: string[]; // array of pull request urls to skip check
5357
maxCommits: number; // limit on number of commits in a pull request
58+
commitLintOptions?: ILintCommitConfig; // options to pass to commit linter
5459
}
5560

5661
export interface IUserConfig {

tests/commit-lint.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { expect, jest, test } from "@jest/globals";
2-
import { ILintError, ILintOptions, LintCommit } from "../lib/commit-lint.js";
2+
import { ILintError, LintCommit } from "../lib/commit-lint.js";
33
import { IPRCommit } from "../lib/github-glue.js";
4+
import { ILintCommitConfig } from "../lib/project-config.js";
45

56
jest.setTimeout(180000);
67

@@ -15,7 +16,7 @@ jest.setTimeout(180000);
1516
* @param check a function to verify the lint result
1617
* @param options extra linter options, if any
1718
*/
18-
function lintCheck(commit: IPRCommit, check?: (error: ILintError) => void, options?: ILintOptions) {
19+
function lintCheck(commit: IPRCommit, check?: (error: ILintError) => void, options?: ILintCommitConfig) {
1920
const linter = new LintCommit(commit, options);
2021
const lintError = linter.lint();
2122
if (!check) {

0 commit comments

Comments
 (0)