Skip to content

Commit e1de4d1

Browse files
author
ole1986
committed
typescript hygiene
1 parent a932c2c commit e1de4d1

File tree

26 files changed

+82
-93
lines changed

26 files changed

+82
-93
lines changed

src/adapter/avatar/github.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -85,19 +85,20 @@ export class GithubAvatarProvider extends BaseAvatarProvider implements IAvatarP
8585
}
8686
protected async getAvatarsImplementation(repository: IGitService): Promise<Avatar[]> {
8787
const remoteUrl = await repository.getOriginUrl();
88-
const remoteRepoPath = remoteUrl.replace(/.*?github.com\//,'');
88+
const remoteRepoPath = remoteUrl.replace(/.*?github.com\//, '');
8989
const remoteRepoWithNoGitSuffix = remoteRepoPath.replace(/\.git\/?$/, '');
9090
const contributors = await this.getContributors(remoteRepoWithNoGitSuffix);
9191

9292
const githubUsers = await Promise.all(contributors.map(async user => {
93-
const u = await this.getUserByLogin(user.login);
94-
return u;
93+
return await this.getUserByLogin(user.login);
9594
}));
9695

9796
let avatars : Avatar[] = [];
9897

9998
githubUsers.forEach(user => {
100-
if(!user) return;
99+
if (!user) {
100+
return;
101+
}
101102
avatars.push({
102103
login: user.login,
103104
name: user.name,
@@ -111,15 +112,15 @@ export class GithubAvatarProvider extends BaseAvatarProvider implements IAvatarP
111112
}
112113
/**
113114
* Fetch the user details through Github API
114-
* @param loginName
115+
* @param loginName the user login name from github
115116
*/
116117
private async getUserByLogin(loginName: string) {
117118
const key = `GitHub:User:${loginName}`;
118119

119120
const cachedUser = await this.stateStore.get<GithubUserResponse>(key);
120121
let headers = {};
121122

122-
if(cachedUser) {
123+
if (cachedUser) {
123124
// Use GitHub API with conditional check on last modified
124125
// to avoid API request rate limitation
125126
headers = {'If-Modified-Since': cachedUser.last_modified};
@@ -138,8 +139,8 @@ export class GithubAvatarProvider extends BaseAvatarProvider implements IAvatarP
138139
// can either be '302 Not Modified' or any other error
139140
// in case of '302 Not Modified' this API request is not counted and returns nothing
140141
});
141-
142-
if(info) {
142+
143+
if (info) {
143144
await this.stateStore.set(key, info);
144145
return info;
145146
} else {
@@ -153,10 +154,9 @@ export class GithubAvatarProvider extends BaseAvatarProvider implements IAvatarP
153154
*/
154155
private async getContributors(repoPath: string) {
155156
const proxy = this.proxy;
156-
const info = await axios.get(`https://api.github.com/repos/${repoPath}/contributors`, { proxy })
157+
return axios.get(`https://api.github.com/repos/${repoPath}/contributors`, { proxy })
157158
.then((result: { data: GithubUserSearchResponseItem[] }) => {
158159
return result.data;
159160
});
160-
return info;
161161
}
162162
}

src/adapter/avatar/gravatar.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export class GravatarAvatarProvider extends BaseAvatarProvider implements IAvata
2121
avatarUrl: gravatar.url(user.email),
2222
name: user.name,
2323
email: user.email
24-
}
24+
};
2525
});
2626
}
2727
}

src/adapter/exec/gitCommandExec.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,18 @@ import * as iconv from 'iconv-lite';
33
import { injectable, multiInject } from 'inversify';
44
import { Writable } from 'stream';
55
import { Disposable, extensions } from 'vscode';
6+
import { IGitCommandExecutor } from './types';
67
import { GitExtension } from '../repository/git.d';
78
import { StopWatch } from '../../common/stopWatch';
89
import { ILogService } from '../../common/types';
9-
import { IGitCommandExecutor } from './types';
10-
1110

1211
const DEFAULT_ENCODING = 'utf8';
1312
const isWindows = /^win/.test(process.platform);
1413

1514
@injectable()
1615
export class GitCommandExecutor implements IGitCommandExecutor {
17-
public gitExtension : GitExtension;
18-
private gitExecutablePath : string;
16+
public gitExtension: GitExtension;
17+
private gitExecutablePath: string;
1918

2019
constructor(@multiInject(ILogService) private loggers: ILogService[]) {
2120
this.gitExtension = extensions.getExtension<GitExtension>('vscode.git')!.exports;
@@ -36,7 +35,7 @@ export class GitCommandExecutor implements IGitCommandExecutor {
3635
childProcOptions.encoding = DEFAULT_ENCODING;
3736
}
3837
const binaryOuput = childProcOptions.encoding === 'binary';
39-
const destination: Writable = binaryOuput ? args.shift()! : undefined;
38+
const destination: Writable = binaryOuput ? args.shift() : undefined;
4039
const gitPathCommand = childProcOptions.shell && gitPath.indexOf(' ') > 0 ? `"${gitPath}"` : gitPath;
4140
const stopWatch = new StopWatch();
4241
const gitShow = spawn(gitPathCommand, args, childProcOptions);

src/adapter/parsers/fileStat/parser.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export class FileStatParser implements IFileStatParser {
1010
constructor( @inject(IServiceContainer) private serviceContainer: IServiceContainer) {
1111
}
1212

13-
private static parseFileMovement(fileInfo: string): { original: string, current: string } | undefined {
13+
private static parseFileMovement(fileInfo: string): { original: string; current: string } | undefined {
1414
// src/client/{common/comms => }/Socket Stream.ts
1515
// src/client/common/{space in folder => comms}/id Dispenser.ts
1616
// src/client/common/space in folder/{idDispenser.ts => id Dispenser.ts}
@@ -67,13 +67,11 @@ export class FileStatParser implements IFileStatParser {
6767

6868
/**
6969
* Parses a line containing file information returned by `git log --name-stat` and returns just the file names
70-
* @private
71-
* @static
7270
* @param {string} line
7371
* @returns {({ original?: string, current: string } | undefined)}
7472
* @memberof FileStatParser
7573
*/
76-
private static getNewAndOldFileNameFromNumStatLine(line: string, status: Status): { original?: string, current: string } | undefined {
74+
private static getNewAndOldFileNameFromNumStatLine(line: string, status: Status): { original?: string; current: string } | undefined {
7775
const statusParts = line.split('\t');
7876
const fileName = statusParts[1].trim();
7977
if (status === Status.Renamed || status === Status.Copied) {
@@ -84,8 +82,6 @@ export class FileStatParser implements IFileStatParser {
8482

8583
/**
8684
* Parses a line containing file information returned by `git log --numstat`
87-
* @private
88-
* @static
8985
* @param {string} line
9086
* @returns {({ additions?: number, deletions?: number } | undefined)}
9187
* @memberof FileStatParser
@@ -108,8 +104,7 @@ export class FileStatParser implements IFileStatParser {
108104
* Parsers the file status
109105
* @param {string[]} filesWithNumStat Files returned using `git log --numstat`
110106
* @param {string[]} filesWithNameStat Files returned using `git log --name-status`
111-
* @returns {CommittedFile[]}
112-
* @memberof FileStatParser
107+
* @returns {CommittedFile[]} An array of committed files
113108
*/
114109
public parse(gitRootPath: string, filesWithNumStat: string[], filesWithNameStat: string[]): CommittedFile[] {
115110
return filesWithNameStat.map((line, index) => {
@@ -142,7 +137,6 @@ export class FileStatParser implements IFileStatParser {
142137
uri: Uri.file(path.join(gitRootPath, relativePath)),
143138
oldUri
144139
};
145-
146140
// uri.fsPath getter sporadically becomes a slash as prefix (E.g "/z:/folder/subfolder").
147141
// By fetching fsPath through the getter, the internal method _makeFsPath(this) immediate get called here
148142
// and the fsPath is set correctly.

src/adapter/parsers/refs/parser.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,8 @@ export class RefsParser implements IRefsParser {
1818
* git branch --all (only considers)
1919
* git show-refs
2020
* git log --format=%D
21-
* @param {string} refContent
22-
* @returns {Ref[]}
23-
* @memberof RefParser
21+
* @param {string} refContent the ref content as string to be parsed
22+
* @returns {Ref[]} A reference which can either be a branch, tag or origin
2423
*/
2524
public parse(refContent: string): Ref[] {
2625
return (refContent || '').split(',')

src/adapter/repository/git.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,4 +240,4 @@ export const enum GitErrorCodes {
240240
PatchDoesNotApply = 'PatchDoesNotApply',
241241
NoPathFound = 'NoPathFound',
242242
UnknownPath = 'UnknownPath',
243-
}
243+
}

src/adapter/repository/git.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ export class Git implements IGitService {
172172
} else if (url.indexOf('visualstudio') > 0) {
173173
return GitOriginType.vsts;
174174
}
175-
175+
176176
return undefined;
177177
}
178178
@cache('IGitService')
@@ -397,8 +397,8 @@ export class Git implements IGitService {
397397
const hashes = output.split(/\r?\n/g).filter(item => item.length > 0)[0].split('-');
398398

399399
return {
400-
short: hashes[1]!,
401-
full: hashes[0]!
400+
short: hashes[1],
401+
full: hashes[0]
402402
};
403403
}
404404

src/adapter/repository/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,5 @@ export enum GitOriginType {
3333
github = 2,
3434
bitbucket = 3,
3535
tfs = 4,
36-
vsts = 5,
36+
vsts = 5
3737
}

src/application/stateStore.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,19 @@ import { Memento } from 'vscode';
33
import { IServiceContainer } from '../ioc/types';
44
import { IStateStore, IStateStoreFactory } from './types/stateStore';
55

6+
export class WorkspaceMementoStore implements IStateStore {
7+
constructor(private store: Memento) { }
8+
public has(key: string): boolean {
9+
return this.store.get(key) !== undefined;
10+
}
11+
public async set<T>(key: string, data: T): Promise<void> {
12+
await this.store.update(key, data);
13+
}
14+
public async get<T>(key: string): Promise<T | undefined> {
15+
return this.store.get(key);
16+
}
17+
}
18+
619
@injectable()
720
export class WorkspaceStateStoreFactory implements IStateStoreFactory {
821
constructor( @inject(IServiceContainer) private serviceContainer: IServiceContainer) { }
@@ -20,16 +33,3 @@ export class GlobalStateStoreFactory implements IStateStoreFactory {
2033
return new WorkspaceMementoStore(this.serviceContainer.get<Memento>('globalMementoStore'));
2134
}
2235
}
23-
24-
export class WorkspaceMementoStore implements IStateStore {
25-
constructor(private store: Memento) { }
26-
public has(key: string): boolean {
27-
return this.store.get(key) !== undefined;
28-
}
29-
public async set<T>(key: string, data: T): Promise<void> {
30-
await this.store.update(key, data);
31-
}
32-
public async get<T>(key: string): Promise<T | undefined> {
33-
return this.store.get(key);
34-
}
35-
}

src/commandHandlers/commit/compare.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export class GitCompareCommitCommandHandler implements IGitCompareCommandHandler
3737
// display explorer view when running compare
3838
await this.commandManager.executeCommand('workbench.view.explorer');
3939
const gitService = await this.serviceContainer.get<IGitServiceFactory>(IGitServiceFactory).createGitService(commit.workspaceFolder, commit.logEntry.gitRoot);
40-
const fileDiffs = await gitService.getDifferences(this.selectedCommit!.logEntry.hash.full, commit.logEntry.hash.full);
40+
const fileDiffs = await gitService.getDifferences(this.selectedCommit.logEntry.hash.full, commit.logEntry.hash.full);
4141
const compareCommit = new CompareCommitDetails(this.selectedCommit, commit, fileDiffs);
4242
this.commitViewerFactory.getCompareCommitViewer().showCommitTree(compareCommit);
4343
}

0 commit comments

Comments
 (0)