Skip to content

Commit

Permalink
Linter: Improve checks
Browse files Browse the repository at this point in the history
* Add `"noUncheckedIndexedAccess": true`
      `"allowUnusedLabels": false`
      `"allowUreachableCode": false`
      `"noImplicitReturns": true`
* Fix related errors

The `tsconfig.json` configuration is used from
https://github.com/tsconfig/bases/blob/main/bases/strictest.json

Change-Id: I310d4b5a69ff28093a8f8725feb55d5a6ca7093f
Reviewed-by: Marcus Tillmanns <[email protected]>
  • Loading branch information
OrkunTokdemir committed May 28, 2024
1 parent d8412af commit 20e16b1
Show file tree
Hide file tree
Showing 11 changed files with 41 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/commands/register-qt-path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export async function registerQt() {
canSelectFolders: true
};
const selectedQtFolderUri = await vscode.window.showOpenDialog(options);
if (!selectedQtFolderUri) {
if (selectedQtFolderUri?.[0] === undefined) {
return;
}
const selectedQtFolder = selectedQtFolderUri[0].fsPath;
Expand Down
3 changes: 2 additions & 1 deletion src/designer-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,11 @@ export class DesignerServer {
this.stop();
}

public getPort() {
public getPort(): number | undefined {
if (this.server.address()) {
return (this.server.address() as net.AddressInfo).port;
}
return undefined;
}
public isClientConnected() {
return this.client !== undefined && !this.client.destroyed;
Expand Down
9 changes: 6 additions & 3 deletions src/kit-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ export class KitManager {
}
const toolchain = path.basename(installation);
const tokens = toolchain.split('_');
let platform = tokens[0];
let platform = tokens[0] ?? '';
if (platform != 'android') {
if (platform.startsWith('msvc')) {
newKit = {
Expand Down Expand Up @@ -625,6 +625,9 @@ export class KitManager {
);
const msvcKitsWithArchitectureMatch = loadedCMakeKits.filter((kit) => {
const version = KitManager.getMsvcYear(kit);
if (!version) {
return false;
}
logger.info('version: ' + version);
const msvcTargetArch =
kit.preferredGenerator?.platform ?? kit.visualStudioArchitecture ?? '';
Expand Down Expand Up @@ -666,15 +669,15 @@ export class KitManager {
}

private static getMsvcYear(kit: Kit) {
const year = kit.name.match(KitManager.MsvcYearRegex)?.at(1);
const year = kit.name.match(KitManager.MsvcYearRegex)?.at(1) ?? '';
if (year) {
return year;
}
const majorMsvcVersion = kit.name
.match(KitManager.MsvcMajorVersionNumberRegex)
?.at(1);
if (majorMsvcVersion) {
return KitManager.MapMsvcMajorVersionToItsYear[majorMsvcVersion];
return KitManager.MapMsvcMajorVersionToItsYear[majorMsvcVersion] ?? '';
}
return '';
}
Expand Down
1 change: 1 addition & 0 deletions src/tasks/wasm-start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export class WASMStartTaskProvider implements vscode.TaskProvider {
await extension.activate();
return true;
}
return false;
} else {
const message =
`The extension ${extensionId} is required to debug ` +
Expand Down
3 changes: 3 additions & 0 deletions src/test/integration/runTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ async function main() {
const vscodeExecutablePath = await downloadAndUnzipVSCode('stable');
const [cliPath, ...args] =
resolveCliArgsFromVSCodeExecutablePath(vscodeExecutablePath);
if (!cliPath) {
throw new Error('Failed to locate Code CLI');
}
const testWorkspace = path.resolve(
extensionDevelopmentPath,
'src/test/integration/project-folder'
Expand Down
3 changes: 3 additions & 0 deletions src/test/unit/runTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ async function main() {
const vscodeExecutablePath = await downloadAndUnzipVSCode('stable');
const [cliPath, ...args] =
resolveCliArgsFromVSCodeExecutablePath(vscodeExecutablePath);
if (!cliPath) {
throw new Error('Failed to locate Code CLI');
}
const testWorkspace = path.resolve(
extensionDevelopmentPath,
'src/test/unit/project-folder'
Expand Down
2 changes: 2 additions & 0 deletions src/test/util/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export function getFirstQtKit(qt_path: string | undefined) {
return kit;
}
}
return undefined;
}

export function getFirstQtInstallation(qt_path: string | undefined) {
Expand All @@ -52,6 +53,7 @@ export function getFirstQtInstallation(qt_path: string | undefined) {
return installation;
}
}
return undefined;
}

export async function activateIntegrationTestExtensions() {
Expand Down
4 changes: 3 additions & 1 deletion src/util/get-qt-paths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,9 @@ export async function locateMingwBinDirPath(qtRootDir: string) {
mingwsWithBins.map((item) => {
const m = item.match(/mingw(\d+)_\d+/);
let v = 0;
if (m) v = parseInt(m[1], 10);
if (m?.[1] !== undefined) {
v = parseInt(m[1], 10);
}
return [v, item];
})
);
Expand Down
7 changes: 6 additions & 1 deletion src/util/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@ export function getFilenameWithoutExtension(filename: string): string {
if (!separatedPath) {
throw new Error('Filename is empty');
}
return separatedPath.split('.')[0];
const splittedPath = separatedPath.split('.')[0];
if (splittedPath === undefined) {
throw new Error('Filename is empty');
}

return splittedPath;
}

export function isError<T>(e: T): e is T & Error {
Expand Down
13 changes: 10 additions & 3 deletions src/util/versions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,18 @@ export function compareVersions(version1: string, version2: string) {
if (v2parts.length === i) {
return 1;
}

if (v1parts[i] === v2parts[i]) {
const v1Part = v1parts[i];
const v2Part = v2parts[i];
if (v1Part === undefined) {
throw new Error('v1Part is undefined');
}
if (v2Part === undefined) {
throw new Error('v2Part is undefined');
}
if (v1Part === v2Part) {
continue;
}
if (v1parts[i] > v2parts[i]) {
if (v1Part > v2Part) {
return 1;
}
return -1;
Expand Down
4 changes: 4 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
"sourceMap": true,
"rootDir": "src",
"strict": true /* enable all strict type-checking options */,
"noUncheckedIndexedAccess": true,
"allowUnusedLabels": false,
"allowUnreachableCode": false,
"noImplicitReturns": true,
"baseUrl": "./",
"paths": {
"@/*": ["src/*"],
Expand Down

0 comments on commit 20e16b1

Please sign in to comment.