Skip to content

Commit 84fe420

Browse files
committed
Enable stylistic type checked
1 parent 0208903 commit 84fe420

File tree

13 files changed

+40
-34
lines changed

13 files changed

+40
-34
lines changed

eslint.config.mjs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export default defineConfig(
3333
files: ["**/*.ts"],
3434
extends: [
3535
...tseslint.configs.recommendedTypeChecked,
36-
...tseslint.configs.stylistic,
36+
...tseslint.configs.stylisticTypeChecked,
3737
importXFlatConfigs.typescript,
3838
],
3939
languageOptions: {
@@ -74,6 +74,16 @@ export default defineConfig(
7474
{ varsIgnorePattern: "^_" },
7575
],
7676
"@typescript-eslint/array-type": ["error", { default: "array-simple" }],
77+
"@typescript-eslint/prefer-nullish-coalescing": [
78+
"error",
79+
// Allow || for strings where empty string should be treated as falsy
80+
{ ignorePrimitives: { string: true } },
81+
],
82+
"@typescript-eslint/dot-notation": [
83+
"error",
84+
// Allow bracket notation for index signatures (e.g., Record<string, T>)
85+
{ allowIndexSignaturePropertyAccess: true },
86+
],
7787

7888
// Import rules
7989
"import-x/order": [

src/api/api-helper.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,8 @@ export function errToStr(error: unknown, def = "No error message provided") {
1818
} else if (isApiErrorResponse(error)) {
1919
return error.message;
2020
} else if (error instanceof ErrorEvent) {
21-
return error.code
22-
? `${error.code}: ${error.message || def}`
23-
: error.message || def;
21+
const message = error.message || def;
22+
return error.code ? `${error.code}: ${message}` : message;
2423
} else if (typeof error === "string" && error.trim().length > 0) {
2524
return error;
2625
}
@@ -46,7 +45,7 @@ export function extractAgents(
4645
resources: readonly WorkspaceResource[],
4746
): WorkspaceAgent[] {
4847
return resources.reduce((acc, resource) => {
49-
return acc.concat(resource.agents || []);
48+
return acc.concat(resource.agents ?? []);
5049
}, [] as WorkspaceAgent[]);
5150
}
5251

src/api/coderApi.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@ function addLoggingInterceptors(client: AxiosInstance, logger: Logger) {
501501

502502
config.transformRequest = [
503503
...wrapRequestTransform(
504-
config.transformRequest || client.defaults.transformRequest || [],
504+
config.transformRequest ?? client.defaults.transformRequest ?? [],
505505
configWithMeta,
506506
),
507507
(data: unknown) => {
@@ -512,7 +512,7 @@ function addLoggingInterceptors(client: AxiosInstance, logger: Logger) {
512512
];
513513

514514
config.transformResponse = wrapResponseTransform(
515-
config.transformResponse || client.defaults.transformResponse || [],
515+
config.transformResponse ?? client.defaults.transformResponse ?? [],
516516
configWithMeta,
517517
);
518518

src/api/proxy.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// This file is copied from proxy-from-env with added support to use something
22
// other than environment variables.
33

4-
import { parse as parseUrl } from "url";
4+
import { parse as parseUrl } from "node:url";
55

66
const DEFAULT_PORTS: Record<string, number> = {
77
ftp: 21,
@@ -34,7 +34,8 @@ export function getProxyForUrl(
3434
// Stripping ports in this way instead of using parsedUrl.hostname to make
3535
// sure that the brackets around IPv6 addresses are kept.
3636
hostname = hostname.replace(/:\d*$/, "");
37-
const port = (portRaw && parseInt(portRaw)) || DEFAULT_PORTS[proto] || 0;
37+
const port =
38+
(portRaw && Number.parseInt(portRaw)) || DEFAULT_PORTS[proto] || 0;
3839
if (!shouldProxy(hostname, port, noProxy)) {
3940
return ""; // Don't proxy URLs that match NO_PROXY.
4041
}
@@ -45,7 +46,7 @@ export function getProxyForUrl(
4546
getEnv(proto + "_proxy") ||
4647
getEnv("npm_config_proxy") ||
4748
getEnv("all_proxy");
48-
if (proxy && proxy.indexOf("://") === -1) {
49+
if (proxy?.includes("://")) {
4950
// Missing scheme in proxy, default to the requested URL's scheme.
5051
proxy = proto + "://" + proxy;
5152
}
@@ -81,9 +82,9 @@ function shouldProxy(
8182
if (!proxy) {
8283
return true; // Skip zero-length hosts.
8384
}
84-
const parsedProxy = proxy.match(/^(.+):(\d+)$/);
85+
const parsedProxy = /^(.+):(\d+)$/.exec(proxy);
8586
let parsedProxyHostname = parsedProxy ? parsedProxy[1] : proxy;
86-
const parsedProxyPort = parsedProxy ? parseInt(parsedProxy[2]) : 0;
87+
const parsedProxyPort = parsedProxy ? Number.parseInt(parsedProxy[2]) : 0;
8788
if (parsedProxyPort && parsedProxyPort !== port) {
8889
return true; // Skip if ports don't match.
8990
}
@@ -93,7 +94,7 @@ function shouldProxy(
9394
return hostname !== parsedProxyHostname;
9495
}
9596

96-
if (parsedProxyHostname.charAt(0) === "*") {
97+
if (parsedProxyHostname.startsWith("*")) {
9798
// Remove leading wildcard.
9899
parsedProxyHostname = parsedProxyHostname.slice(1);
99100
}

src/core/cliManager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ export class CliManager {
240240
const newStat = await cliUtils.stat(binPath);
241241
this.output.info(
242242
"Downloaded binary size is",
243-
prettyBytes(newStat?.size || 0),
243+
prettyBytes(newStat?.size ?? 0),
244244
);
245245

246246
// Make sure we can execute this new binary.

src/extension.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ export async function activate(ctx: vscode.ExtensionContext): Promise<void> {
232232
const detail = getErrorDetail(ex) || "None";
233233
const urlString = axios.getUri(ex.config);
234234
const method = ex.config?.method?.toUpperCase() || "request";
235-
const status = ex.response?.status || "None";
235+
const status = ex.response?.status ?? "None";
236236
const message = `API ${method} to '${urlString}' failed.\nStatus code: ${status}\nMessage: ${msg}\nDetail: ${detail}`;
237237
output.warn(message);
238238
await vscodeProposed.window.showErrorMessage(

src/featureSet.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@ export function featureSetForVersion(
2525
// If this check didn't exist, VS Code connections would fail on
2626
// older versions because of an unknown CLI argument.
2727
proxyLogDirectory:
28-
(version?.compare("2.3.3") || 0) > 0 ||
28+
(version?.compare("2.3.3") ?? 0) > 0 ||
2929
version?.prerelease[0] === "devel",
3030
wildcardSSH:
3131
(version ? version.compare("2.19.0") : -1) >= 0 ||
3232
version?.prerelease[0] === "devel",
3333

3434
// The --reason flag was added to `coder start` in 2.25.0
3535
buildReason:
36-
(version?.compare("2.25.0") || 0) >= 0 ||
36+
(version?.compare("2.25.0") ?? 0) >= 0 ||
3737
version?.prerelease[0] === "devel",
3838
};
3939
}

src/headers.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,7 @@ export async function getHeaders(
9595
const [key, value] = line.split(/=(.*)/);
9696
// Header names cannot be blank or contain whitespace and the Coder CLI
9797
// requires that there be an equals sign (the value can be blank though).
98-
if (
99-
key.length === 0 ||
100-
key.indexOf(" ") !== -1 ||
101-
typeof value === "undefined"
102-
) {
98+
if (key.length === 0 || key.includes(" ") || value === undefined) {
10399
throw new Error(
104100
`Malformed line from header command: [${line}] (out: ${result.stdout})`,
105101
);

src/remote/remote.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -774,9 +774,9 @@ export class Remote {
774774

775775
// deploymentConfig is now set from the remote coderd deployment.
776776
// Now override with the user's config.
777-
const userConfigSsh =
778-
vscode.workspace.getConfiguration("coder").get<string[]>("sshConfig") ||
779-
[];
777+
const userConfigSsh = vscode.workspace
778+
.getConfiguration("coder")
779+
.get<string[]>("sshConfig", []);
780780
const userConfig = parseSshConfig(userConfigSsh);
781781
const sshConfigOverrides = mergeSshConfigValues(
782782
deploymentSSHConfig,

src/remote/sshConfig.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { mkdir, readFile, rename, stat, writeFile } from "fs/promises";
2-
import path from "path";
1+
import { mkdir, readFile, rename, stat, writeFile } from "node:fs/promises";
2+
import path from "node:path";
33

44
import { countSubstring } from "../util";
55

@@ -45,7 +45,7 @@ export function parseSshConfig(lines: string[]): Record<string, string> {
4545
return lines.reduce(
4646
(acc, line) => {
4747
// Match key pattern (same as VS Code settings: ^[a-zA-Z0-9-]+)
48-
const keyMatch = line.match(/^[a-zA-Z0-9-]+/);
48+
const keyMatch = /^[a-zA-Z0-9-]+/.exec(line);
4949
if (!keyMatch) {
5050
return acc; // Malformed line
5151
}
@@ -258,7 +258,7 @@ export class SSHConfig {
258258
const lines = [this.startBlockComment(safeHostname), `Host ${Host}`];
259259

260260
// configValues is the merged values of the defaults and the overrides.
261-
const configValues = mergeSshConfigValues(otherValues, overrides || {});
261+
const configValues = mergeSshConfigValues(otherValues, overrides ?? {});
262262

263263
// keys is the sorted keys of the merged values.
264264
const keys = Object.keys(configValues).sort();

0 commit comments

Comments
 (0)