Skip to content

Commit eb29b87

Browse files
authored
Merge pull request gitgitgadget#1790 from dscho/fix-lint-warnings
Fix many ESLint warnings/errors
2 parents 2650ab1 + d162073 commit eb29b87

28 files changed

+807
-490
lines changed

lib/ci-helper.ts

Lines changed: 112 additions & 60 deletions
Large diffs are not rendered by default.

lib/commit-lint.ts

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { IPRCommit } from "./github-glue.js";
22

33
export interface ILintError {
4-
checkFailed: boolean; // true if check failed
4+
checkFailed: boolean; // true if check failed
55
message: string;
66
}
77

@@ -35,38 +35,45 @@ export class LintCommit {
3535
* Linter method to run checks on the commit message.
3636
*/
3737
public lint(): ILintError | void {
38-
const phase1 = [
39-
this.commitViable
40-
];
38+
const phase1 = [this.commitViable];
4139

42-
const phase2 = [ // checks to always run
40+
const phase2 = [
41+
// checks to always run
4342
this.commitMessageLength,
4443
this.bangPrefix,
4544
this.lowerCaseAfterPrefix,
4645
this.signedOffBy,
4746
];
4847

49-
const phase3 = [ // checks if phase1 was successful
48+
const phase3 = [
49+
// checks if phase1 was successful
5050
this.commitTextLength,
5151
this.moreThanAHyperlink,
5252
];
5353

54-
phase1.map((linter) => { linter(); });
54+
phase1.map((linter) => {
55+
linter();
56+
});
5557

5658
const phase1Okay = false === this.blocked;
5759

58-
phase2.map((linter) => { linter(); });
60+
phase2.map((linter) => {
61+
linter();
62+
});
5963

6064
if (phase1Okay) {
61-
phase3.map((linter) => { linter(); });
65+
phase3.map((linter) => {
66+
linter();
67+
});
6268
}
6369

6470
if (this.messages.length) {
6571
this.messages.unshift(`\`${this.lines[0]}\``);
6672
return {
6773
checkFailed: this.blocked,
6874
message: `There ${this.messages.length > 1 ? "are issues" : "is an issue"} in commit ${
69-
this.patch.commit}:\n${this.messages.join("\n")}`,
75+
this.patch.commit
76+
}:\n${this.messages.join("\n")}`,
7077
};
7178
}
7279
}
@@ -107,14 +114,19 @@ export class LintCommit {
107114
}
108115

109116
for (const line of this.lines) {
110-
if (line.length > this.maxColumns &&
117+
if (
118+
line.length > this.maxColumns &&
111119
// Allow long lines if prefixed with whitespace (ex. quoted error messages)
112120
!line.match(/^\s+/) &&
113121
// Allow long lines if they cannot be wrapped at some white-space character, e.g. URLs. To allow a
114122
// short preamble such as `ref [1] <URL>` lines, we skip the first 10 (arbitrary) characters.
115-
line.slice(10).match(/\s/)) {
116-
this.block(`Lines in the body of the commit messages should be wrapped between 60 and ${
117-
this.maxColumns} characters.\nIndented lines, and lines without whitespace, are exempt`);
123+
line.slice(10).match(/\s/)
124+
) {
125+
this.block(
126+
`Lines in the body of the commit messages should be wrapped between 60 and ${
127+
this.maxColumns
128+
} characters.\nIndented lines, and lines without whitespace, are exempt`,
129+
);
118130
break;
119131
}
120132
}

lib/delete-ci-test-branches.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@ a workflow. The default is to delete branches older than two days.
1010
// ref level results of the GraphQL query
1111

1212
declare type refGraph = {
13-
node: { // branches as refs
13+
node: {
14+
// branches as refs
1415
name: string;
1516
id: string;
1617
pulls: {
17-
edges: [ // pull requests
18+
edges: [
19+
// pull requests
1820
{
1921
node: {
2022
number: number;
@@ -57,9 +59,12 @@ export type deletionOptions = {
5759
* @param repo name of repository on GitHub
5860
* @param options deletionOptions to override default of two days
5961
*/
60-
export async function deleteBranches(octocat: Octokit, owner: string,
61-
repo: string, options: deletionOptions = {}): Promise<void> {
62-
62+
export async function deleteBranches(
63+
octocat: Octokit,
64+
owner: string,
65+
repo: string,
66+
options: deletionOptions = {},
67+
): Promise<void> {
6368
if (!owner || !repo) {
6469
throw new Error("Missing owner or repo name.");
6570
}

lib/git.ts

Lines changed: 39 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ function trimTrailingNewline(str: string): string {
2020
}
2121

2222
export function git(args: string[], options?: IGitOptions): Promise<string> {
23-
const workDir = options && options.workDir || ".";
23+
const workDir = (options && options.workDir) || ".";
2424
if (options && options.trace) {
2525
process.stderr.write(`Called 'git ${args.join(" ")}' in '${workDir}':\n${new Error().stack}\n`);
2626
}
@@ -83,31 +83,43 @@ export function git(args: string[], options?: IGitOptions): Promise<string> {
8383
handleLine(buffer);
8484
}
8585
if (linePromise) {
86-
linePromise.then(() => { resolve(""); })
87-
.catch((reason) => { reject(reason as Error); });
86+
linePromise
87+
.then(() => {
88+
resolve("");
89+
})
90+
.catch((reason) => {
91+
reject(reason as Error);
92+
});
8893
} else {
8994
resolve("");
9095
}
9196
});
9297
};
9398
}
9499

95-
GitProcess.exec(args, workDir, options as IGitExecutionOptions).then((result) => {
96-
if (result.exitCode) {
97-
reject(new Error(`git ${args.join(" ")} failed: ${result.exitCode},\n${result.stderr}`));
98-
return;
99-
}
100-
if (options && options.trace) {
101-
process.stderr.write(`Output of 'git ${args.join(" ")}':\nstderr: ${result.stderr}\nstdout: ${
102-
result.stdout}\n`);
103-
}
104-
if (!options?.lineHandler) { // let callback resolve the promise
105-
resolve(!options || options.trimTrailingNewline === false ?
106-
result.stdout : trimTrailingNewline(result.stdout));
107-
}
108-
}).catch((reason) => {
109-
reject(reason as Error);
110-
});
100+
GitProcess.exec(args, workDir, options as IGitExecutionOptions)
101+
.then((result) => {
102+
if (result.exitCode) {
103+
reject(new Error(`git ${args.join(" ")} failed: ${result.exitCode},\n${result.stderr}`));
104+
return;
105+
}
106+
if (options && options.trace) {
107+
process.stderr.write(
108+
`Output of 'git ${args.join(" ")}':\nstderr: ${result.stderr}\nstdout: ${result.stdout}\n`,
109+
);
110+
}
111+
if (!options?.lineHandler) {
112+
// let callback resolve the promise
113+
resolve(
114+
!options || options.trimTrailingNewline === false
115+
? result.stdout
116+
: trimTrailingNewline(result.stdout),
117+
);
118+
}
119+
})
120+
.catch((reason) => {
121+
reject(reason as Error);
122+
});
111123
});
112124
}
113125

@@ -138,15 +150,14 @@ export async function revParse(argument: string, workDir?: string): Promise<stri
138150
*/
139151
export async function revListCount(rangeArgs: string | string[], workDir = "."): Promise<number> {
140152
const gitArgs: string[] = ["rev-list", "--count"];
141-
if (typeof(rangeArgs) === "string") {
153+
if (typeof rangeArgs === "string") {
142154
gitArgs.push(rangeArgs);
143155
} else {
144156
gitArgs.push(...rangeArgs);
145157
}
146158
const result = await GitProcess.exec(gitArgs, workDir);
147159
if (result.exitCode) {
148-
throw new Error(`Could not determine count for ${
149-
rangeArgs}: ${result.stderr}`);
160+
throw new Error(`Could not determine count for ${rangeArgs}: ${result.stderr}`);
150161
}
151162
return parseInt(result.stdout, 10);
152163
}
@@ -159,7 +170,7 @@ export async function revListCount(rangeArgs: string | string[], workDir = "."):
159170
* @returns {boolean} whether the commit exists
160171
*/
161172
export async function commitExists(commit: string, workDir: string): Promise<boolean> {
162-
return await revParse(`${commit}^{commit}`, workDir) !== undefined;
173+
return (await revParse(`${commit}^{commit}`, workDir)) !== undefined;
163174
}
164175

165176
export async function gitConfig(key: string, workDir?: string): Promise<string | undefined> {
@@ -170,10 +181,11 @@ export async function gitConfig(key: string, workDir?: string): Promise<string |
170181
return trimTrailingNewline(result.stdout);
171182
}
172183

173-
export async function gitConfigForEach(key: string,
174-
callbackfn: (value: string) => void,
175-
workDir?: string):
176-
Promise<void> {
184+
export async function gitConfigForEach(
185+
key: string,
186+
callbackfn: (value: string) => void,
187+
workDir?: string,
188+
): Promise<void> {
177189
const result = await GitProcess.exec(["config", "--get-all", key], workDir || ".");
178190
result.stdout.split(/\r?\n/).map(callbackfn);
179191
}

lib/gitgitgadget-config.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,7 @@ const defaultConfig: IConfig = {
3232
altname: "gitgitgadget-git",
3333
},
3434
lint: {
35-
maxCommitsIgnore: [
36-
"https://github.com/gitgitgadget/git/pull/923",
37-
],
35+
maxCommitsIgnore: ["https://github.com/gitgitgadget/git/pull/923"],
3836
maxCommits: 30,
3937
},
4038
user: {
@@ -48,4 +46,4 @@ setConfig(defaultConfig);
4846

4947
export function getConfig(): IConfig {
5048
return setConfig(defaultConfig);
51-
}
49+
}

0 commit comments

Comments
 (0)