Skip to content

Commit 1f92cc8

Browse files
committed
linting galore
1 parent 49716fb commit 1f92cc8

File tree

4 files changed

+135
-58
lines changed

4 files changed

+135
-58
lines changed

src/clangMode.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
import vscode = require('vscode');
44

55
let languages: string[] = [];
6-
for (var l of ['cpp', 'c', 'objective-c', 'objective-cpp', 'java', 'javascript', 'typescript', 'proto']) {
6+
for (let l of ['cpp', 'c', 'objective-c', 'objective-cpp', 'java', 'javascript', 'typescript', 'proto']) {
77
if (vscode.workspace.getConfiguration('clang-format').get('language.' + l + '.enable')) {
88
languages.push(l);
99
}
1010
}
1111

12-
export const MODES: vscode.DocumentFilter[] = languages.map(language => ({language, scheme : 'file'}));
12+
export const MODES: vscode.DocumentFilter[] = languages.map((language) => ({language, scheme: 'file'}));

src/clangPath.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
import fs = require('fs');
44
import path = require('path');
55

6-
var binPathCache: {[bin: string] : string;} = {}
6+
let binPathCache: {[bin: string]: string} = {};
77

88
export function getBinPath(binname: string) {
99
if (binPathCache[binname]) {
10-
return binPathCache[binname]
11-
};
10+
return binPathCache[binname];
11+
}
1212

1313
for (let binNameToSearch of correctBinname(binname)) {
1414
// clang-format.executable has a valid absolute path
@@ -18,8 +18,8 @@ export function getBinPath(binname: string) {
1818
}
1919

2020
if (process.env['PATH']) {
21-
var pathparts = process.env['PATH'].split(path.delimiter);
22-
for (var i = 0; i < pathparts.length; i++) {
21+
let pathparts = process.env['PATH'].split(path.delimiter);
22+
for (let i = 0; i < pathparts.length; i++) {
2323
let binpath = path.join(pathparts[i], binNameToSearch);
2424
if (fs.existsSync(binpath)) {
2525
binPathCache[binname] = binpath;
@@ -34,10 +34,10 @@ export function getBinPath(binname: string) {
3434
return binname;
3535
}
3636

37-
function correctBinname(binname: string): [ string ] {
37+
function correctBinname(binname: string): [string] {
3838
if (process.platform === 'win32') {
39-
return [ binname + '.exe', binname + '.bat', binname + '.cmd', binname ];
39+
return [binname + '.exe', binname + '.bat', binname + '.cmd', binname];
4040
} else {
41-
return [ binname ];
41+
return [binname];
4242
}
4343
}

src/extension.ts

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ import sax = require('sax');
77

88
export class ClangDocumentFormattingEditProvider implements vscode.DocumentFormattingEditProvider, vscode.DocumentRangeFormattingEditProvider {
99
private defaultConfigure = {
10-
executable : 'clang-format',
11-
style : 'file',
12-
fallbackStyle : 'none',
13-
assumeFilename : ''
10+
executable: 'clang-format',
11+
style: 'file',
12+
fallbackStyle: 'none',
13+
assumeFilename: ''
1414
};
1515

1616
public provideDocumentFormattingEdits(document: vscode.TextDocument, options: vscode.FormattingOptions, token: vscode.CancellationToken): Thenable<vscode.TextEdit[]> {
@@ -23,25 +23,25 @@ export class ClangDocumentFormattingEditProvider implements vscode.DocumentForma
2323

2424
private getEdits(document: vscode.TextDocument, xml: string, codeContent: string): Thenable<vscode.TextEdit[]> {
2525
return new Promise((resolve, reject) => {
26-
var options = {
27-
trim : false,
28-
normalize : false,
29-
loose : true
26+
let options = {
27+
trim: false,
28+
normalize: false,
29+
loose: true
3030
};
31-
var parser = sax.parser(true, options);
31+
let parser = sax.parser(true, options);
3232

33-
var edits: vscode.TextEdit[] = [];
34-
var currentEdit: {length : number, offset : number, text : string};
33+
let edits: vscode.TextEdit[] = [];
34+
let currentEdit: {length: number, offset: number, text: string};
3535

36-
var codeBuffer = new Buffer(codeContent);
36+
let codeBuffer = new Buffer(codeContent);
3737
// encoding position cache
38-
var codeByteOffsetCache = {
39-
byte : 0,
40-
offset : 0
38+
let codeByteOffsetCache = {
39+
byte: 0,
40+
offset: 0
4141
};
42-
var byteToOffset = function(editInfo: {length : number, offset : number}) {
43-
var offset = editInfo.offset;
44-
var length = editInfo.length;
42+
let byteToOffset = function(editInfo: {length: number, offset: number}) {
43+
let offset = editInfo.offset;
44+
let length = editInfo.length;
4545

4646
if (offset >= codeByteOffsetCache.byte) {
4747
editInfo.offset = codeByteOffsetCache.offset + codeBuffer.slice(codeByteOffsetCache.byte, offset).toString('utf8').length;
@@ -73,9 +73,9 @@ export class ClangDocumentFormattingEditProvider implements vscode.DocumentForma
7373

7474
case 'replacement':
7575
currentEdit = {
76-
length : parseInt(tag.attributes['length'].toString()),
77-
offset : parseInt(tag.attributes['offset'].toString()),
78-
text : ''
76+
length: parseInt(tag.attributes['length'].toString()),
77+
offset: parseInt(tag.attributes['offset'].toString()),
78+
text: ''
7979
};
8080
byteToOffset(currentEdit);
8181
break;
@@ -95,10 +95,10 @@ export class ClangDocumentFormattingEditProvider implements vscode.DocumentForma
9595
parser.onclosetag = (tagName) => {
9696
if (!currentEdit) { return; }
9797

98-
var start = document.positionAt(currentEdit.offset);
99-
var end = document.positionAt(currentEdit.offset + currentEdit.length);
98+
let start = document.positionAt(currentEdit.offset);
99+
let end = document.positionAt(currentEdit.offset + currentEdit.length);
100100

101-
var editRange = new vscode.Range(start, end);
101+
let editRange = new vscode.Range(start, end);
102102

103103
edits.push(new vscode.TextEdit(editRange, currentEdit.text));
104104
currentEdit = null;
@@ -169,12 +169,12 @@ export class ClangDocumentFormattingEditProvider implements vscode.DocumentForma
169169

170170
private doFormatDocument(document: vscode.TextDocument, range: vscode.Range, options: vscode.FormattingOptions, token: vscode.CancellationToken): Thenable<vscode.TextEdit[]> {
171171
return new Promise((resolve, reject) => {
172-
var filename = document.fileName;
172+
let filename = document.fileName;
173173

174-
var formatCommandBinPath = getBinPath(this.getExecutablePath());
175-
var codeContent = document.getText();
174+
let formatCommandBinPath = getBinPath(this.getExecutablePath());
175+
let codeContent = document.getText();
176176

177-
var childCompleted = (err, stdout, stderr) => {
177+
let childCompleted = (err, stdout, stderr) => {
178178
try {
179179
if (err && (<any>err).code === 'ENOENT') {
180180
vscode.window.showInformationMessage('The \'' + formatCommandBinPath + '\' command is not available. Please check your clang-format.executable user setting and ensure it is installed.');
@@ -184,7 +184,7 @@ export class ClangDocumentFormattingEditProvider implements vscode.DocumentForma
184184
return reject('Cannot format due to syntax errors.');
185185
}
186186

187-
var dummyProcessor = (value: string) => {
187+
let dummyProcessor = (value: string) => {
188188
debugger;
189189
return value;
190190
};
@@ -195,16 +195,16 @@ export class ClangDocumentFormattingEditProvider implements vscode.DocumentForma
195195
}
196196
};
197197

198-
var formatArgs = [
198+
let formatArgs = [
199199
'-output-replacements-xml',
200200
`-style=${this.getStyle(document)}`,
201201
`-fallback-style=${this.getFallbackStyle(document)}`,
202-
`-assume-filename=${this.getAssumedFilename(document)}`,
202+
`-assume-filename=${this.getAssumedFilename(document)}`
203203
];
204204

205205
if (range) {
206-
var offset = document.offsetAt(range.start);
207-
var length = document.offsetAt(range.end) - offset;
206+
let offset = document.offsetAt(range.start);
207+
let length = document.offsetAt(range.end) - offset;
208208

209209
// fix charater length to byte length
210210
length = Buffer.byteLength(codeContent.substr(offset, length), 'utf8');
@@ -214,12 +214,12 @@ export class ClangDocumentFormattingEditProvider implements vscode.DocumentForma
214214
formatArgs.push(`-offset=${offset}`, `-length=${length}`);
215215
}
216216

217-
var workingPath = vscode.workspace.rootPath;
217+
let workingPath = vscode.workspace.rootPath;
218218
if (!document.isUntitled) {
219219
workingPath = path.dirname(document.fileName);
220220
}
221221

222-
var child = cp.execFile(formatCommandBinPath, formatArgs, {cwd : workingPath}, childCompleted);
222+
let child = cp.execFile(formatCommandBinPath, formatArgs, {cwd: workingPath}, childCompleted);
223223
child.stdin.end(codeContent);
224224

225225
if (token) {
@@ -240,10 +240,10 @@ let diagnosticCollection: vscode.DiagnosticCollection;
240240

241241
export function activate(ctx: vscode.ExtensionContext): void {
242242

243-
var formatter = new ClangDocumentFormattingEditProvider();
244-
var availableLanguages = {};
243+
let formatter = new ClangDocumentFormattingEditProvider();
244+
let availableLanguages = {};
245245

246-
MODES.forEach(mode => {
246+
MODES.forEach((mode) => {
247247
ctx.subscriptions.push(vscode.languages.registerDocumentRangeFormattingEditProvider(mode, formatter));
248248
ctx.subscriptions.push(vscode.languages.registerDocumentFormattingEditProvider(mode, formatter));
249249
availableLanguages[mode.language] = true;

tslint.json

Lines changed: 87 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,89 @@
11
{
2-
"rules": {
3-
"no-unused-expression": true,
4-
"no-duplicate-variable": true,
5-
"no-duplicate-key": true,
6-
"no-unused-variable": true,
7-
"curly": true,
8-
"class-name": true,
9-
"semicolon": ["always"],
10-
"triple-equals": true
11-
}
2+
"rules": {
3+
"array-type": [
4+
true,
5+
"array-simple"
6+
],
7+
"arrow-parens": true,
8+
"no-var-keyword": true,
9+
"no-unused-variable": [
10+
true,
11+
{
12+
"ignore-pattern": "^_"
13+
}
14+
],
15+
"ordered-imports": [
16+
true,
17+
{
18+
"import-sources-order": "lowercase-last",
19+
"named-imports-order": "lowercase-first"
20+
}
21+
],
22+
"trailing-comma": [
23+
true,
24+
{
25+
"multiline": "never",
26+
"singleline": "never"
27+
}
28+
],
29+
"class-name": true,
30+
"comment-format": [
31+
true,
32+
"check-space"
33+
],
34+
"indent": [
35+
true,
36+
"spaces"
37+
],
38+
"no-eval": true,
39+
"no-internal-module": true,
40+
"no-trailing-whitespace": true,
41+
"no-unsafe-finally": true,
42+
"one-line": [
43+
true,
44+
"check-open-brace",
45+
"check-whitespace"
46+
],
47+
"quotemark": [
48+
true,
49+
"single"
50+
],
51+
"semicolon": [
52+
true,
53+
"always"
54+
],
55+
"triple-equals": [
56+
true,
57+
"allow-null-check"
58+
],
59+
"typedef-whitespace": [
60+
true,
61+
{
62+
"call-signature": "nospace",
63+
"index-signature": "nospace",
64+
"parameter": "nospace",
65+
"property-declaration": "nospace",
66+
"variable-declaration": "nospace"
67+
}
68+
],
69+
"variable-name": [
70+
true,
71+
"ban-keywords"
72+
],
73+
"whitespace": [
74+
true,
75+
"check-branch",
76+
"check-decl",
77+
"check-operator",
78+
"check-separator",
79+
"check-type"
80+
]
81+
},
82+
"jsRules": {
83+
"triple-equals": [
84+
true,
85+
"allow-null-check"
86+
]
87+
},
88+
"defaultSeverity": "warning"
1289
}

0 commit comments

Comments
 (0)