Skip to content

Commit 4e5bdf7

Browse files
committed
Adding Prettier
1 parent 3c92b8d commit 4e5bdf7

25 files changed

+527
-382
lines changed

.prettierrc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"printWidth": 80,
3+
"tabWidth": 4,
4+
"useTabs": false,
5+
"semi": true,
6+
"singleQuote": true,
7+
"bracketSpacing": true,
8+
"arrowParens": "always",
9+
"parser": "typescript"
10+
}

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
* Fix: Renaming `GitBlameFile*` to `GitFile*`
88
* Fix: Rewrote all the tests
99
* Fix: Updating dependencies
10+
* Enhancment: Prettifying with [Prettier](https://prettier.io/)
1011

1112
## 2.2.0 (September 07, 2017)
1213

src/git/blame.ts

Lines changed: 77 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,16 @@
11
import { isWebUri } from 'valid-url';
22

3-
import {
4-
Disposable,
5-
commands,
6-
window,
7-
workspace,
8-
Uri } from 'vscode';
3+
import { Disposable, commands, window, workspace, Uri } from 'vscode';
94

105
import { ErrorHandler } from '../util/errorhandler';
116
import { TextDecorator } from '../util/textdecorator';
127
import { isActiveEditorValid } from '../util/editorvalidator';
138
import { GitFile } from './file';
149
import { GitFileFactory } from './filefactory';
1510
import { StatusBarView } from '../view';
16-
import {
17-
Property,
18-
Properties } from '../util/property';
19-
import {
20-
GitBlameInfo,
21-
GitCommitInfo } from '../interfaces';
22-
import {
23-
HASH_NO_COMMIT_GIT,
24-
TITLE_VIEW_ONLINE } from '../constants';
25-
11+
import { Property, Properties } from '../util/property';
12+
import { GitBlameInfo, GitCommitInfo } from '../interfaces';
13+
import { HASH_NO_COMMIT_GIT, TITLE_VIEW_ONLINE } from '../constants';
2614

2715
export class GitBlame {
2816
private disposable: Disposable;
@@ -47,15 +35,31 @@ export class GitBlame {
4735

4836
const propertyHolder = Property.getInstance();
4937

50-
this.disposable = Disposable.from(this.statusBarView, errorHandler, propertyHolder);
38+
this.disposable = Disposable.from(
39+
this.statusBarView,
40+
errorHandler,
41+
propertyHolder
42+
);
5143
}
5244

5345
setupListeners(): void {
5446
const disposables: Disposable[] = [];
5547

56-
window.onDidChangeActiveTextEditor(this.onTextEditorMove, this, disposables);
57-
window.onDidChangeTextEditorSelection(this.onTextEditorMove, this, disposables);
58-
workspace.onDidSaveTextDocument(this.onTextEditorMove, this, disposables);
48+
window.onDidChangeActiveTextEditor(
49+
this.onTextEditorMove,
50+
this,
51+
disposables
52+
);
53+
window.onDidChangeTextEditorSelection(
54+
this.onTextEditorMove,
55+
this,
56+
disposables
57+
);
58+
workspace.onDidSaveTextDocument(
59+
this.onTextEditorMove,
60+
this,
61+
disposables
62+
);
5963

6064
this.disposable = Disposable.from(this.disposable, ...disposables);
6165
}
@@ -70,26 +74,38 @@ export class GitBlame {
7074
const commitInfo = await this.getCurrentLineInfo();
7175

7276
// Only update if we haven't moved since we started blaming
73-
if (beforeBlameOpenFile === this.getCurrentActiveFileName() && beforeBlameLineNumber === this.getCurrentActiveLineNumber()) {
77+
if (
78+
beforeBlameOpenFile === this.getCurrentActiveFileName() &&
79+
beforeBlameLineNumber === this.getCurrentActiveLineNumber()
80+
) {
7481
this.updateView(commitInfo);
7582
}
76-
7783
}
7884

7985
private getCurrentActiveFileName(): string {
80-
return window.activeTextEditor && window.activeTextEditor.document.fileName;
86+
return (
87+
window.activeTextEditor && window.activeTextEditor.document.fileName
88+
);
8189
}
8290

8391
private getCurrentActiveLineNumber(): number {
84-
return window.activeTextEditor && window.activeTextEditor.selection.active.line;
92+
return (
93+
window.activeTextEditor &&
94+
window.activeTextEditor.selection.active.line
95+
);
8596
}
8697

8798
async showMessage(): Promise<void> {
8899
const commitInfo = await this.getCommitInfo();
89100
const commitToolUrl = this.getToolUrl(commitInfo);
90101
const messageFormat = Property.get(Properties.InfoMessageFormat);
91-
const normalizedTokens = TextDecorator.normalizeCommitInfoTokens(commitInfo);
92-
const message = TextDecorator.parseTokens(messageFormat, normalizedTokens);
102+
const normalizedTokens = TextDecorator.normalizeCommitInfoTokens(
103+
commitInfo
104+
);
105+
const message = TextDecorator.parseTokens(
106+
messageFormat,
107+
normalizedTokens
108+
);
93109
const extraAction = commitToolUrl ? TITLE_VIEW_ONLINE : '';
94110

95111
this.updateView(commitInfo);
@@ -107,17 +123,20 @@ export class GitBlame {
107123

108124
if (commitToolUrl) {
109125
commands.executeCommand('vscode.open', commitToolUrl);
110-
}
111-
else {
112-
window.showErrorMessage('Missing gitblame.commitUrl configuration value.');
126+
} else {
127+
window.showErrorMessage(
128+
'Missing gitblame.commitUrl configuration value.'
129+
);
113130
}
114131
}
115132

116133
private async getCommitInfo(): Promise<GitCommitInfo> {
117134
let commitInfo = await this.getCurrentLineInfo();
118135

119136
if (GitBlame.isGeneratedCommit(commitInfo)) {
120-
window.showErrorMessage('The current file and line can not be blamed.');
137+
window.showErrorMessage(
138+
'The current file and line can not be blamed.'
139+
);
121140
}
122141

123142
return commitInfo;
@@ -128,61 +147,71 @@ export class GitBlame {
128147
return;
129148
}
130149

131-
const parsedUrl = TextDecorator.parseTokens(Property.get(Properties.CommitUrl), {
132-
'hash': commitInfo.hash
133-
});
150+
const parsedUrl = TextDecorator.parseTokens(
151+
Property.get(Properties.CommitUrl),
152+
{
153+
hash: commitInfo.hash
154+
}
155+
);
134156

135157
if (isWebUri(parsedUrl)) {
136158
return Uri.parse(parsedUrl);
137-
}
138-
else if (parsedUrl) {
139-
window.showErrorMessage('Malformed URL in setting gitblame.commitUrl. Must be a valid web url.');
159+
} else if (parsedUrl) {
160+
window.showErrorMessage(
161+
'Malformed URL in setting gitblame.commitUrl. Must be a valid web url.'
162+
);
140163
}
141164
}
142165

143166
private updateView(commitInfo: GitCommitInfo): void {
144167
if (GitBlame.isGeneratedCommit(commitInfo)) {
145168
this.statusBarView.clear();
146-
}
147-
else {
169+
} else {
148170
this.statusBarView.update(commitInfo);
149171
}
150172
}
151173

152174
async getBlameInfo(fileName: string): Promise<GitBlameInfo> {
153175
if (!this.files[fileName]) {
154-
this.files[fileName] = GitFileFactory.create(fileName, this.generateDisposeFunction(fileName));
176+
this.files[fileName] = GitFileFactory.create(
177+
fileName,
178+
this.generateDisposeFunction(fileName)
179+
);
155180
}
156181

157182
return this.files[fileName].blame();
158183
}
159184

160185
async getCurrentLineInfo(): Promise<GitCommitInfo> {
161186
if (isActiveEditorValid()) {
162-
return this.getLineInfo(window.activeTextEditor.document.fileName, window.activeTextEditor.selection.active.line)
163-
}
164-
else {
187+
return this.getLineInfo(
188+
window.activeTextEditor.document.fileName,
189+
window.activeTextEditor.selection.active.line
190+
);
191+
} else {
165192
return GitBlame.blankCommitInfo();
166193
}
167194
}
168195

169-
async getLineInfo(fileName: string, lineNumber: number): Promise<GitCommitInfo> {
196+
async getLineInfo(
197+
fileName: string,
198+
lineNumber: number
199+
): Promise<GitCommitInfo> {
170200
const commitLineNumber = lineNumber + 1;
171201
const blameInfo = await this.getBlameInfo(fileName);
172202

173203
if (blameInfo['lines'][commitLineNumber]) {
174204
const hash = blameInfo['lines'][commitLineNumber];
175205
return blameInfo['commits'][hash];
176-
}
177-
else {
206+
} else {
178207
return GitBlame.blankCommitInfo();
179208
}
180209
}
181210

182211
private generateDisposeFunction(fileName) {
183212
return () => {
184213
delete this.files[fileName];
185-
}
214+
};
186215
}
187216

188217
dispose(): void {
@@ -192,8 +221,8 @@ export class GitBlame {
192221

193222
static blankBlameInfo(): GitBlameInfo {
194223
return {
195-
'commits': {},
196-
'lines': {}
224+
commits: {},
225+
lines: {}
197226
};
198227
}
199228

src/git/file.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
1-
import {
2-
workspace,
3-
window,
4-
Uri } from 'vscode';
1+
import { workspace, window, Uri } from 'vscode';
52

63
import { GitBlame } from './blame';
74
import { ErrorHandler } from '../util/errorhandler';
85
import { GitBlameInfo } from '../interfaces';
96
import { TIME_CACHE_LIFETIME } from '../constants';
107

11-
128
export class GitFile {
139
private cacheClearInterval: NodeJS.Timer;
1410

@@ -24,17 +20,23 @@ export class GitFile {
2420
startCacheInterval(): void {
2521
clearInterval(this.cacheClearInterval);
2622
this.cacheClearInterval = setInterval(() => {
27-
const isOpen = window.visibleTextEditors.some(editor => editor.document.uri.fsPath === this.fileName.fsPath);
23+
const isOpen = window.visibleTextEditors.some(
24+
(editor) => editor.document.uri.fsPath === this.fileName.fsPath
25+
);
2826

2927
if (!isOpen) {
30-
ErrorHandler.getInstance().logInfo(`Clearing the file "${this.fileName.fsPath}" from the internal cache`);
28+
ErrorHandler.getInstance().logInfo(
29+
`Clearing the file "${
30+
this.fileName.fsPath
31+
}" from the internal cache`
32+
);
3133
this.dispose();
3234
}
3335
}, TIME_CACHE_LIFETIME);
3436
}
3537

3638
async getGitWorkTree(): Promise<string> {
37-
return this.workTree
39+
return this.workTree;
3840
}
3941

4042
changed(): void {

src/git/filedummy.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
import { GitFile } from './file';
22
import { ErrorHandler } from '../util/errorhandler';
33

4-
54
export class GitFileDummy extends GitFile {
65
constructor(fileName: string, disposeCallback: Function = () => {}) {
76
super(fileName, disposeCallback);
87
this.startCacheInterval();
9-
ErrorHandler.getInstance().logInfo(`Will not try to blame file "${this.fileName.fsPath}" as it is outside of the current workspace`);
8+
ErrorHandler.getInstance().logInfo(
9+
`Will not try to blame file "${
10+
this.fileName.fsPath
11+
}" as it is outside of the current workspace`
12+
);
1013
}
1114
}

src/git/filefactory.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
1-
import {
2-
Uri,
3-
workspace } from 'vscode';
1+
import { Uri, workspace } from 'vscode';
42

53
import { GitFilePhysical } from './filephysical';
64
import { GitFileDummy } from './filedummy';
75
import { GitFile } from './file';
86

9-
107
export class GitFileFactory {
11-
static create(fileName: string, disposeCallback: Function = () => {}): GitFile {
8+
static create(
9+
fileName: string,
10+
disposeCallback: Function = () => {}
11+
): GitFile {
1212
if (GitFileFactory.inWorkspace(fileName)) {
1313
return new GitFilePhysical(fileName, disposeCallback);
14-
}
15-
else {
14+
} else {
1615
return new GitFileDummy(fileName, disposeCallback);
1716
}
1817
}

0 commit comments

Comments
 (0)