Skip to content

Commit 992079d

Browse files
authored
Merge pull request #3089 from github/koesie10/eslint-curly
Enable ESLint `curly` rule
2 parents d5e7e54 + 918661e commit 992079d

File tree

13 files changed

+83
-31
lines changed

13 files changed

+83
-31
lines changed

extensions/ql-vscode/.eslintrc.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ const baseConfig = {
5050
"@typescript-eslint/no-throw-literal": "error",
5151
"no-useless-escape": 0,
5252
camelcase: "off",
53+
curly: ["error", "all"],
5354
"escompat/no-regexp-lookbehind": "off",
5455
"etc/no-implicit-any-catch": "error",
5556
"filenames/match-regex": "off",

extensions/ql-vscode/src/codeql-cli/cli.ts

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -635,9 +635,10 @@ export class CodeQLCliServer implements Disposable {
635635
} = {},
636636
): Promise<OutputType> {
637637
let args: string[] = [];
638-
if (addFormat)
638+
if (addFormat) {
639639
// Add format argument first, in case commandArgs contains positional parameters.
640640
args = args.concat(["--format", "json"]);
641+
}
641642
args = args.concat(commandArgs);
642643
const result = await this.runCodeQlCliCommand(command, args, description, {
643644
progressReporter,
@@ -939,8 +940,12 @@ export class CodeQLCliServer implements Disposable {
939940
name?: string,
940941
): Promise<string> {
941942
const subcommandArgs = [];
942-
if (target) subcommandArgs.push("--target", target);
943-
if (name) subcommandArgs.push("--name", name);
943+
if (target) {
944+
subcommandArgs.push("--target", target);
945+
}
946+
if (name) {
947+
subcommandArgs.push("--name", name);
948+
}
944949
subcommandArgs.push(archivePath);
945950

946951
return await this.runCodeQlCliCommand(
@@ -961,7 +966,9 @@ export class CodeQLCliServer implements Disposable {
961966
outputDirectory?: string,
962967
): Promise<string> {
963968
const subcommandArgs = ["--format=markdown"];
964-
if (outputDirectory) subcommandArgs.push("--output", outputDirectory);
969+
if (outputDirectory) {
970+
subcommandArgs.push("--output", outputDirectory);
971+
}
965972
subcommandArgs.push(pathToQhelp);
966973

967974
return await this.runCodeQlCliCommand(
@@ -1609,16 +1616,19 @@ export function spawnServer(
16091616
});
16101617
// Set up event listeners.
16111618
child.on("close", async (code, signal) => {
1612-
if (code !== null)
1619+
if (code !== null) {
16131620
void logger.log(`Child process exited with code ${code}`);
1614-
if (signal)
1621+
}
1622+
if (signal) {
16151623
void logger.log(
16161624
`Child process exited due to receipt of signal ${signal}`,
16171625
);
1626+
}
16181627
// If the process exited abnormally, log the last stdout message,
16191628
// It may be from the jvm.
1620-
if (code !== 0 && lastStdout !== undefined)
1629+
if (code !== 0 && lastStdout !== undefined) {
16211630
void logger.log(`Last stdout was "${lastStdout.toString()}"`);
1631+
}
16221632
});
16231633
child.stderr!.on("data", stderrListener);
16241634
if (stdoutListener !== undefined) {

extensions/ql-vscode/src/common/sarif-utils.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,15 @@ export function parseSarifLocation(
107107
sourceLocationPrefix: string,
108108
): ParsedSarifLocation {
109109
const physicalLocation = loc.physicalLocation;
110-
if (physicalLocation === undefined) return { hint: "no physical location" };
111-
if (physicalLocation.artifactLocation === undefined)
110+
if (physicalLocation === undefined) {
111+
return { hint: "no physical location" };
112+
}
113+
if (physicalLocation.artifactLocation === undefined) {
112114
return { hint: "no artifact location" };
113-
if (physicalLocation.artifactLocation.uri === undefined)
115+
}
116+
if (physicalLocation.artifactLocation.uri === undefined) {
114117
return { hint: "artifact location has no uri" };
118+
}
115119
if (isEmptyPath(physicalLocation.artifactLocation.uri)) {
116120
return { hint: "artifact location has empty uri" };
117121
}

extensions/ql-vscode/src/common/vscode/archive-filesystem-provider.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,11 +130,14 @@ export function decodeSourceArchiveUri(uri: vscode.Uri): ZipFileReference {
130130
};
131131
}
132132
const match = sourceArchiveUriAuthorityPattern.exec(uri.authority);
133-
if (match === null) throw new InvalidSourceArchiveUriError(uri);
133+
if (match === null) {
134+
throw new InvalidSourceArchiveUriError(uri);
135+
}
134136
const zipPathStartIndex = parseInt(match[1]);
135137
const zipPathEndIndex = parseInt(match[2]);
136-
if (isNaN(zipPathStartIndex) || isNaN(zipPathEndIndex))
138+
if (isNaN(zipPathStartIndex) || isNaN(zipPathEndIndex)) {
137139
throw new InvalidSourceArchiveUriError(uri);
140+
}
138141
return {
139142
pathWithinSourceArchive: uri.path.substring(zipPathEndIndex) || "/",
140143
sourceArchiveZipPath: uri.path.substring(
@@ -179,8 +182,9 @@ type Archive = {
179182
};
180183

181184
async function parse_zip(zipPath: string): Promise<Archive> {
182-
if (!(await pathExists(zipPath)))
185+
if (!(await pathExists(zipPath))) {
183186
throw vscode.FileSystemError.FileNotFound(zipPath);
187+
}
184188
const archive: Archive = {
185189
unzipped: await unzipper.Open.file(zipPath),
186190
dirMap: new Map(),

extensions/ql-vscode/src/databases/db-item-selection.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,15 @@ export function getSelectedDbItem(dbItems: DbItem[]): DbItem | undefined {
99
) {
1010
for (const child of dbItem.children) {
1111
const selectedItem = extractSelected(child);
12-
if (selectedItem) return selectedItem;
12+
if (selectedItem) {
13+
return selectedItem;
14+
}
1315
}
1416
} else {
1517
const selectedItem = extractSelected(dbItem);
16-
if (selectedItem) return selectedItem;
18+
if (selectedItem) {
19+
return selectedItem;
20+
}
1721
}
1822
}
1923
return undefined;

extensions/ql-vscode/src/databases/local-databases/database-item-impl.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,9 @@ export class DatabaseItemImpl implements DatabaseItem {
197197
* Holds if `uri` belongs to this database's source archive.
198198
*/
199199
public belongsToSourceArchiveExplorerUri(uri: vscode.Uri): boolean {
200-
if (this.sourceArchive === undefined) return false;
200+
if (this.sourceArchive === undefined) {
201+
return false;
202+
}
201203
return (
202204
uri.scheme === zipArchiveScheme &&
203205
decodeSourceArchiveUri(uri).sourceArchiveZipPath ===

extensions/ql-vscode/src/local-queries/results-view.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -655,8 +655,9 @@ export class ResultsView extends AbstractWebview<
655655
const schema = resultSetSchemas.find(
656656
(resultSet) => resultSet.name === selectedTable,
657657
)!;
658-
if (schema === undefined)
658+
if (schema === undefined) {
659659
throw new Error(`Query result set '${selectedTable}' not found.`);
660+
}
660661

661662
const pageSize = PAGE_SIZE.getValue<number>();
662663
const chunk = await this.cliServer.bqrsDecode(
@@ -771,7 +772,9 @@ export class ResultsView extends AbstractWebview<
771772
);
772773
}
773774

774-
if (interp.data.t !== "SarifInterpretationData") return interp;
775+
if (interp.data.t !== "SarifInterpretationData") {
776+
return interp;
777+
}
775778

776779
if (interp.data.runs.length !== 1) {
777780
void this.logger.log(
@@ -887,7 +890,9 @@ export class ResultsView extends AbstractWebview<
887890
): Promise<void> {
888891
const { data, sourceLocationPrefix } = interpretation;
889892

890-
if (data.t !== "SarifInterpretationData") return;
893+
if (data.t !== "SarifInterpretationData") {
894+
return;
895+
}
891896

892897
if (!data.runs || !data.runs[0].results) {
893898
void this.logger.log(

extensions/ql-vscode/src/query-history/query-history-manager.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,9 @@ export class QueryHistoryManager extends DisposableObject {
556556
item,
557557
)}. Are you sure?`,
558558
);
559-
if (!response) return;
559+
if (!response) {
560+
return;
561+
}
560562
}
561563

562564
this.treeDataProvider.remove(item);
@@ -579,7 +581,9 @@ export class QueryHistoryManager extends DisposableObject {
579581

580582
void showInformationMessageWithAction(message, "Go to workflow run").then(
581583
async (shouldOpenWorkflowRun) => {
582-
if (!shouldOpenWorkflowRun) return;
584+
if (!shouldOpenWorkflowRun) {
585+
return;
586+
}
583587
await env.openExternal(Uri.parse(workflowRunUrl));
584588
},
585589
);

extensions/ql-vscode/src/view/results/locations/NonClickableLocation.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ interface Props {
1010
* Designed to fit in with the other types of location components.
1111
*/
1212
export function NonClickableLocation({ msg, locationHint }: Props) {
13-
if (msg === undefined) return null;
13+
if (msg === undefined) {
14+
return null;
15+
}
1416
return <span title={locationHint}>{msg}</span>;
1517
}

extensions/ql-vscode/src/view/results/result-keys.ts

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,19 @@ export function getPath(
5454
key: Path | PathNode,
5555
): sarif.ThreadFlow | undefined {
5656
const result = getResult(sarif, key);
57-
if (result === undefined) return undefined;
57+
if (result === undefined) {
58+
return undefined;
59+
}
5860
let index = -1;
59-
if (result.codeFlows === undefined) return undefined;
61+
if (result.codeFlows === undefined) {
62+
return undefined;
63+
}
6064
for (const codeFlows of result.codeFlows) {
6165
for (const threadFlow of codeFlows.threadFlows) {
6266
++index;
63-
if (index === key.pathIndex) return threadFlow;
67+
if (index === key.pathIndex) {
68+
return threadFlow;
69+
}
6470
}
6571
}
6672
return undefined;
@@ -74,7 +80,9 @@ export function getPathNode(
7480
key: PathNode,
7581
): sarif.Location | undefined {
7682
const path = getPath(sarif, key);
77-
if (path === undefined) return undefined;
83+
if (path === undefined) {
84+
return undefined;
85+
}
7886
return path.locations[key.pathNodeIndex]?.location;
7987
}
8088

@@ -85,7 +93,9 @@ export function equalsNotUndefined(
8593
key1: Partial<PathNode> | undefined,
8694
key2: Partial<PathNode> | undefined,
8795
): boolean {
88-
if (key1 === undefined || key2 === undefined) return false;
96+
if (key1 === undefined || key2 === undefined) {
97+
return false;
98+
}
8999
return (
90100
key1.resultIndex === key2.resultIndex &&
91101
key1.pathIndex === key2.pathIndex &&
@@ -99,7 +109,9 @@ export function equalsNotUndefined(
99109
* Path nodes indices are relative to this flattened list.
100110
*/
101111
export function getAllPaths(result: sarif.Result): sarif.ThreadFlow[] {
102-
if (result.codeFlows === undefined) return [];
112+
if (result.codeFlows === undefined) {
113+
return [];
114+
}
103115
const paths = [];
104116
for (const codeFlow of result.codeFlows) {
105117
for (const threadFlow of codeFlow.threadFlows) {

0 commit comments

Comments
 (0)