Skip to content

Commit e5c15ed

Browse files
committed
fix: biome linter fixes
1 parent 2885911 commit e5c15ed

9 files changed

+88
-92
lines changed

.husky/pre-commit

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1 @@
1-
#!/bin/sh
2-
. "$(dirname $0)/_/husky.sh"
3-
4-
yarn pretty-quick --staged
1+
bun lint

biome.json

+32-30
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,33 @@
11
{
2-
"$schema": "https://biomejs.dev/schemas/1.9.4/schema.json",
3-
"vcs": {
4-
"enabled": true,
5-
"clientKind": "git",
6-
"useIgnoreFile": true
7-
},
8-
"files": {
9-
"ignoreUnknown": false,
10-
"ignore": []
11-
},
12-
"formatter": {
13-
"enabled": true,
14-
"indentStyle": "tab"
15-
},
16-
"organizeImports": {
17-
"enabled": true
18-
},
19-
"linter": {
20-
"enabled": true,
21-
"rules": {
22-
"recommended": true
23-
}
24-
},
25-
"javascript": {
26-
"formatter": {
27-
"quoteStyle": "double"
28-
},
29-
"globals": ["exports"]
30-
}
31-
}
2+
"$schema": "https://biomejs.dev/schemas/1.9.4/schema.json",
3+
"vcs": {
4+
"enabled": true,
5+
"clientKind": "git",
6+
"useIgnoreFile": true
7+
},
8+
"files": {
9+
"ignoreUnknown": false,
10+
"ignore": []
11+
},
12+
"formatter": {
13+
"enabled": true,
14+
"indentStyle": "space"
15+
},
16+
"organizeImports": {
17+
"enabled": true
18+
},
19+
"linter": {
20+
"enabled": true,
21+
"rules": {
22+
"recommended": true
23+
}
24+
},
25+
"javascript": {
26+
"formatter": {
27+
"quoteStyle": "double"
28+
},
29+
"globals": [
30+
"exports"
31+
]
32+
}
33+
}

src/client.ts

+18-15
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,29 @@
11
// from PR of https://github.com/nix-community/vscode-nix-ide/pull/16/
22

3+
// biome-ignore lint/style/useNodejsImportProtocol: <explanation>
4+
import { inspect } from "util";
5+
import { sync as commandExistsSync } from "command-exists";
36
import {
4-
env,
5-
ExtensionContext,
7+
type Disposable,
8+
type ExtensionContext,
69
Uri,
10+
env,
711
window,
812
workspace,
9-
Disposable,
1013
} from "vscode";
11-
import {
12-
LanguageClientOptions,
13-
LSPArray,
14+
import type {
15+
CancellationToken,
1416
ConfigurationParams,
17+
LSPArray,
18+
LanguageClientOptions,
1519
MessageSignature,
16-
CancellationToken,
1720
} from "vscode-languageclient";
1821
import {
19-
Executable,
22+
type Executable,
2023
LanguageClient,
21-
ServerOptions,
24+
type ServerOptions,
2225
} from "vscode-languageclient/node";
23-
import { config, UriMessageItem } from "./configuration";
24-
import { sync as commandExistsSync } from "command-exists";
25-
import { inspect } from "util";
26+
import { type UriMessageItem, config } from "./configuration";
2627

2728
class Client extends LanguageClient {
2829
disposables: Disposable[] = [];
@@ -52,7 +53,9 @@ class Client extends LanguageClient {
5253
override dispose(timeout?: number): Promise<void> {
5354
let timedOut = false;
5455
if (timeout) {
55-
setTimeout(() => (timedOut = true), timeout);
56+
setTimeout(() => {
57+
timedOut = true;
58+
}, timeout);
5659
}
5760

5861
for (const disposable of this.disposables) {
@@ -131,8 +134,8 @@ export async function activate(context: ExtensionContext): Promise<void> {
131134
context.subscriptions.push(client);
132135
}
133136

134-
export async function deactivate(): Promise<void | undefined> {
135-
if (client && client.needsStop()) {
137+
export async function deactivate(): Promise<void> {
138+
if (client?.needsStop()) {
136139
await client.stop();
137140
}
138141
await client.dispose();

src/configuration.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import {
2-
ConfigurationChangeEvent,
3-
WorkspaceConfiguration,
2+
type ConfigurationChangeEvent,
3+
type WorkspaceConfiguration,
44
workspace,
55
} from "vscode";
6-
import { LSPObject } from "vscode-languageclient";
6+
import type { LSPObject } from "vscode-languageclient";
77

8-
import { MessageItem, Uri } from "vscode";
8+
import type { MessageItem, Uri } from "vscode";
99
import { transformConfigValueByVscodeVariables } from "./utils";
1010

1111
export interface UriMessageItem extends MessageItem {

src/extension.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import * as vscode from "vscode";
2-
import { ExtensionContext } from "vscode";
2+
import type { ExtensionContext } from "vscode";
3+
import * as client from "./client";
4+
import { config } from "./configuration";
35
import { formattingProviders } from "./formatter";
46
import { startLinting } from "./linter";
5-
import { config } from "./configuration";
6-
import * as client from "./client";
77

88
/**
99
* Activate this extension.

src/formatter.ts

+16-17
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
import * as vscode from "vscode";
22
import {
3-
DocumentFormattingEditProvider,
4-
DocumentRangeFormattingEditProvider,
3+
type DocumentFormattingEditProvider,
4+
type DocumentRangeFormattingEditProvider,
55
Range,
6-
TextDocument,
6+
type TextDocument,
77
TextEdit,
88
} from "vscode";
9-
import { IProcessResult, runInWorkspace } from "./process-runner";
109
import { config } from "./configuration";
10+
import { type IProcessResult, runInWorkspace } from "./process-runner";
1111

12-
const FORMATTER: Array<string> =
13-
config.formatterPath instanceof Array
14-
? config.formatterPath
15-
: [config.formatterPath];
12+
const FORMATTER: Array<string> = Array.isArray(config.formatterPath)
13+
? config.formatterPath
14+
: [config.formatterPath];
1615

1716
/**
1817
* Get text edits to format a range in a document.
@@ -23,25 +22,25 @@ const FORMATTER: Array<string> =
2322
*/
2423
const getFormatRangeEdits = async (
2524
document: TextDocument,
26-
range?: Range
25+
range?: Range,
2726
): Promise<ReadonlyArray<TextEdit>> => {
2827
const actualRange = document.validateRange(
29-
range || new Range(0, 0, Number.MAX_VALUE, Number.MAX_VALUE)
28+
range || new Range(0, 0, Number.MAX_VALUE, Number.MAX_VALUE),
3029
);
3130
let result: IProcessResult;
3231
try {
33-
FORMATTER.forEach(
34-
(elm, i) => (FORMATTER[i] = elm.replace("{file}", document.fileName))
35-
);
32+
FORMATTER.forEach((elm, i) => {
33+
FORMATTER[i] = elm.replace("{file}", document.fileName);
34+
});
3635
result = await runInWorkspace(
3736
vscode.workspace.getWorkspaceFolder(document.uri),
3837
FORMATTER,
39-
document.getText(actualRange)
38+
document.getText(actualRange),
4039
);
4140
} catch (error) {
4241
if (error instanceof Error) {
4342
await vscode.window.showErrorMessage(
44-
`Failed to run ${FORMATTER.join(" ")}: ${error.message}`
43+
`Failed to run ${FORMATTER.join(" ")}: ${error.message}`,
4544
);
4645
}
4746
// Re-throw the error to make the promise fail
@@ -67,13 +66,13 @@ export const formattingProviders: FormattingProviders = {
6766
token.isCancellationRequested
6867
? []
6968
: // tslint:disable-next-line:readonly-array
70-
(edits as TextEdit[])
69+
(edits as TextEdit[]),
7170
),
7271
provideDocumentRangeFormattingEdits: (document, range, _, token) =>
7372
getFormatRangeEdits(document, range).then((edits) =>
7473
token.isCancellationRequested
7574
? []
7675
: // tslint:disable-next-line:readonly-array
77-
(edits as TextEdit[])
76+
(edits as TextEdit[]),
7877
),
7978
};

src/linter.ts

+9-11
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
"use strict";
2-
31
import * as vscode from "vscode";
4-
import { Diagnostic, ExtensionContext, TextDocument } from "vscode";
2+
import { Diagnostic, type ExtensionContext, type TextDocument } from "vscode";
53
import { runInWorkspace } from "./process-runner";
64

75
/**
@@ -18,7 +16,7 @@ const isSavedDocument = (document: TextDocument): boolean =>
1816
language: "nix",
1917
scheme: "file",
2018
},
21-
document
19+
document,
2220
);
2321

2422
interface LintErrorType {
@@ -45,8 +43,8 @@ const getErrors = (text: string): ReadonlyArray<LintErrorType> => {
4543
while (match !== null) {
4644
results.push({
4745
msg: match[1],
48-
row: parseInt(match[2]),
49-
col: parseInt(match[3]),
46+
row: Number.parseInt(match[2]),
47+
col: Number.parseInt(match[3]),
5048
});
5149
match = pattern.exec(text);
5250
}
@@ -62,12 +60,12 @@ const getErrors = (text: string): ReadonlyArray<LintErrorType> => {
6260
*/
6361
const shellOutputToDiagnostics = (
6462
document: TextDocument,
65-
output: string
63+
output: string,
6664
): ReadonlyArray<Diagnostic> => {
6765
const diagnostics: Array<Diagnostic> = [];
6866
for (const err of getErrors(output)) {
6967
const range = document.validateRange(
70-
new vscode.Range(err.row - 1, err.col - 2, err.row - 1, err.col + 2)
68+
new vscode.Range(err.row - 1, err.col - 2, err.row - 1, err.col + 2),
7169
);
7270
const diagnostic = new Diagnostic(range, err.msg);
7371
diagnostic.source = "nix";
@@ -88,7 +86,7 @@ export async function startLinting(context: ExtensionContext): Promise<void> {
8886
const lint = async (document: TextDocument) => {
8987
if (isSavedDocument(document)) {
9088
const workspaceFolder = vscode.workspace.getWorkspaceFolder(document.uri);
91-
let d: ReadonlyArray<Diagnostic>
89+
let d: ReadonlyArray<Diagnostic>;
9290
try {
9391
const result = await runInWorkspace(workspaceFolder, [
9492
"nix-instantiate",
@@ -116,6 +114,6 @@ export async function startLinting(context: ExtensionContext): Promise<void> {
116114
vscode.workspace.onDidCloseTextDocument(
117115
(d) => diagnostics.delete(d.uri),
118116
null,
119-
context.subscriptions
117+
context.subscriptions,
120118
);
121-
};
119+
}

src/process-runner.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { execFile } from "child_process";
2-
import { WorkspaceFolder } from "vscode";
1+
import { execFile } from "node:child_process";
2+
import type { WorkspaceFolder } from "vscode";
33

44
/**
55
* A system error, i.e. an error that results from a syscall.

src/utils.ts

+3-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { LSPObject } from "vscode-languageclient";
1+
import type { LSPObject } from "vscode-languageclient";
22
import variables from "vscode-variables";
33

44
/**
@@ -15,12 +15,9 @@ export const transformConfigValueByVscodeVariables = <
1515
if (typeof cfg === "string") {
1616
cfg = variables(cfg) as T;
1717
} else if (!!cfg && typeof cfg === "object") {
18-
Object.keys(cfg).forEach((key) => {
19-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
20-
// @ts-ignore
21-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
18+
for (const key of Object.keys(cfg)) {
2219
cfg[key] = transformConfigValueByVscodeVariables(cfg[key]);
23-
});
20+
}
2421
} else if (Array.isArray(cfg) && cfg.length > 0) {
2522
cfg = cfg.map(
2623
(item) => transformConfigValueByVscodeVariables(item) as unknown,

0 commit comments

Comments
 (0)