Skip to content

Commit 5d87bb3

Browse files
committed
Setting up Prettier and TSLint to use the same settings
1 parent bcdd610 commit 5d87bb3

File tree

12 files changed

+90
-77
lines changed

12 files changed

+90
-77
lines changed

.prettierrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
"tabWidth": 4,
44
"useTabs": false,
55
"semi": true,
6-
"singleQuote": true,
6+
"singleQuote": false,
7+
"trailingComma": "all",
78
"bracketSpacing": true,
89
"arrowParens": "always",
910
"parser": "typescript"

src/git/blame.ts

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
import { isWebUri } from "valid-url";
22

3-
import { commands, Disposable, MessageItem, Uri, window, workspace } from "vscode";
3+
import {
4+
commands,
5+
Disposable,
6+
MessageItem,
7+
Uri,
8+
window,
9+
workspace,
10+
} from "vscode";
411

512
import { HASH_NO_COMMIT_GIT, TITLE_VIEW_ONLINE } from "../constants";
613
import { IGitBlameInfo, IGitCommitInfo } from "../interfaces";
@@ -147,7 +154,10 @@ export class GitBlame {
147154

148155
this.updateView(commitInfo);
149156

150-
const actionedItem = await window.showInformationMessage(message, ...extraActions);
157+
const actionedItem = await window.showInformationMessage(
158+
message,
159+
...extraActions,
160+
);
151161

152162
if (actionedItem) {
153163
actionedItem.takeAction();
@@ -172,12 +182,16 @@ export class GitBlame {
172182
);
173183
}
174184

175-
private generateMessageActions(commitInfo: IGitCommitInfo): ActionableMessageItem[] {
185+
private generateMessageActions(
186+
commitInfo: IGitCommitInfo,
187+
): ActionableMessageItem[] {
176188
const commitToolUrl = this.getToolUrl(commitInfo);
177189
const extraActions: ActionableMessageItem[] = [];
178190

179191
if (commitToolUrl) {
180-
const viewOnlineAction = new ActionableMessageItem(TITLE_VIEW_ONLINE);
192+
const viewOnlineAction = new ActionableMessageItem(
193+
TITLE_VIEW_ONLINE,
194+
);
181195

182196
viewOnlineAction.setAction(() => {
183197
commands.executeCommand("vscode.open", commitToolUrl);
@@ -217,7 +231,7 @@ export class GitBlame {
217231
return Uri.parse(parsedUrl);
218232
} else if (parsedUrl) {
219233
window.showErrorMessage(
220-
"Malformed URL in setting gitblame.commitUrl. Must be a valid web url.",
234+
"Malformed URL in gitblame.commitUrl. Must be a valid web url.",
221235
);
222236
}
223237
}

src/git/stream.ts

Lines changed: 33 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import { Properties, Property } from "../util/property";
1010
import { GitBlame } from "./blame";
1111

1212
export class GitBlameStream extends EventEmitter {
13+
private static readonly HASH_PATTERN: RegExp = /[a-z0-9]{40}/;
14+
1315
private file: Uri;
1416
private workTree: string;
1517
private process: ChildProcess;
@@ -78,19 +80,25 @@ export class GitBlameStream extends EventEmitter {
7880

7981
private data(dataChunk: string): void {
8082
const lines = dataChunk.split("\n");
81-
let commitInfo = this.getCommitTemplate();
83+
let commitInfo = GitBlame.blankCommitInfo();
84+
85+
commitInfo.filename = this.file.fsPath.replace(this.workTree, "");
8286

8387
lines.forEach((line, index) => {
8488
if (line && line !== "boundary") {
8589
const [all, key, value] = Array.from(line.match(/(.*?) (.*)/));
8690
if (
87-
/[a-z0-9]{40}/.test(key) &&
91+
GitBlameStream.HASH_PATTERN.test(key) &&
8892
lines.hasOwnProperty(index + 1) &&
8993
/^(author|committer)/.test(lines[index + 1]) &&
9094
commitInfo.hash !== ""
9195
) {
9296
this.commitInfoToCommitEmit(commitInfo);
93-
commitInfo = this.getCommitTemplate();
97+
commitInfo = GitBlame.blankCommitInfo();
98+
commitInfo.filename = this.file.fsPath.replace(
99+
this.workTree,
100+
"",
101+
);
94102
}
95103
this.processLine(key, value, commitInfo);
96104
}
@@ -104,25 +112,32 @@ export class GitBlameStream extends EventEmitter {
104112
value: string,
105113
commitInfo: IGitCommitInfo,
106114
): void {
115+
const [keyPrefix, keySuffix] = key.split(" ");
116+
let owner: IGitCommitAuthor = {
117+
mail: "",
118+
name: "",
119+
temporary: true,
120+
timestamp: 0,
121+
tz: "",
122+
};
123+
107124
if (key === "author") {
108-
commitInfo.author.name = value;
109-
} else if (key === "author-mail") {
110-
commitInfo.author.mail = value;
111-
} else if (key === "author-time") {
112-
commitInfo.author.timestamp = parseInt(value, 10);
113-
} else if (key === "author-tz") {
114-
commitInfo.author.tz = value;
125+
owner = commitInfo.author;
115126
} else if (key === "committer") {
116-
commitInfo.committer.name = value;
117-
} else if (key === "committer-mail") {
118-
commitInfo.committer.mail = value;
119-
} else if (key === "committer-time") {
120-
commitInfo.committer.timestamp = parseInt(value, 10);
121-
} else if (key === "committer-tz") {
122-
commitInfo.committer.tz = value;
127+
owner = commitInfo.committer;
128+
}
129+
130+
if (!owner.temporary && !keySuffix) {
131+
owner.name = value;
132+
} else if (keySuffix === "mail") {
133+
owner.mail = value;
134+
} else if (keySuffix === "time") {
135+
owner.timestamp = parseInt(value, 10);
136+
} else if (keySuffix === "tz") {
137+
owner.tz = value;
123138
} else if (key === "summary") {
124139
commitInfo.summary = value;
125-
} else if (key.length === 40) {
140+
} else if (GitBlameStream.HASH_PATTERN.test(key)) {
126141
commitInfo.hash = key;
127142

128143
const hash = key;
@@ -152,24 +167,4 @@ export class GitBlameStream extends EventEmitter {
152167
this.emit("commit", internalHash, commitInfo);
153168
}
154169
}
155-
156-
private getCommitTemplate(): IGitCommitInfo {
157-
return {
158-
author: {
159-
mail: "",
160-
name: "",
161-
timestamp: 0,
162-
tz: "",
163-
},
164-
committer: {
165-
mail: "",
166-
name: "",
167-
timestamp: 0,
168-
tz: "",
169-
},
170-
filename: this.file.fsPath.replace(this.workTree, ""),
171-
hash: "",
172-
summary: "",
173-
};
174-
}
175170
}

src/interfaces.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ export interface IGitCommitAuthor {
33
mail: string;
44
timestamp: number;
55
tz: string;
6+
temporary?: true;
67
}
78

89
export interface IGitCommitInfo {

src/util/gitcommand.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,13 @@ import { ErrorHandler } from "./errorhandler";
88

99
export function getGitCommand(): Promise<string> {
1010
const gitConfig = workspace.getConfiguration("git");
11-
const command =
12-
gitConfig.get("path", GIT_COMMAND_IN_PATH) as string ||
13-
GIT_COMMAND_IN_PATH;
11+
const pathCommand = gitConfig.get("path") as string;
1412
const promise = new Promise<string>((resolve, reject) => {
15-
if (command === GIT_COMMAND_IN_PATH) {
16-
resolve(command);
13+
if (!pathCommand) {
14+
resolve(GIT_COMMAND_IN_PATH);
1715
}
1816

19-
const commandPath = normalize(command);
17+
const commandPath = normalize(pathCommand);
2018

2119
access(commandPath, FSConstant.X_OK, (err) => {
2220
if (err) {

src/util/textdecorator.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@ import * as moment from "moment";
33
import { workspace } from "vscode";
44

55
import { GitBlame } from "../git/blame";
6-
import { IGitCommitInfo, IInfoTokenHash, IInfoTokenNormalizedCommitInfo } from "../interfaces";
6+
import {
7+
IGitCommitInfo,
8+
IInfoTokenHash,
9+
IInfoTokenNormalizedCommitInfo,
10+
} from "../interfaces";
711
import { walkObject } from "./objectpath";
812
import { Properties, Property } from "./property";
913

@@ -84,7 +88,9 @@ export class TextDecorator {
8488
);
8589
}
8690

87-
public static normalizeCommitInfoTokens(commitInfo: IGitCommitInfo): IInfoTokenNormalizedCommitInfo {
91+
public static normalizeCommitInfoTokens(
92+
commitInfo: IGitCommitInfo,
93+
): IInfoTokenNormalizedCommitInfo {
8894
const now = new Date();
8995
const authorTime = moment.unix(commitInfo.author.timestamp);
9096
const committerTime = moment.unix(commitInfo.committer.timestamp);
@@ -100,7 +106,8 @@ export class TextDecorator {
100106
committer: commitInfo.committer,
101107
time: {
102108
ago: () => TextDecorator.toDateText(now, authorTime.toDate()),
103-
c_ago: () => TextDecorator.toDateText(now, committerTime.toDate()),
109+
c_ago: () =>
110+
TextDecorator.toDateText(now, committerTime.toDate()),
104111
c_custom: (momentFormat) => committerTime.format(momentFormat),
105112
c_from: () => committerTime.fromNow(),
106113
custom: (momentFormat) => authorTime.format(momentFormat),

test/execcommand.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import assert = require("assert");
1+
import * as assert from "assert";
22

33
import { execute } from "../src/util/execcommand";
44

test/gitplatformdetector.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import assert = require("assert");
1+
import * as assert from "assert";
22
// Nock is a library for mocking network requests
3-
import nock = require("nock");
3+
import * as nock from "nock";
44

55
import { GitPlatformDetector } from "../src/util/gitplatformdetector";
66

test/index.ts

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,8 @@
1-
//
2-
// PLEASE DO NOT MODIFY / DELETE UNLESS YOU KNOW WHAT YOU ARE DOING
3-
//
4-
// This file is providing the test runner to use when running extension tests.
5-
// By default the test runner in use is Mocha based.
6-
//
7-
// You can provide your own test runner if you want to override it by exporting
8-
// a function run(testRoot: string, clb: (error:Error) => void) that the extension
9-
// host can call to run the tests. The test runner is expected to use console.log
10-
// to report the results back to the caller. When the tests are finished, return
11-
// a possible error to the callback or null if none.
1+
import * as testRunner from "vscode/lib/testrunner";
122

13-
import testRunner = require("vscode/lib/testrunner");
14-
15-
// You can directly control Mocha options by uncommenting the following lines
16-
// See https://github.com/mochajs/mocha/wiki/Using-mocha-programmatically#set-options for more info
173
testRunner.configure({
18-
ui: "tdd", // the TDD UI is being used in extension.test.ts (suite, test, etc.)
19-
useColors: true, // colored output from test results
4+
ui: "tdd",
5+
useColors: true,
206
});
217

228
module.exports = testRunner;

test/objectpath.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import assert = require("assert");
1+
import * as assert from "assert";
22

33
import { walkObject } from "../src/util/objectpath";
44

0 commit comments

Comments
 (0)