From 2e39325db6d4d77c40258868062b4a4d53d7692b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jens=20M=C3=BCller?= Date: Thu, 4 Aug 2022 21:20:04 +0200 Subject: [PATCH] code cleanup: be more strict MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jens Müller --- src/ccScmProvider.ts | 75 +++++++++++++++++++------------------------- src/ccScmResource.ts | 4 +-- src/clearcase.ts | 16 +++++----- tsconfig.json | 49 ++++++++++++++++------------- 4 files changed, 71 insertions(+), 73 deletions(-) diff --git a/src/ccScmProvider.ts b/src/ccScmProvider.ts index f2a7715..dfcdbc0 100644 --- a/src/ccScmProvider.ts +++ b/src/ccScmProvider.ts @@ -64,7 +64,7 @@ export class CCScmProvider { private mDisposables: Disposable[], private outputChannel: OutputChannel, private configHandler: CCConfigHandler - ) {} + ) { } public async init(): Promise { this.mListLock = new Lock(1); @@ -187,29 +187,30 @@ export class CCScmProvider { if (this.mListLock?.reserve()) { try { version = this.clearCase ? await this.clearCase.getVersionInformation(fileObj) : ""; - let changed: boolean[] = [false, false]; - let filteredUntracked: CCScmResource[] = []; - let filteredCheckedout: CCScmResource[] = this.mCCCheckedoutGrp?.resourceStates.filter((val, index) => { - if (val.resourceUri.fsPath !== fileObj.fsPath) { - return val; - } else { - changed[0] = true; - } - }) as CCScmResource[]; - if (changed[0] === false) { + let checkoutsChanged = false; + let untrackedChanged = false; + let filteredUntracked: SourceControlResourceState[] = []; + let filteredCheckedout = this.mCCCheckedoutGrp?.resourceStates.filter(item => { + if (item.resourceUri.fsPath !== fileObj.fsPath) + return true; + + checkoutsChanged = true; + return false; + }) || []; + if (checkoutsChanged === false) { filteredUntracked = - (this.mCCUntrackedGrp?.resourceStates.filter((val, index) => { - if (val.resourceUri.fsPath !== fileObj.fsPath) { - return val; - } else { - changed[1] = true; - } - }) as CCScmResource[]) || []; + (this.mCCUntrackedGrp?.resourceStates.filter(item => { + if (item.resourceUri.fsPath !== fileObj.fsPath) + return true; + + untrackedChanged = true; + return false; + })) || []; } // file is checked out, add to resource state list if (version.match(/checkedout/i) !== null) { filteredCheckedout?.push(new CCScmResource(ResourceGroupType.index, fileObj, CCScmStatus.modified)); - changed[0] = true; + checkoutsChanged = true; } // file has no version information, so it is view private if (version === "" && this.clearCase !== null) { @@ -220,15 +221,15 @@ export class CCScmProvider { let ign = this.mIgnores?.getFolderIgnore(path.dirname(fileObj.fsPath)); if (ign !== null && ign?.ignore.ignores(fileObj.fsPath) === false) { filteredUntracked.push(new CCScmResource(ResourceGroupType.index, fileObj, CCScmStatus.untracked)); - changed[1] = true; + untrackedChanged = true; } } - if (changed[0]) { + if (checkoutsChanged) { if (this.mCCCheckedoutGrp !== null) { this.mCCCheckedoutGrp.resourceStates = filteredCheckedout?.sort(CCScmResource.sort) || []; } } - if (changed[1]) { + if (untrackedChanged) { if (this.mCCUntrackedGrp !== null) { this.mCCUntrackedGrp.resourceStates = filteredUntracked?.sort(CCScmResource.sort) || []; } @@ -247,18 +248,12 @@ export class CCScmProvider { public async handleDeleteFiles(fileObj: Uri) { if (this.mCCCheckedoutGrp !== null && this.mCCUntrackedGrp) { - let filtered = this.mCCCheckedoutGrp.resourceStates.filter((val) => { - if (val.resourceUri.fsPath !== fileObj.fsPath) { - return val; - } - }); - this.mCCCheckedoutGrp.resourceStates = filtered; - filtered = this.mCCUntrackedGrp.resourceStates.filter((val) => { - if (val.resourceUri.fsPath !== fileObj.fsPath) { - return val; - } - }); - this.mCCUntrackedGrp.resourceStates = filtered; + this.mCCCheckedoutGrp.resourceStates = this.mCCCheckedoutGrp.resourceStates + .filter(item => item.resourceUri.fsPath !== fileObj.fsPath); + + this.mCCUntrackedGrp.resourceStates = this.mCCUntrackedGrp.resourceStates + .filter(item => item.resourceUri.fsPath !== fileObj.fsPath); + } } @@ -320,15 +315,11 @@ export class CCScmProvider { let root = this.root; if (root !== undefined) { let ign = this.mIgnores?.getFolderIgnore(root); - let d = this.clearCase?.untrackedList.getStringsByKey(root?.fsPath)?.filter((val) => { + let d = this.clearCase?.untrackedList.getStringsByKey(root?.fsPath)?.filter(item => // if no .ccignore file is present, show all files - if ( - root !== undefined && - (ign === undefined || (val !== "" && ign?.ignore.ignores(path.relative(root.fsPath, val)) === false)) - ) { - return val; - } - }); + root !== undefined && + (ign === undefined || (item !== "" && ign?.ignore.ignores(path.relative(root.fsPath, item)) === false)) + ); if (d !== undefined) { viewPrv = viewPrv.concat( d.map((val) => { diff --git a/src/ccScmResource.ts b/src/ccScmResource.ts index ee7e0a0..3332110 100644 --- a/src/ccScmResource.ts +++ b/src/ccScmResource.ts @@ -27,7 +27,7 @@ export class CCScmResource implements SourceControlResourceState { }; } - constructor(private mResourceGrpType: ResourceGroupType, private mResourceUri: Uri, private mType: CCScmStatus) {} + constructor(private mResourceGrpType: ResourceGroupType, private mResourceUri: Uri, private mType: CCScmStatus) { } get type(): CCScmStatus { return this.mType; @@ -69,7 +69,7 @@ export class CCScmResource implements SourceControlResourceState { return { strikeThrough, faded, tooltip, light, dark }; } - public static sort(a: CCScmResource, b: CCScmResource) { + public static sort(a: SourceControlResourceState, b: SourceControlResourceState) { if (a.resourceUri.fsPath < b.resourceUri.fsPath) { return -1; } diff --git a/src/clearcase.ts b/src/clearcase.ts index 99575a6..2297539 100644 --- a/src/clearcase.ts +++ b/src/clearcase.ts @@ -318,7 +318,7 @@ export class ClearCase { await this.runCleartoolCommand( cmd, dirname(path), - (data: string[]) => {}, + (data: string[]) => { }, (finish: string) => { this.mUpdateEvent.fire(doc); } @@ -341,7 +341,7 @@ export class ClearCase { try { await doc.save(); this.mUpdateEvent.fire(doc.uri); - } catch (error) {} + } catch (error) { } } else { window.showErrorMessage("Could not save file."); } @@ -364,7 +364,7 @@ export class ClearCase { await this.runCleartoolCommand( new CCArgs(["unco", rm], path), dirname(path), - (data: string[]) => {}, + (data: string[]) => { }, (finish: string) => { this.mUpdateEvent.fire(doc); } @@ -377,7 +377,7 @@ export class ClearCase { await this.runCleartoolCommand( new CCArgs(["mkelem", "-mkp", "-nc"], path), dirname(path), - (data: string[]) => {}, + (data: string[]) => { }, (finish: string) => { this.mUpdateEvent.fire(doc); } @@ -436,7 +436,7 @@ export class ClearCase { await this.runCleartoolCommand( cmd, dirname(path), - (data: string[]) => {}, + (data: string[]) => { }, (finish: string) => { this.mUpdateEvent.fire(doc); } @@ -561,7 +561,7 @@ export class ClearCase { await this.runCleartoolCommand( cmd, workspace.workspaceFolders[0].uri.fsPath, - (data) => {}, + (data) => { }, (finishRes: string) => { if (finishRes === "error") { result = false; @@ -889,7 +889,7 @@ export class ClearCase { await this.runCleartoolCommand( new CCArgs(["get", "-to", tempFile], fsPath, version), workspace.workspaceFolders[0].uri.fsPath, - (data: string[]) => {}, + (data: string[]) => { }, (result: string) => { console.log(result); }, @@ -1050,7 +1050,7 @@ export class ClearCase { */ public async runClearTooledcs(baseFolder: string): Promise { let executable = this.configHandler.configuration.executable.value; - process.env.VISUAL = "code -r"; + process.env['VISUAL'] = "code -r"; var options = { cwd: baseFolder, env: process.env, diff --git a/tsconfig.json b/tsconfig.json index b65c745..6ce3c87 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,21 +1,28 @@ -{ - "compilerOptions": { - "module": "commonjs", - "target": "es6", - "outDir": "out", - "lib": [ - "es6" - ], - "sourceMap": true, - "rootDir": "src", - "strict": true /* enable all strict type-checking options */ - /* Additional Checks */ - // "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */ - // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */ - // "noUnusedParameters": true, /* Report errors on unused parameters. */ - }, - "exclude": [ - "node_modules", - ".vscode-test" - ] -} +{ + "compilerOptions": { + "module": "commonjs", + "target": "es2020", + "outDir": "out", + "lib": [ + "es2020" + ], + "sourceMap": true, + "rootDir": "src", + "strict": true, /* enable all strict type-checking options */ + /* Additional Checks */ + // "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */ + // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */ + // "noUnusedParameters": true, /* Report errors on unused parameters. */ + "noImplicitOverride": true, + "noPropertyAccessFromIndexSignature": true, + "noImplicitReturns": true, + "noFallthroughCasesInSwitch": true, + "declaration": false, + "downlevelIteration": true, + "experimentalDecorators": true, + }, + "exclude": [ + "node_modules", + ".vscode-test" + ] +} \ No newline at end of file