Skip to content

Commit 18886b0

Browse files
committed
chore(*): Update tsconfig
1 parent 5132c0a commit 18886b0

6 files changed

Lines changed: 23 additions & 58 deletions

File tree

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
"@types/node": "^8.0.20",
7171
"mocha": "^3.5.0",
7272
"tslint": "^5.6.0",
73+
"tslint-config-mrmlnc": "^1.0.0",
7374
"tslint-config-xo": "^1.3.0",
7475
"typescript": "^2.8.1",
7576
"vscode": "^1.1.4"

src/extension.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as path from 'path';
22

3-
import * as vscode from 'vscode';
43
import escapeRegExp = require('lodash.escaperegexp');
4+
import * as vscode from 'vscode';
55

66
import * as filepaths from './managers/filepaths';
77
import * as fsUtils from './utils/fs';
@@ -12,16 +12,16 @@ import { IPluginSettings } from './types';
1212
/**
1313
* Open file after duplicate action.
1414
*/
15-
async function openFile(filepath: string) {
16-
const document = await vscode.workspace.openTextDocument(filepath);
15+
async function openFile(filepath: string): Promise<vscode.TextEditor> {
16+
const document = await (vscode.workspace.openTextDocument(filepath) as Promise<vscode.TextDocument>);
1717

1818
return vscode.window.showTextDocument(document);
1919
}
2020

2121
/**
2222
* Duplicate action.
2323
*/
24-
async function duplicator(uri: vscode.Uri, settings: IPluginSettings) {
24+
async function duplicator(uri: vscode.Uri, settings: IPluginSettings): Promise<vscode.TextEditor | undefined> {
2525
const oldPath = uri.fsPath;
2626
const oldPathParsed = path.parse(oldPath);
2727
const oldPathStats = await fsUtils.pathStat(oldPath);
@@ -38,6 +38,7 @@ async function duplicator(uri: vscode.Uri, settings: IPluginSettings) {
3838
// If a user tries to copy a file on the same path
3939
if (uri.fsPath === newPath) {
4040
vscode.window.showErrorMessage('You can\'t copy a file or directory on the same path.');
41+
4142
return;
4243
}
4344

@@ -69,19 +70,20 @@ async function duplicator(uri: vscode.Uri, settings: IPluginSettings) {
6970
return;
7071
}
7172

72-
export function activate(context: vscode.ExtensionContext) {
73+
export function activate(context: vscode.ExtensionContext): void {
7374
const command = vscode.commands.registerCommand('duplicate.execute', (uri: vscode.TextDocument | vscode.Uri) => {
75+
const settings = vscode.workspace.getConfiguration().get('duplicate') as IPluginSettings;
76+
7477
if (!uri || !(<vscode.Uri>uri).fsPath) {
7578
const editor = vscode.window.activeTextEditor;
7679
if (!editor) {
7780
return;
7881
}
79-
uri = editor.document.uri;
80-
}
8182

82-
const settings = vscode.workspace.getConfiguration().get('duplicate') as IPluginSettings;
83+
return duplicator(<vscode.Uri>editor.document.uri, settings);
84+
}
8385

84-
duplicator(<vscode.Uri>uri, settings);
86+
return duplicator(<vscode.Uri>uri, settings);
8587
});
8688

8789
context.subscriptions.push(command);

src/managers/filepaths.spec.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,18 @@ import * as path from 'path';
33

44
import * as manager from './filepaths';
55

6-
function getBuildedFilepath(oldName: string, newName: string, isFile: boolean, keep: boolean) {
6+
function getBuildedFilepath(oldName: string, newName: string, isFile: boolean, keep: boolean): string {
77
const oldPath = path.parse(`/Users/name/Documents/${oldName}`);
88

99
return manager.buildFilepath(
1010
oldPath,
11-
<any>{ isFile: () => isFile },
11+
{ isFile: () => isFile } as any, /* tslint:disable-line no-any */
1212
newName,
1313
{ keepOriginalExtension: keep, openFileAfterCopy: false }
1414
);
1515
}
1616

1717
describe('Managers → Filepaths', () => {
18-
1918
describe('.buildFilepath', () => {
2019
it('should build path to file', () => {
2120
const expected = '/Users/name/Documents/test.ts';
@@ -81,5 +80,4 @@ describe('Managers → Filepaths', () => {
8180
assert.equal(actual, expected);
8281
});
8382
});
84-
8583
});

src/managers/filepaths.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import * as path from 'path';
21
import * as fs from 'fs';
2+
import * as path from 'path';
33

44
import { IPluginSettings } from '../types';
55

src/utils/prompt.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
import * as vscode from 'vscode';
22

3-
export function name(filename: string) {
3+
export function name(filename: string): Promise<string | undefined> {
44
return vscode.window.showInputBox({
55
placeHolder: 'Enter the new path for the duplicate.',
66
value: filename.split('.').map((el, i) => i === 0 ? `${el}-copy` : el).join('.')
7-
});
7+
}) as Promise<string | undefined>;
88
}
99

10-
export function overwrite(filepath: string) {
10+
export function overwrite(filepath: string): Promise<vscode.MessageItem | undefined> {
1111
const message = `The path **${filepath}** alredy exists. Do you want to overwrite the existing path?`;
1212
const action = {
1313
title: 'OK',
1414
isCloseAffordance: false
1515
};
1616

17-
return vscode.window.showWarningMessage(message, action);
17+
return vscode.window.showWarningMessage(message, action) as Promise<vscode.MessageItem | undefined>;
1818
}

tslint.json

Lines changed: 4 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,8 @@
11
{
2-
"extends": [
3-
"tslint-config-xo/esnext"
4-
],
2+
"extends": ["tslint-config-mrmlnc"],
53
"rules": {
6-
"object-curly-spacing": false,
7-
"ter-arrow-parens": true,
8-
9-
"adjacent-overload-signatures": true,
10-
"member-access": true,
11-
"member-ordering": [
12-
true,
13-
{
14-
"order": [
15-
"static-field",
16-
"instance-field",
17-
"constructor",
18-
"public-instance-method",
19-
"protected-instance-method",
20-
"private-instance-method"
21-
]
22-
}
23-
],
24-
"no-empty-interface": "true",
25-
"no-reference": true,
26-
"no-var-requires": true,
27-
"typedef-whitespace": [
28-
true,
29-
{
30-
"call-signature": "nospace",
31-
"index-signature": "nospace",
32-
"parameter": "nospace",
33-
"property-declaration": "nospace",
34-
"variable-declaration": "nospace"
35-
}
36-
],
37-
"unified-signatures": true,
38-
"variable-name": [
39-
true,
40-
"check-format",
41-
"allow-leading-underscore"
42-
]
4+
"no-require-imports": false,
5+
"match-default-export-name": false,
6+
"max-file-line-count": false
437
}
448
}

0 commit comments

Comments
 (0)