Skip to content

Commit

Permalink
code cleanup: be more strict
Browse files Browse the repository at this point in the history
Signed-off-by: Jens Müller <tschenser@gmx.de>
  • Loading branch information
jmue committed Aug 4, 2022
1 parent b991b11 commit 2e39325
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 73 deletions.
75 changes: 33 additions & 42 deletions src/ccScmProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export class CCScmProvider {
private mDisposables: Disposable[],
private outputChannel: OutputChannel,
private configHandler: CCConfigHandler
) {}
) { }

public async init(): Promise<boolean> {
this.mListLock = new Lock(1);
Expand Down Expand Up @@ -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) {
Expand All @@ -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) || [];
}
Expand All @@ -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);

}
}

Expand Down Expand Up @@ -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) => {
Expand Down
4 changes: 2 additions & 2 deletions src/ccScmResource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
16 changes: 8 additions & 8 deletions src/clearcase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ export class ClearCase {
await this.runCleartoolCommand(
cmd,
dirname(path),
(data: string[]) => {},
(data: string[]) => { },
(finish: string) => {
this.mUpdateEvent.fire(doc);
}
Expand All @@ -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.");
}
Expand All @@ -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);
}
Expand All @@ -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);
}
Expand Down Expand Up @@ -436,7 +436,7 @@ export class ClearCase {
await this.runCleartoolCommand(
cmd,
dirname(path),
(data: string[]) => {},
(data: string[]) => { },
(finish: string) => {
this.mUpdateEvent.fire(doc);
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
},
Expand Down Expand Up @@ -1050,7 +1050,7 @@ export class ClearCase {
*/
public async runClearTooledcs(baseFolder: string): Promise<ChildProcess> {
let executable = this.configHandler.configuration.executable.value;
process.env.VISUAL = "code -r";
process.env['VISUAL'] = "code -r";
var options = {
cwd: baseFolder,
env: process.env,
Expand Down
49 changes: 28 additions & 21 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -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"
]
}

0 comments on commit 2e39325

Please sign in to comment.