From 6fe45780dfd78d06c0905bf1ad8bb7b4880295c7 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Fri, 7 Apr 2017 11:15:31 -0400 Subject: [PATCH] Additional changes for linter (#167) * Additional changes for linter * Initial values of Git and Wit should be '-' and not '0' * Ensure at least 1 change for UndoAll --- src/clients/gitclient.ts | 19 ++++++------ src/clients/teamservicesclient.ts | 4 +-- src/clients/witclient.ts | 21 +++++++------ src/helpers/strings.ts | 1 + src/services/gitvc.ts | 6 ++-- src/services/workitemtracking.ts | 6 ++-- src/team-extension.ts | 6 ++-- src/tfvc/commands/add.ts | 4 +-- src/tfvc/commands/commandhelper.ts | 2 +- src/tfvc/commands/getinfo.ts | 2 +- src/tfvc/commands/sync.ts | 4 +-- src/tfvc/commands/undo.ts | 2 +- src/tfvc/scm/commithoverprovider.ts | 10 +++--- src/tfvc/scm/model.ts | 14 ++++----- src/tfvc/scm/resource.ts | 2 +- src/tfvc/scm/tfvccontentprovider.ts | 2 +- src/tfvc/tfcommandlinerunner.ts | 8 ++--- src/tfvc/tfvc-extension.ts | 19 +++++++----- src/tfvc/tfvcscmprovider.ts | 31 +++++++++++++------ src/tfvc/util.ts | 12 +++---- .../services/build.integration.test.ts | 6 ++-- .../services/gitvc.integration.test.ts | 8 ++--- .../workitemtracking.integration.test.ts | 6 ++-- test/contexts/contexthelper.ts | 2 +- test/contexts/externalcontext.test.ts | 4 +-- test/contexts/gitcontext.test.ts | 2 +- test/helpers/logger.test.ts | 2 +- test/helpers/repoutils.test.ts | 2 +- test/helpers/utils.test.ts | 4 +-- test/services/build.test.ts | 2 +- test/services/gitvc.test.ts | 2 +- test/services/workitemtracking.test.ts | 2 +- test/tfvc/scm/status.test.ts | 2 +- test/tfvc/tfvcerror.test.ts | 4 +-- test/tfvc/tfvcversion.test.ts | 2 +- tslint.json | 9 ++++++ 36 files changed, 129 insertions(+), 105 deletions(-) diff --git a/src/clients/gitclient.ts b/src/clients/gitclient.ts index 6eeff65bc..2655a86ee 100644 --- a/src/clients/gitclient.ts +++ b/src/clients/gitclient.ts @@ -118,7 +118,7 @@ export class GitClient extends BaseClient { let requests: BaseQuickPickItem[] = await this.getMyPullRequests(); this._statusBarItem.tooltip = Strings.BrowseYourPullRequests; //Remove the default Strings.BrowseYourPullRequests item from the calculation - this._statusBarItem.text = GitClient.GetPullRequestStatusText(requests.length - 1); + this._statusBarItem.text = GitClient.GetPullRequestStatusText((requests.length - 1).toString()); } catch (err) { this.handleError(err, GitClient.GetOfflinePullRequestStatusText(), true, "Attempting to poll my pull requests"); } @@ -135,7 +135,7 @@ export class GitClient extends BaseClient { let label: string = `$(icon ${icon}) `; requestItems.push({ label: label + Strings.BrowseYourPullRequests, description: undefined, id: undefined }); - myPullRequests.forEach(pr => { + myPullRequests.forEach((pr) => { let score: PullRequestScore = GitVcService.GetPullRequestScore(pr); requestItems.push(this.getPullRequestLabel(pr.createdBy.displayName, pr.title, pr.description, pr.pullRequestId.toString(), score)); requestIds.push(pr.pullRequestId); @@ -145,7 +145,7 @@ export class GitClient extends BaseClient { Logger.LogInfo("Getting pull requests for which I'm a reviewer..."); //Go get the active pull requests that I'm a reviewer for let myReviewPullRequests: GitPullRequest[] = await svc.GetPullRequests(this._serverContext.RepoInfo.RepositoryId, undefined, this._serverContext.UserInfo.Id, PullRequestStatus.Active); - myReviewPullRequests.forEach(pr => { + myReviewPullRequests.forEach((pr) => { let score: PullRequestScore = GitVcService.GetPullRequestScore(pr); if (requestIds.indexOf(pr.pullRequestId) < 0) { requestItems.push(this.getPullRequestLabel(pr.createdBy.displayName, pr.title, pr.description, pr.pullRequestId.toString(), score)); @@ -154,7 +154,7 @@ export class GitClient extends BaseClient { Logger.LogInfo("Retrieved " + myReviewPullRequests.length + " pull requests that I'm the reviewer"); //Remove the default Strings.BrowseYourPullRequests item from the calculation - this._statusBarItem.text = GitClient.GetPullRequestStatusText(requestItems.length - 1); + this._statusBarItem.text = GitClient.GetPullRequestStatusText((requestItems.length - 1).toString()); this._statusBarItem.tooltip = Strings.BrowseYourPullRequests; this._statusBarItem.command = CommandNames.GetPullRequests; @@ -178,14 +178,15 @@ export class GitClient extends BaseClient { } public static GetOfflinePullRequestStatusText() : string { - return `$(icon octicon-git-pull-request) ` + `???`; + return `$(icon octicon-git-pull-request) ???`; } //Sets the text on the pull request status bar - public static GetPullRequestStatusText(total: number) : string { - let octipullrequest: string = "octicon-git-pull-request"; - - return `$(icon ${octipullrequest}) ` + total.toString(); + public static GetPullRequestStatusText(total?: string) : string { + if (!total) { + return `$(icon octicon-git-pull-request) $(icon octicon-dash)`; + } + return `$(icon octicon-git-pull-request) ${total.toString()}`; } //Ensure that we don't accidentally send non-Git (e.g., TFVC) contexts to the Git client diff --git a/src/clients/teamservicesclient.ts b/src/clients/teamservicesclient.ts index 64a737e11..7f463f9df 100644 --- a/src/clients/teamservicesclient.ts +++ b/src/clients/teamservicesclient.ts @@ -16,7 +16,7 @@ export class TeamServicesApi extends basem.ClientApiBase { //Create an instance of Promise since we're calling a function with the callback pattern but want to return a Promise let promise: Promise = new Promise((resolve, reject) => { /* tslint:disable:no-null-keyword */ - this.restClient.getJson(this.vsoClient.resolveUrl("/vsts/info"), "", null, null, function(err: any, statusCode: number, obj: any) { + this.restClient.getJson(this.vsoClient.resolveUrl("/vsts/info"), "", null, null, (err: any, statusCode: number, obj: any) => { /* tslint:enable:no-null-keyword */ if (err) { err.statusCode = statusCode; @@ -34,7 +34,7 @@ export class TeamServicesApi extends basem.ClientApiBase { //Create an instance of Promise since we're calling a function with the callback pattern but want to return a Promise let promise: Promise = new Promise((resolve, reject) => { /* tslint:disable:no-null-keyword */ - this.restClient.getJson(this.vsoClient.resolveUrl("_apis/tfvc/branches"), "", null, null, function(err: any, statusCode: number, obj: any) { + this.restClient.getJson(this.vsoClient.resolveUrl("_apis/tfvc/branches"), "", null, null, (err: any, statusCode: number, obj: any) => { /* tslint:enable:no-null-keyword */ if (err) { err.statusCode = statusCode; diff --git a/src/clients/witclient.ts b/src/clients/witclient.ts index 244d11ec2..656e6f1fe 100644 --- a/src/clients/witclient.ts +++ b/src/clients/witclient.ts @@ -172,7 +172,7 @@ export class WitClient extends BaseClient { Logger.LogInfo("Getting my work item queries (" + this._serverContext.RepoInfo.TeamProject + ")..."); let hierarchyItems: QueryHierarchyItem[] = await svc.GetWorkItemHierarchyItems(this._serverContext.RepoInfo.TeamProject); Logger.LogInfo("Retrieved " + hierarchyItems.length + " hierarchyItems"); - hierarchyItems.forEach(folder => { + hierarchyItems.forEach((folder) => { if (folder && folder.isFolder === true && folder.isPublic === false) { // Because "My Queries" is localized and there is no API to get the name of the localized // folder, we need to save off the localized name when constructing URLs. @@ -199,7 +199,7 @@ export class WitClient extends BaseClient { Logger.LogInfo("Getting my work items (" + this._serverContext.RepoInfo.TeamProject + ")..."); let simpleWorkItems: SimpleWorkItem[] = await svc.GetWorkItems(teamProject, wiql); Logger.LogInfo("Retrieved " + simpleWorkItems.length + " work items"); - simpleWorkItems.forEach(wi => { + simpleWorkItems.forEach((wi) => { workItems.push({ label: wi.label, description: wi.description, id: wi.id}); }); if (simpleWorkItems.length === WorkItemTrackingService.MaxResults) { @@ -229,7 +229,7 @@ export class WitClient extends BaseClient { let svc: WorkItemTrackingService = new WorkItemTrackingService(this._serverContext); let types: WorkItemType[] = await svc.GetWorkItemTypes(this._serverContext.RepoInfo.TeamProject); let workItemTypes: BaseQuickPickItem[] = []; - types.forEach(type => { + types.forEach((type) => { workItemTypes.push({ label: type.name, description: type.description, id: undefined }); }); workItemTypes.sort((t1, t2) => { @@ -252,21 +252,22 @@ export class WitClient extends BaseClient { } public PollPinnedQuery(): void { - this.GetPinnedQueryResultCount().then((items) => { + this.GetPinnedQueryResultCount().then((numberOfItems) => { this._statusBarItem.tooltip = Strings.ViewYourPinnedQuery; - this._statusBarItem.text = WitClient.GetPinnedQueryStatusText(items); + this._statusBarItem.text = WitClient.GetPinnedQueryStatusText(numberOfItems.toString()); }).catch((err) => { this.handleError(err, WitClient.GetOfflinePinnedQueryStatusText(), true, "Failed to get pinned query count during polling"); }); } public static GetOfflinePinnedQueryStatusText() : string { - return `$(icon octicon-bug) ` + `???`; + return `$(icon octicon-bug) ???`; } - public static GetPinnedQueryStatusText(total: number) : string { - let octibug: string = "octicon-bug"; - - return `$(icon ${octibug}) ` + total.toString(); + public static GetPinnedQueryStatusText(total?: string) : string { + if (!total) { + return `$(icon octicon-bug) $(icon octicon-dash)`; + } + return `$(icon octicon-bug) ${total.toString()}`; } } diff --git a/src/helpers/strings.ts b/src/helpers/strings.ts index cb65f12f3..a7f01b040 100644 --- a/src/helpers/strings.ts +++ b/src/helpers/strings.ts @@ -68,6 +68,7 @@ export class Strings { static TfNoPendingChanges: string = "There are no matching pending changes."; static UndoChanges: string = "Undo Changes"; static NoChangesToCheckin: string = "There are no changes to check in. Changes must be added to the 'Included' section to be checked in."; + static NoChangesToUndo: string = "There are no changes to undo."; static AllFilesUpToDate: string = "All files are up to date."; static CommandRequiresFileContext: string = "This command requires a file context and can only be executed from the TFVC viewlet window."; static CommandRequiresExplorerContext: string = "This command requires a file context and can only be executed from the Explorer window."; diff --git a/src/services/gitvc.ts b/src/services/gitvc.ts index e2c048fd3..007173629 100644 --- a/src/services/gitvc.ts +++ b/src/services/gitvc.ts @@ -24,7 +24,7 @@ export class GitVcService { this._gitApi = new WebApi(context.RepoInfo.CollectionUrl, CredentialManager.GetCredentialHandler()).getGitApi(); } - //Returns a Q.Promise containing an array of GitPullRequest objectss for the creator and repository + //Returns a Promise containing an array of GitPullRequest objectss for the creator and repository //If creatorId is undefined, all pull requests will be returned public async GetPullRequests(repositoryId: string, creatorId?: string, reviewerId?: string, status?: PullRequestStatus) : Promise { let criteria: GitPullRequestSearchCriteria = { creatorId: creatorId, includeLinks: false, repositoryId: repositoryId, reviewerId: reviewerId, @@ -32,7 +32,7 @@ export class GitVcService { return await this._gitApi.getPullRequests(repositoryId, criteria); } - //Returns a Q.Promise containing an array of GitRepository objects for the project + //Returns a Promise containing an array of GitRepository objects for the project public async GetRepositories(project: string): Promise { return await this._gitApi.getRepositories(project, false); } @@ -96,7 +96,7 @@ export class GitVcService { let lowestVote: number = 0; let highestVote: number = 0; if (pullRequest.reviewers !== undefined && pullRequest.reviewers.length > 0) { - pullRequest.reviewers.forEach(reviewer => { + pullRequest.reviewers.forEach((reviewer) => { let vote: number = reviewer.vote; if (vote < lowestVote) { lowestVote = vote; diff --git a/src/services/workitemtracking.ts b/src/services/workitemtracking.ts index 6462592b3..4b1fb11d4 100644 --- a/src/services/workitemtracking.ts +++ b/src/services/workitemtracking.ts @@ -48,11 +48,11 @@ export class WorkItemTrackingService { let types: WorkItemType[] = await this._witApi.getWorkItemTypes(teamProject); let workItemTypes: WorkItemType[] = []; let hiddenTypes: WorkItemTypeReference[] = []; - types.forEach(type => { + types.forEach((type) => { workItemTypes.push(type); }); let category: WorkItemTypeCategory = await this._witApi.getWorkItemTypeCategory(teamProject, "Microsoft.HiddenCategory"); - category.workItemTypes.forEach(hiddenType => { + category.workItemTypes.forEach((hiddenType) => { hiddenTypes.push(hiddenType); }); let filteredTypes: WorkItemType[] = workItemTypes.filter(function (el) { @@ -111,7 +111,7 @@ export class WorkItemTrackingService { //Keep original sort order that wiql specified for (let index = 0; index < workItemIds.length; index++) { - let item: WorkItem = workItems.find(i => i.id === workItemIds[index]); + let item: WorkItem = workItems.find((i) => i.id === workItemIds[index]); results.push({ id: item.fields[WorkItemFields.Id], label: item.fields[WorkItemFields.Id] + " [" + item.fields[WorkItemFields.WorkItemType] + "]", diff --git a/src/team-extension.ts b/src/team-extension.ts index 44828abce..ec5ad39aa 100644 --- a/src/team-extension.ts +++ b/src/team-extension.ts @@ -318,7 +318,7 @@ export class TeamExtension { if (!this._pullRequestStatusBarItem) { this._pullRequestStatusBarItem = window.createStatusBarItem(StatusBarAlignment.Left, 99); this._pullRequestStatusBarItem.command = CommandNames.GetPullRequests; - this._pullRequestStatusBarItem.text = GitClient.GetPullRequestStatusText(0); + this._pullRequestStatusBarItem.text = GitClient.GetPullRequestStatusText(); this._pullRequestStatusBarItem.tooltip = Strings.BrowseYourPullRequests; this._pullRequestStatusBarItem.show(); } @@ -327,7 +327,7 @@ export class TeamExtension { if (!this._buildStatusBarItem) { this._buildStatusBarItem = window.createStatusBarItem(StatusBarAlignment.Left, 98); this._buildStatusBarItem.command = CommandNames.OpenBuildSummaryPage; - this._buildStatusBarItem.text = `$(icon octicon-package) ` + `$(icon octicon-dash)`; + this._buildStatusBarItem.text = `$(icon octicon-package) $(icon octicon-dash)`; this._buildStatusBarItem.tooltip = Strings.NoBuildsFound; this._buildStatusBarItem.show(); } @@ -335,7 +335,7 @@ export class TeamExtension { if (!this._pinnedQueryStatusBarItem) { this._pinnedQueryStatusBarItem = window.createStatusBarItem(StatusBarAlignment.Left, 97); this._pinnedQueryStatusBarItem.command = CommandNames.ViewPinnedQueryWorkItems; - this._pinnedQueryStatusBarItem.text = WitClient.GetPinnedQueryStatusText(0); + this._pinnedQueryStatusBarItem.text = WitClient.GetPinnedQueryStatusText(); this._pinnedQueryStatusBarItem.tooltip = Strings.ViewYourPinnedQuery; this._pinnedQueryStatusBarItem.show(); } diff --git a/src/tfvc/commands/add.ts b/src/tfvc/commands/add.ts index 26fbf3a7b..49593caaa 100644 --- a/src/tfvc/commands/add.ts +++ b/src/tfvc/commands/add.ts @@ -48,9 +48,9 @@ export class Add implements ITfvcCommand { let lines: string[] = CommandHelper.SplitIntoLines(executionResult.stdout, false, true /*filterEmptyLines*/); //Remove any lines indicating that there were no files to add (e.g., calling add on files that don't exist) - lines = lines.filter(e => !e.startsWith("No arguments matched any files to add.")); //CLC + lines = lines.filter((e) => !e.startsWith("No arguments matched any files to add.")); //CLC //Ex. /usr/alias/repos/Tfvc.L2VSCodeExtension.RC/file-does-not-exist.md: No file matches. - lines = lines.filter(e => !e.endsWith(" No file matches.")); //tf.exe + lines = lines.filter((e) => !e.endsWith(" No file matches.")); //tf.exe let filesAdded: string[] = []; let path: string = ""; diff --git a/src/tfvc/commands/commandhelper.ts b/src/tfvc/commands/commandhelper.ts index b72c32492..d17e2d6fd 100644 --- a/src/tfvc/commands/commandhelper.ts +++ b/src/tfvc/commands/commandhelper.ts @@ -123,7 +123,7 @@ export class CommandHelper { lines = lines.splice(index); } if (filterEmptyLines) { - lines = lines.filter(e => e.trim() !== ""); + lines = lines.filter((e) => e.trim() !== ""); } return lines; } diff --git a/src/tfvc/commands/getinfo.ts b/src/tfvc/commands/getinfo.ts index c4ab6f94e..4bb30c53b 100644 --- a/src/tfvc/commands/getinfo.ts +++ b/src/tfvc/commands/getinfo.ts @@ -101,7 +101,7 @@ export class GetInfo implements ITfvcCommand { // If all of the info objects are "empty" let's report an error if (itemInfos.length > 0 && - itemInfos.length === itemInfos.filter(info => info.localItem === undefined).length) { + itemInfos.length === itemInfos.filter((info) => info.localItem === undefined).length) { throw new TfvcError({ message: Strings.NoMatchesFound, tfvcErrorCode: TfvcErrorCodes.TfvcNoItemsMatch, diff --git a/src/tfvc/commands/sync.ts b/src/tfvc/commands/sync.ts index ede911034..7cf8d2335 100644 --- a/src/tfvc/commands/sync.ts +++ b/src/tfvc/commands/sync.ts @@ -84,8 +84,8 @@ export class Sync implements ITfvcCommand { const itemResults: ISyncItemResult[] = this.getItemResults(executionResult.stdout); const errorMessages: ISyncItemResult[] = this.getErrorMessages(executionResult.stderr); return { - hasConflicts: errorMessages.filter(err => err.syncType === SyncType.Conflict).length > 0, - hasErrors: errorMessages.filter(err => err.syncType !== SyncType.Conflict).length > 0, + hasConflicts: errorMessages.filter((err) => err.syncType === SyncType.Conflict).length > 0, + hasErrors: errorMessages.filter((err) => err.syncType !== SyncType.Conflict).length > 0, itemResults: itemResults.concat(errorMessages) }; } diff --git a/src/tfvc/commands/undo.ts b/src/tfvc/commands/undo.ts index 351699dd2..5d543c414 100644 --- a/src/tfvc/commands/undo.ts +++ b/src/tfvc/commands/undo.ts @@ -56,7 +56,7 @@ export class Undo implements ITfvcCommand { //Otherwise, we assume some error occurred so let that be thrown. if (executionResult.exitCode !== 0) { //Remove any entries for which there were no pending changes - lines = lines.filter(e => !e.startsWith("No pending changes ")); + lines = lines.filter((e) => !e.startsWith("No pending changes ")); if (executionResult.exitCode === 100 && lines.length === 0) { //All of the files had no pending changes, return [] return []; diff --git a/src/tfvc/scm/commithoverprovider.ts b/src/tfvc/scm/commithoverprovider.ts index 7f2cd0114..ccf4ee971 100644 --- a/src/tfvc/scm/commithoverprovider.ts +++ b/src/tfvc/scm/commithoverprovider.ts @@ -62,7 +62,7 @@ export class CommitHoverProvider implements HoverProvider { } private onVisibleTextEditors(editors: TextEditor[]): void { - const [editor] = editors.filter(e => isSCMInput(e.document.uri)); + const [editor] = editors.filter((e) => isSCMInput(e.document.uri)); if (!editor) { return; @@ -71,7 +71,7 @@ export class CommitHoverProvider implements HoverProvider { this.visibleTextEditorsDisposable.dispose(); this.editor = editor; - const onDidChange = filterEvent(workspace.onDidChangeTextDocument, e => e.document && isSCMInput(e.document.uri)); + const onDidChange = filterEvent(workspace.onDidChangeTextDocument, (e) => e.document && isSCMInput(e.document.uri)); onDidChange(this.update, this, this.disposables); workspace.onDidChangeConfiguration(this.update, this, this.disposables); @@ -81,12 +81,12 @@ export class CommitHoverProvider implements HoverProvider { private update(): void { this.diagnostics = []; //TODO provide any diagnostic info based on the message here (see git commitcontroller) - this.editor.setDecorations(this.decorationType, this.diagnostics.map(d => d.range)); + this.editor.setDecorations(this.decorationType, this.diagnostics.map((d) => d.range)); } /* Implement HoverProvider */ provideHover(document: TextDocument, position: Position): Hover | undefined { - const [decoration] = this.diagnostics.filter(d => d.range.contains(position)); + const [decoration] = this.diagnostics.filter((d) => d.range.contains(position)); if (!decoration || !document) { return; @@ -96,6 +96,6 @@ export class CommitHoverProvider implements HoverProvider { } dispose(): void { - this.disposables.forEach(d => d.dispose()); + this.disposables.forEach((d) => d.dispose()); } } diff --git a/src/tfvc/scm/model.ts b/src/tfvc/scm/model.ts index 0bc3660aa..01d459b9b 100644 --- a/src/tfvc/scm/model.ts +++ b/src/tfvc/scm/model.ts @@ -55,7 +55,7 @@ export class Model implements Disposable { public dispose() { if (this._disposables) { - this._disposables.forEach(d => d.dispose()); + this._disposables.forEach((d) => d.dispose()); this._disposables = []; } } @@ -104,7 +104,7 @@ export class Model implements Disposable { //Add the items to the explicitly excluded list. public async Exclude(paths: string[]): Promise { if (paths && paths.length > 0) { - paths.forEach(path => { + paths.forEach((path) => { let normalizedPath: string = path.toLowerCase(); if (!_.contains(this._explicitlyExcluded, normalizedPath)) { this._explicitlyExcluded.push(normalizedPath); @@ -117,7 +117,7 @@ export class Model implements Disposable { //Unexclude doesn't explicitly INclude. It defers to the status of the individual item. public async Unexclude(paths: string[]): Promise { if (paths && paths.length > 0) { - paths.forEach(path => { + paths.forEach((path) => { let normalizedPath: string = path.toLowerCase(); if (_.contains(this._explicitlyExcluded, normalizedPath)) { this._explicitlyExcluded = _.without(this._explicitlyExcluded, normalizedPath); @@ -143,14 +143,14 @@ export class Model implements Disposable { // Get the list of conflicts //TODO: Optimize out this call unless it is needed. This call takes over 4 times longer than the status call and is unecessary most of the time. foundConflicts = await this._repository.FindConflicts(); - foundConflicts.forEach(conflict => { + foundConflicts.forEach((conflict) => { if (conflict.message) { TfvcOutput.AppendLine(`[Resolve] ${conflict.message}`); } }); } - const conflict: IConflict = foundConflicts.find(c => c.type === ConflictType.NAME_AND_CONTENT || c.type === ConflictType.RENAME); + const conflict: IConflict = foundConflicts.find((c) => c.type === ConflictType.NAME_AND_CONTENT || c.type === ConflictType.RENAME); if (conflict) { if (conflict.type === ConflictType.RENAME) { Telemetry.SendEvent(TfvcTelemetryEvents.RenameConflict); @@ -163,8 +163,8 @@ export class Model implements Disposable { const excluded: Resource[] = []; const conflicts: Resource[] = []; - changes.forEach(raw => { - const conflict: IConflict = foundConflicts.find(c => this.conflictMatchesPendingChange(raw, c)); + changes.forEach((raw) => { + const conflict: IConflict = foundConflicts.find((c) => this.conflictMatchesPendingChange(raw, c)); const resource: Resource = new Resource(raw, conflict); if (resource.HasStatus(Status.CONFLICT)) { diff --git a/src/tfvc/scm/resource.ts b/src/tfvc/scm/resource.ts index d90cc6708..c49e008e9 100644 --- a/src/tfvc/scm/resource.ts +++ b/src/tfvc/scm/resource.ts @@ -37,7 +37,7 @@ export class Resource implements SourceControlResourceState { public get ConflictType(): ConflictType { return this._conflictType; } public HasStatus(status: Status): boolean { - return this._statuses.findIndex(s => s === status) >= 0; + return this._statuses.findIndex((s) => s === status) >= 0; } get IsVersioned(): boolean { return this._version !== "0"; } diff --git a/src/tfvc/scm/tfvccontentprovider.ts b/src/tfvc/scm/tfvccontentprovider.ts index d43ef8241..e2b60bb78 100644 --- a/src/tfvc/scm/tfvccontentprovider.ts +++ b/src/tfvc/scm/tfvccontentprovider.ts @@ -60,7 +60,7 @@ export class TfvcContentProvider { dispose(): void { if (this._disposables) { - this._disposables.forEach(d => d.dispose()); + this._disposables.forEach((d) => d.dispose()); this._disposables = []; } } diff --git a/src/tfvc/tfcommandlinerunner.ts b/src/tfvc/tfcommandlinerunner.ts index 8553b920b..132530707 100644 --- a/src/tfvc/tfcommandlinerunner.ts +++ b/src/tfvc/tfcommandlinerunner.ts @@ -236,9 +236,9 @@ export class TfCommandLineRunner { once(child, "error", e); once(child, "exit", c); }), - new Promise(c => { + new Promise((c) => { const buffers: string[] = []; - on(child.stdout, "data", b => { + on(child.stdout, "data", (b) => { buffers.push(b); }); once(child.stdout, "close", () => { @@ -255,9 +255,9 @@ export class TfCommandLineRunner { c(stdout); }); }), - new Promise(c => { + new Promise((c) => { const buffers: string[] = []; - on(child.stderr, "data", b => buffers.push(b)); + on(child.stderr, "data", (b) => buffers.push(b)); once(child.stderr, "close", () => c(buffers.join(""))); }) ]); diff --git a/src/tfvc/tfvc-extension.ts b/src/tfvc/tfvc-extension.ts index 5b0aaf2e9..e8a2bb2c2 100644 --- a/src/tfvc/tfvc-extension.ts +++ b/src/tfvc/tfvc-extension.ts @@ -57,7 +57,7 @@ export class TfvcExtension { if (resources && resources.length > 0) { //Keep an in-memory list of items that were explicitly excluded. The list is not persisted at this time. let paths: string[] = []; - resources.forEach(resource => { + resources.forEach((resource) => { paths.push(resource.resourceUri.fsPath); }); await TfvcSCMProvider.Exclude(paths); @@ -72,7 +72,7 @@ export class TfvcExtension { if (resources && resources.length > 0) { let pathsToUnexclude: string[] = []; let pathsToAdd: string[] = []; - resources.forEach(resource => { + resources.forEach((resource) => { let path: string = resource.resourceUri.fsPath; //Unexclude each file passed in pathsToUnexclude.push(path); @@ -249,7 +249,7 @@ export class TfvcExtension { async () => { if (resources) { let pathsToUndo: string[] = []; - resources.forEach(resource => { + resources.forEach((resource) => { pathsToUndo.push(resource.resourceUri.fsPath); }); //When calling from UI, we have the uri of the resource from which the command was invoked @@ -277,10 +277,15 @@ export class TfvcExtension { public async UndoAll(): Promise { this.displayErrors( async () => { - let message: string = `Are you sure you want to undo all changes?`; - if (await UIHelper.PromptForConfirmation(message, Strings.UndoChanges)) { - //We decided not to send telemetry on file operations - await this._repo.Undo(["*"]); + if (TfvcSCMProvider.HasItems()) { + let message: string = `Are you sure you want to undo all changes?`; + if (await UIHelper.PromptForConfirmation(message, Strings.UndoChanges)) { + //We decided not to send telemetry on file operations + await this._repo.Undo(["*"]); + } + } else { + window.showInformationMessage(Strings.NoChangesToUndo); + return; } }, "UndoAll"); diff --git a/src/tfvc/tfvcscmprovider.ts b/src/tfvc/tfvcscmprovider.ts index 6c7d65c01..92e6e40d6 100644 --- a/src/tfvc/tfvcscmprovider.ts +++ b/src/tfvc/tfvcscmprovider.ts @@ -46,7 +46,7 @@ export class TfvcSCMProvider { } public static GetCheckinInfo(): ICheckinInfo { - const tfvcProvider: TfvcSCMProvider = TfvcSCMProvider.GetProviderInstance(); + const tfvcProvider: TfvcSCMProvider = TfvcSCMProvider.getProviderInstance(); try { const files: string[] = []; @@ -94,19 +94,19 @@ export class TfvcSCMProvider { } public static async Exclude(paths: string[]): Promise { - const tfvcProvider: TfvcSCMProvider = TfvcSCMProvider.GetProviderInstance(); + const tfvcProvider: TfvcSCMProvider = TfvcSCMProvider.getProviderInstance(); await tfvcProvider._model.Exclude(paths); }; public static async Refresh(): Promise { - const tfvcProvider: TfvcSCMProvider = TfvcSCMProvider.GetProviderInstance(); + const tfvcProvider: TfvcSCMProvider = TfvcSCMProvider.getProviderInstance(); await tfvcProvider._model.Refresh(); }; public static async Unexclude(paths: string[]): Promise { - const tfvcProvider: TfvcSCMProvider = TfvcSCMProvider.GetProviderInstance(); + const tfvcProvider: TfvcSCMProvider = TfvcSCMProvider.getProviderInstance(); await tfvcProvider._model.Unexclude(paths); }; @@ -169,7 +169,7 @@ export class TfvcSCMProvider { let repoContext: TfvcContext = this._extensionManager.RepoContext; const fsWatcher = workspace.createFileSystemWatcher("**"); const onWorkspaceChange = anyEvent(fsWatcher.onDidChange, fsWatcher.onDidCreate, fsWatcher.onDidDelete); - const onTfvcChange = filterEvent(onWorkspaceChange, uri => /^\$tf\//.test(workspace.asRelativePath(uri))); + const onTfvcChange = filterEvent(onWorkspaceChange, (uri) => /^\$tf\//.test(workspace.asRelativePath(uri))); this._model = new Model(repoContext.RepoFolder, repoContext.TfvcRepository, onWorkspaceChange); // Hook up the model change event to trigger our own event this._disposables.push(this._model.onDidChange(this.onDidModelChange, this)); @@ -206,7 +206,7 @@ export class TfvcSCMProvider { private cleanup() { // dispose all the temporary items if (this._tempDisposables) { - this._tempDisposables.forEach(d => d.dispose()); + this._tempDisposables.forEach((d) => d.dispose()); this._tempDisposables = []; } @@ -230,11 +230,24 @@ export class TfvcSCMProvider { TfvcSCMProvider.instance = undefined; this.cleanup(); if (this._disposables) { - this._disposables.forEach(d => d.dispose()); + this._disposables.forEach((d) => d.dispose()); this._disposables = []; } } + /** + * If Tfvc is the active provider, returns the number of items it is tracking. + */ + public static HasItems(): boolean { + const tfvcProvider: TfvcSCMProvider = TfvcSCMProvider.instance; + if (tfvcProvider) { + if (tfvcProvider.count > 0) { + return true; + } + } + return false; + } + /** * Gets the uri for the previous version of the file. */ @@ -260,11 +273,11 @@ export class TfvcSCMProvider { } } - private static GetProviderInstance(): TfvcSCMProvider { + private static getProviderInstance(): TfvcSCMProvider { const tfvcProvider: TfvcSCMProvider = TfvcSCMProvider.instance; if (!tfvcProvider) { // We are not the active provider - Logger.LogDebug("Failed to GetCheckinInfo. TFVC is not the active provider."); + Logger.LogDebug("TFVC is not the active provider."); throw TfvcError.CreateInvalidStateError(); } return tfvcProvider; diff --git a/src/tfvc/util.ts b/src/tfvc/util.ts index e2eba44ea..3fd187e70 100644 --- a/src/tfvc/util.ts +++ b/src/tfvc/util.ts @@ -16,7 +16,7 @@ export interface IDisposable { } export function dispose(disposables: T[]): T[] { - disposables.forEach(d => d.dispose()); + disposables.forEach((d) => d.dispose()); return []; } @@ -29,15 +29,15 @@ export function combinedDisposable(disposables: IDisposable[]): IDisposable { } export function mapEvent(event: Event, map: (i: I) => O): Event { - return (listener, thisArgs = null, disposables?) => event(i => listener.call(thisArgs, map(i)), null, disposables); + return (listener, thisArgs = null, disposables?) => event((i) => listener.call(thisArgs, map(i)), null, disposables); } export function filterEvent(event: Event, filter: (e: T) => boolean): Event { - return (listener, thisArgs = null, disposables?) => event(e => filter(e) && listener.call(thisArgs, e), null, disposables); + return (listener, thisArgs = null, disposables?) => event((e) => filter(e) && listener.call(thisArgs, e), null, disposables); } export function anyEvent(...events: Event[]): Event { - return (listener, thisArgs = null, disposables?) => combinedDisposable(events.map(event => event(i => listener.call(thisArgs, i), disposables))); + return (listener, thisArgs = null, disposables?) => combinedDisposable(events.map((event) => event((i) => listener.call(thisArgs, i), disposables))); } export function done(promise: Promise): Promise { @@ -47,7 +47,7 @@ export function done(promise: Promise): Promise { export function once(event: Event): Event { return (listener, thisArgs = null, disposables?) => { const result = event( - e => { + (e) => { result.dispose(); return listener.call(thisArgs, e); }, @@ -59,6 +59,6 @@ export function once(event: Event): Event { } export function eventToPromise(event: Event): Promise { - return new Promise(c => once(event)(c)); + return new Promise((c) => once(event)(c)); } /* tslint:enable:no-null-keyword */ diff --git a/test-integration/services/build.integration.test.ts b/test-integration/services/build.integration.test.ts index cb5ef92fd..3be2c3e48 100644 --- a/test-integration/services/build.integration.test.ts +++ b/test-integration/services/build.integration.test.ts @@ -6,15 +6,13 @@ import { assert, expect } from "chai"; +import { Build, BuildBadge } from "vso-node-api/interfaces/BuildInterfaces"; import { Mocks } from "../helpers-integration/mocks"; import { TestSettings } from "../helpers-integration/testsettings"; - -import { Build, BuildBadge } from "vso-node-api/interfaces/BuildInterfaces"; - import { CredentialManager } from "../../src/helpers/credentialmanager"; import { UserAgentProvider } from "../../src/helpers/useragentprovider"; import { TeamServerContext } from "../../src/contexts/servercontext"; -import { BuildService } from "../../src/services/build"; +import { BuildService } from "../../src/services/build"; import { WellKnownRepositoryTypes } from "../../src/helpers/constants"; describe("BuildService-Integration", function() { diff --git a/test-integration/services/gitvc.integration.test.ts b/test-integration/services/gitvc.integration.test.ts index b49eacec9..476e2a775 100644 --- a/test-integration/services/gitvc.integration.test.ts +++ b/test-integration/services/gitvc.integration.test.ts @@ -6,15 +6,13 @@ import { assert, expect } from "chai"; +import { GitPullRequest, GitRepository } from "vso-node-api/interfaces/GitInterfaces"; import { Mocks } from "../helpers-integration/mocks"; import { TestSettings } from "../helpers-integration/testsettings"; - -import { GitPullRequest, GitRepository } from "vso-node-api/interfaces/GitInterfaces"; - import { CredentialManager } from "../../src/helpers/credentialmanager"; import { UserAgentProvider } from "../../src/helpers/useragentprovider"; import { TeamServerContext } from "../../src/contexts/servercontext"; -import { GitVcService, PullRequestScore } from "../../src/services/gitvc"; +import { GitVcService, PullRequestScore } from "../../src/services/gitvc"; describe("GitVcService-Integration", function() { this.timeout(TestSettings.SuiteTimeout); @@ -75,7 +73,7 @@ describe("GitVcService-Integration", function() { let svc: GitVcService = new GitVcService(ctx); let requests: GitPullRequest[] = await svc.GetPullRequests(ctx.RepoInfo.RepositoryId); let totals = []; - requests.forEach(request => { + requests.forEach((request) => { totals.push({ "id" : request.pullRequestId, "score" : GitVcService.GetPullRequestScore(request) }); }); assert.equal(totals.length, 4); diff --git a/test-integration/services/workitemtracking.integration.test.ts b/test-integration/services/workitemtracking.integration.test.ts index 963007b88..6326cad78 100644 --- a/test-integration/services/workitemtracking.integration.test.ts +++ b/test-integration/services/workitemtracking.integration.test.ts @@ -6,16 +6,14 @@ import { assert, expect } from "chai"; +import { QueryHierarchyItem, WorkItem, WorkItemType } from "vso-node-api/interfaces/WorkItemTrackingInterfaces"; import { Mocks } from "../helpers-integration/mocks"; import { TestSettings } from "../helpers-integration/testsettings"; - -import { QueryHierarchyItem, WorkItem, WorkItemType } from "vso-node-api/interfaces/WorkItemTrackingInterfaces"; - import { WitQueries } from "../../src/helpers/constants"; import { CredentialManager } from "../../src/helpers/credentialmanager"; import { UserAgentProvider } from "../../src/helpers/useragentprovider"; import { TeamServerContext } from "../../src/contexts/servercontext"; -import { SimpleWorkItem, WorkItemTrackingService } from "../../src/services/workitemtracking"; +import { SimpleWorkItem, WorkItemTrackingService } from "../../src/services/workitemtracking"; describe("WorkItemTrackingService-Integration", function() { this.timeout(TestSettings.SuiteTimeout); diff --git a/test/contexts/contexthelper.ts b/test/contexts/contexthelper.ts index 6a358165b..d40182b38 100644 --- a/test/contexts/contexthelper.ts +++ b/test/contexts/contexthelper.ts @@ -4,7 +4,7 @@ *--------------------------------------------------------------------------------------------*/ "use strict"; -import { ISettings } from "../../src/helpers/settings"; +import { ISettings } from "../../src/helpers/settings"; //Used to test the GitContext, ExternalContext classes export class SettingsMock implements ISettings { diff --git a/test/contexts/externalcontext.test.ts b/test/contexts/externalcontext.test.ts index 775c0a5b6..508e786ae 100644 --- a/test/contexts/externalcontext.test.ts +++ b/test/contexts/externalcontext.test.ts @@ -8,8 +8,8 @@ import { assert } from "chai"; const path = require("path"); import { RepositoryType } from "../../src/contexts/repositorycontext"; -import { ExternalContext } from "../../src/contexts/externalcontext"; -import { SettingsMock } from "./contexthelper"; +import { ExternalContext } from "../../src/contexts/externalcontext"; +import { SettingsMock } from "./contexthelper"; describe("ExternalContext", function() { let TEST_REPOS_FOLDER: string = "testrepos"; diff --git a/test/contexts/gitcontext.test.ts b/test/contexts/gitcontext.test.ts index cb72d9e4b..c6540c41d 100644 --- a/test/contexts/gitcontext.test.ts +++ b/test/contexts/gitcontext.test.ts @@ -7,7 +7,7 @@ import { assert } from "chai"; const path = require("path"); -import { GitContext } from "../../src/contexts/gitcontext"; +import { GitContext } from "../../src/contexts/gitcontext"; import { RepositoryType } from "../../src/contexts/repositorycontext"; describe("GitContext", function() { diff --git a/test/helpers/logger.test.ts b/test/helpers/logger.test.ts index a19e4cafa..602c29732 100644 --- a/test/helpers/logger.test.ts +++ b/test/helpers/logger.test.ts @@ -5,7 +5,7 @@ "use strict"; import { assert } from "chai"; -import { Logger, LoggingLevel } from "../../src/helpers/logger"; +import { Logger, LoggingLevel } from "../../src/helpers/logger"; describe("Logger", function() { diff --git a/test/helpers/repoutils.test.ts b/test/helpers/repoutils.test.ts index 7f5ab6ed5..e415a9d75 100644 --- a/test/helpers/repoutils.test.ts +++ b/test/helpers/repoutils.test.ts @@ -6,7 +6,7 @@ import { assert } from "chai"; -import { RepoUtils } from "../../src/helpers/repoutils"; +import { RepoUtils } from "../../src/helpers/repoutils"; describe("RepoUtils", function() { diff --git a/test/helpers/utils.test.ts b/test/helpers/utils.test.ts index 879f3320c..05f13ebb4 100644 --- a/test/helpers/utils.test.ts +++ b/test/helpers/utils.test.ts @@ -8,8 +8,8 @@ import { assert, expect } from "chai"; const path = require("path"); import { BuildResult } from "vso-node-api/interfaces/BuildInterfaces"; -import { Utils } from "../../src/helpers/utils"; -import { Strings } from "../../src/helpers/strings"; +import { Utils } from "../../src/helpers/utils"; +import { Strings } from "../../src/helpers/strings"; describe("Utils", function() { let TEST_REPOS_FOLDER: string = "testrepos"; diff --git a/test/services/build.test.ts b/test/services/build.test.ts index e6131eb52..e10f6dc1d 100644 --- a/test/services/build.test.ts +++ b/test/services/build.test.ts @@ -6,7 +6,7 @@ import { assert } from "chai"; -import { BuildService } from "../../src/services/build"; +import { BuildService } from "../../src/services/build"; describe("BuildService", function() { diff --git a/test/services/gitvc.test.ts b/test/services/gitvc.test.ts index 75aae76af..8500b4ec1 100644 --- a/test/services/gitvc.test.ts +++ b/test/services/gitvc.test.ts @@ -7,7 +7,7 @@ import { assert } from "chai"; import { GitPullRequest, PullRequestAsyncStatus } from "vso-node-api/interfaces/GitInterfaces"; -import { GitVcService, PullRequestScore } from "../../src/services/gitvc"; +import { GitVcService, PullRequestScore } from "../../src/services/gitvc"; describe("GitVcService", function() { diff --git a/test/services/workitemtracking.test.ts b/test/services/workitemtracking.test.ts index 3f9d73826..add9f5ab8 100644 --- a/test/services/workitemtracking.test.ts +++ b/test/services/workitemtracking.test.ts @@ -6,7 +6,7 @@ import { assert } from "chai"; -import { WorkItemFields, WorkItemTrackingService } from "../../src/services/workitemtracking"; +import { WorkItemFields, WorkItemTrackingService } from "../../src/services/workitemtracking"; describe("WorkItemTrackingService", function() { diff --git a/test/tfvc/scm/status.test.ts b/test/tfvc/scm/status.test.ts index d58a0ba8f..323353efe 100644 --- a/test/tfvc/scm/status.test.ts +++ b/test/tfvc/scm/status.test.ts @@ -6,7 +6,7 @@ import { expect } from "chai"; -import { GetStatuses, Status } from "../../../src/tfvc/scm/status"; +import { GetStatuses, Status } from "../../../src/tfvc/scm/status"; describe("Tfvc-Version", function() { beforeEach(function() { diff --git a/test/tfvc/tfvcerror.test.ts b/test/tfvc/tfvcerror.test.ts index 0b214053d..0505261c9 100644 --- a/test/tfvc/tfvcerror.test.ts +++ b/test/tfvc/tfvcerror.test.ts @@ -6,8 +6,8 @@ import { assert } from "chai"; -import { Strings } from "../../src/helpers/strings"; -import { TfvcError, TfvcErrorCodes } from "../../src/tfvc/tfvcerror"; +import { Strings } from "../../src/helpers/strings"; +import { TfvcError, TfvcErrorCodes } from "../../src/tfvc/tfvcerror"; describe("Tfvc-Error", function() { beforeEach(function() { diff --git a/test/tfvc/tfvcversion.test.ts b/test/tfvc/tfvcversion.test.ts index 652da0ec0..5681eb1e5 100644 --- a/test/tfvc/tfvcversion.test.ts +++ b/test/tfvc/tfvcversion.test.ts @@ -6,7 +6,7 @@ import { assert } from "chai"; -import { TfvcVersion } from "../../src/tfvc/tfvcversion"; +import { TfvcVersion } from "../../src/tfvc/tfvcversion"; describe("Tfvc-Version", function() { beforeEach(function() { diff --git a/tslint.json b/tslint.json index 1380a9ca6..e2fa4c1f0 100644 --- a/tslint.json +++ b/tslint.json @@ -5,13 +5,16 @@ "arguments", "statements" ], + "arrow-parens": true, "class-name": true, "curly": true, "eofline": true, "forin": true, + "import-spacing": true, "indent": [true, "spaces", 4], "label-position": true, "max-line-length": [false, 160], + "newline-before-return": false, "no-arg": true, "no-bitwise": true, "no-console": [true, @@ -38,9 +41,15 @@ "check-else", "check-whitespace" ], + "one-variable-per-declaration": true, + "prefer-const": false, + "prefer-method-signature": true, "quotemark": [true, "double"], "radix": false, "semicolon": true, + "space-before-function-paren": [ + false, {"anonymous": "always", "named": "never", "asyncArrow": "always"} + ], "trailing-comma": [false, { "multiline": "never", "singleline": "never" }], "triple-equals": [true, "allow-null-check"], "variable-name": [true,