Skip to content

Commit 16769a0

Browse files
committed
introduce linter
1 parent ea41761 commit 16769a0

6 files changed

Lines changed: 85 additions & 74 deletions

File tree

src/copy-github-URL.ts

Lines changed: 28 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
import * as child_process from 'child_process';
2-
import * as fs from 'fs';
1+
import * as child_process from "child_process";
32
import * as url from "url";
4-
import * as cp from 'copy-paste';
53

64
export function copyGithubURL(args: {
75
execGitCommand: (rootDir: string) => string,
@@ -12,22 +10,22 @@ export function copyGithubURL(args: {
1210
showInformationMessage: (message: string) => void,
1311
}) {
1412

15-
let stdout = args.execGitCommand(args.rootDir);
13+
const stdout = args.execGitCommand(args.rootDir);
1614

17-
let p = parseStdout(stdout);
15+
const p = parseStdout(stdout);
1816
if (!p) {
19-
return
17+
return;
2018
}
2119

22-
let url = buildGithubURL({
23-
domain: p.domain,
20+
const url = buildGithubURL({
2421
commit: p.sha1,
25-
repository: p.repository,
22+
domain: p.domain,
2623
filePath: args.filePath,
27-
line: args.line
28-
})
24+
line: args.line,
25+
repository: p.repository,
26+
});
2927
if (!url) {
30-
return
28+
return;
3129
}
3230
args.copy(url);
3331
args.showInformationMessage("copy! " + url);
@@ -38,54 +36,53 @@ export function buildGithubURL(args: {
3836
"commit": string,
3937
"repository": string,
4038
"filePath": string,
41-
"line": { start: number, end: number }
39+
"line": { start: number, end: number },
4240
}) {
4341

44-
let L = args.line.start === args.line.end ? `L${args.line.start}` : `L${args.line.start}-L${args.line.end}`
45-
let u = url.parse(`https://${args.domain}/${args.repository}/blob/${args.commit}/${args.filePath}/#${L}`);
46-
return u.href
42+
const L = args.line.start === args.line.end ? `L${args.line.start}` : `L${args.line.start}-L${args.line.end}`;
43+
const u = url.parse(`https://${args.domain}/${args.repository}/blob/${args.commit}/${args.filePath}/#${L}`);
44+
return u.href;
4745
}
4846

4947
export function parseStdout(stdout: string) {
5048

51-
let ret = {sha1: "", domain: "", repository: ""};
49+
const ret = {sha1: "", domain: "", repository: ""};
5250

53-
let sha1 = stdout.match(/^([a-z0-9]{40})$/m);
51+
const sha1 = stdout.match(/^([a-z0-9]{40})$/m);
5452
if (sha1 !== null && sha1[1]) {
5553
ret.sha1 = sha1[1];
5654
} else {
57-
return null
55+
return null;
5856
}
5957

60-
let isHTTP = stdout.match(/^origin\s+https(.*)\s+\(fetch\)$/m);
58+
const isHTTP = stdout.match(/^origin\s+https(.*)\s+\(fetch\)$/m);
6159

6260
if (isHTTP) {
63-
let m = stdout.match(/^origin\s+https?:\/\/([^\/]+)\/(.*)\.git\s+\(fetch\)$/m);
61+
const m = stdout.match(/^origin\s+https?:\/\/([^\/]+)\/(.*)\.git\s+\(fetch\)$/m);
6462

6563
if (m !== null && m[0] && m[1] && m[2]) {
6664
ret.domain = m[1];
67-
ret.repository = m[2]
68-
return ret
65+
ret.repository = m[2];
66+
return ret;
6967
} else {
70-
return null
68+
return null;
7169
}
7270

7371
} else {
74-
let m = stdout.match(/^origin(.*)@(.*):(.*)\.git\s+\(fetch\)$/m);
72+
const m = stdout.match(/^origin(.*)@(.*):(.*)\.git\s+\(fetch\)$/m);
7573

7674
if (m !== null && m[0] && m[1] && m[2] && m[3]) {
7775
ret.domain = m[2];
78-
ret.repository = m[3]
79-
return ret
76+
ret.repository = m[3];
77+
return ret;
8078
} else {
81-
return null
79+
return null;
8280
}
8381
}
8482
}
8583

8684
export function execGitCommand(rootDir: string): string {
8785

88-
let stdoutOrNull = null;
89-
let out = child_process.execSync(`cd ${rootDir}; git remote -v; git rev-parse HEAD`).toString();
86+
const out = child_process.execSync(`cd ${rootDir}; git remote -v; git rev-parse HEAD`).toString();
9087
return out;
91-
}
88+
}

src/extension.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
1-
import * as vscode from 'vscode';
1+
import * as cp from "copy-paste";
2+
import * as vscode from "vscode";
23

3-
import * as cgu from './copy-github-URL';
4-
import * as cp from 'copy-paste';
4+
import * as cgu from "./copy-github-URL";
55

66
export function activate(context: vscode.ExtensionContext) {
77

8-
let disposable = vscode.commands.registerCommand('extension.copyGithubURL', () => {
8+
const disposable = vscode.commands.registerCommand("extension.copyGithubURL", () => {
99

1010
const activeTextEditor = vscode.window.activeTextEditor;
1111

1212
if (activeTextEditor && vscode.workspace.rootPath) {
1313
cgu.copyGithubURL({
14-
execGitCommand: cgu.execGitCommand,
1514
copy: cp.copy,
16-
rootDir: vscode.workspace.rootPath,
15+
execGitCommand: cgu.execGitCommand,
1716
filePath: vscode.workspace.asRelativePath(activeTextEditor.document.fileName),
1817
line: {
18+
end: activeTextEditor.selection.end.line,
1919
start: activeTextEditor.selection.start.line,
20-
end: activeTextEditor.selection.end.line
2120
},
22-
showInformationMessage: vscode.window.showInformationMessage
21+
rootDir: vscode.workspace.rootPath,
22+
showInformationMessage: vscode.window.showInformationMessage,
2323
});
2424
}
2525

@@ -29,4 +29,5 @@ export function activate(context: vscode.ExtensionContext) {
2929
}
3030

3131
export function deactivate() {
32-
}
32+
return;
33+
}

test/copy-github-URL.ts

Lines changed: 25 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import * as assert from 'assert';
2-
import * as vscode from 'vscode';
3-
import * as myExtension from '../src/copy-github-url';
1+
import * as assert from "assert";
2+
import * as myExtension from "../src/copy-github-url";
43

54
suite("copyGithubUR", () => {
65

@@ -9,19 +8,19 @@ suite("copyGithubUR", () => {
98
origin git@github.com:t-mrt/copy-github-url.git (fetch)
109
origin git@github.com:t-mrt/copy-github-url.git (push)
1110
7332779b314e5aed7496bbacda35514655ef6399
12-
`
11+
`;
1312
let message;
1413

1514
myExtension.copyGithubURL({
16-
execGitCommand: (rootDir: string) => { return stdout },
17-
copy: (url: string) => { },
18-
rootDir: "/User/test/test",
15+
copy: () => { return; },
16+
execGitCommand: () => stdout,
1917
filePath: "test/test/test.pl",
2018
line: {
19+
end: 5,
2120
start: 2,
22-
end: 5
2321
},
24-
showInformationMessage: (m: string) => { message = m }
22+
rootDir: "/User/test/test",
23+
showInformationMessage: (m: string) => { message = m; },
2524
});
2625
assert.equal("copy! https://github.com/t-mrt/copy-github-url/blob/7332779b314e5aed7496bbacda35514655ef6399/test/test/test.pl/#L2-L5", message);
2726
});
@@ -32,59 +31,57 @@ suite("buildGithubURL", () => {
3231
test("multi line", () => {
3332

3433
assert.equal("https://github.com/t-mrt/copy-github-url/blob/7332779b314e5aed7496bbacda35514655ef6399//t/test.t/#L2-L3", myExtension.buildGithubURL({
35-
domain: "github.com",
3634
commit: "7332779b314e5aed7496bbacda35514655ef6399",
37-
repository: "t-mrt/copy-github-url",
35+
domain: "github.com",
3836
filePath: "/t/test.t",
39-
line: { start: 2, end: 3 }
37+
line: {
38+
end: 3,
39+
start: 2,
40+
},
41+
repository: "t-mrt/copy-github-url",
4042
}));
4143
});
4244

4345
test("single line", () => {
4446

45-
4647
assert.equal("https://github.com/t-mrt/copy-github-url/blob/7332779b314e5aed7496bbacda35514655ef6399//t/test.t/#L2", myExtension.buildGithubURL({
47-
domain: "github.com",
4848
commit: "7332779b314e5aed7496bbacda35514655ef6399",
49-
repository: "t-mrt/copy-github-url",
49+
domain: "github.com",
5050
filePath: "/t/test.t",
51-
line: { start: 2, end: 2 }
51+
line: { start: 2, end: 2 },
52+
repository: "t-mrt/copy-github-url",
5253
}));
53-
5454
});
55-
5655
});
5756

58-
5957
suite("parseGitRemoteStdout", () => {
6058

6159
test("git protocol", () => {
6260
assert.deepEqual({
63-
domain: 'github.com',
64-
repository: 't-mrt/gocha',
61+
domain: "github.com",
62+
repository: "t-mrt/gocha",
6563
sha1: "54c5e13a35ea88bd914284b99254e32afb34672d",
6664
}, myExtension.parseStdout(`
6765
origin git@github.com:t-mrt/gocha.git (fetch)
6866
origin git@github.com:t-mrt/gocha.git (push)
6967
54c5e13a35ea88bd914284b99254e32afb34672d
7068
`));
7169

72-
assert.equal(null, myExtension.parseStdout(''));
70+
assert.equal(null, myExtension.parseStdout(""));
7371
});
7472

75-
test("https protocol", () => {
73+
test("https protocol", () => {
7674
assert.deepEqual({
77-
domain: 'github.com',
78-
repository: 't-mrt/gocha',
75+
domain: "github.com",
76+
repository: "t-mrt/gocha",
7977
sha1: "54c5e13a35ea88bd914284b99254e32afb34672d",
8078
}, myExtension.parseStdout(`
8179
origin https://github.com/t-mrt/gocha.git (fetch)
8280
origin https://github.com/t-mrt/gocha.git (push)
8381
54c5e13a35ea88bd914284b99254e32afb34672d
8482
`));
8583

86-
assert.equal(null, myExtension.parseStdout(''));
84+
assert.equal(null, myExtension.parseStdout(""));
8785
});
8886

89-
90-
});
87+
});

test/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@
1010
// to report the results back to the caller. When the tests are finished, return
1111
// a possible error to the callback or null if none.
1212

13-
var testRunner = require('vscode/lib/testrunner');
13+
const testRunner = require("vscode/lib/testrunner");
1414

1515
// You can directly control Mocha options by uncommenting the following lines
1616
// See https://github.com/mochajs/mocha/wiki/Using-mocha-programmatically#set-options for more info
1717
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
18+
ui: "tdd", // the TDD UI is being used in extension.test.ts (suite, test, etc.)
19+
useColors: true, // colored output from test results
2020
});
2121

22-
module.exports = testRunner;
22+
module.exports = testRunner;

tsconfig.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
"es6"
88
],
99
"strict": true,
10-
"noUnusedLocals": false,
11-
"noUnusedParameters": false,
10+
"noUnusedLocals": true,
11+
"noUnusedParameters": true,
1212
"sourceMap": true,
1313
"rootDir": "."
1414
},

tslint.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"defaultSeverity": "error",
3+
"extends": [
4+
"tslint:recommended"
5+
],
6+
"jsRules": {},
7+
"rules": {
8+
"max-line-length": [
9+
false,
10+
120
11+
],
12+
"quotemark": [false],
13+
"no-var-requires": false
14+
},
15+
"rulesDirectory": []
16+
}

0 commit comments

Comments
 (0)