Skip to content

Commit 38f7515

Browse files
authored
Fix security warnings (#39)
1 parent 27b2e31 commit 38f7515

File tree

7 files changed

+1188
-971
lines changed

7 files changed

+1188
-971
lines changed

.eslintrc.json

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
{
2+
"root": true,
3+
"parser": "@typescript-eslint/parser",
4+
"extends": [
5+
"eslint:recommended",
6+
"plugin:@typescript-eslint/recommended",
7+
"prettier"
8+
],
9+
"parserOptions": {
10+
"ecmaVersion": 6,
11+
"sourceType": "module"
12+
},
13+
"plugins": ["@typescript-eslint"],
14+
"rules": {
15+
"@typescript-eslint/consistent-type-assertions": [
16+
"error",
17+
{
18+
"assertionStyle": "as"
19+
}
20+
],
21+
"@typescript-eslint/naming-convention": "warn",
22+
"@typescript-eslint/no-explicit-any": "off",
23+
"@typescript-eslint/no-inferrable-types": "off",
24+
"@typescript-eslint/no-non-null-assertion": "off",
25+
"@typescript-eslint/no-unused-vars": [
26+
"warn",
27+
{
28+
"argsIgnorePattern": "^_",
29+
"varsIgnorePattern": "^_",
30+
"ignoreRestSiblings": true
31+
}
32+
],
33+
"curly": "warn",
34+
"eqeqeq": [
35+
"warn",
36+
"always",
37+
{
38+
"null": "never"
39+
}
40+
],
41+
"no-constant-condition": ["error", { "checkLoops": false }],
42+
"no-throw-literal": "warn",
43+
"semi": "off"
44+
},
45+
"ignorePatterns": ["**/vendor/**/*.ts", "**/vendor/**/*.js"]
46+
}
47+

package.json

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"ui"
1515
],
1616
"engines": {
17-
"vscode": "^1.34.0"
17+
"vscode": "^1.58.0"
1818
},
1919
"categories": [
2020
"Programming Languages",
@@ -65,16 +65,20 @@
6565
"compile": "tsc -p ./ && make parsers",
6666
"watch": "tsc -watch -p ./",
6767
"preinstall": "make web-tree-sitter",
68-
"postinstall": "node ./node_modules/vscode/bin/install",
6968
"test": "npm run compile && node ./out/test",
7069
"benchmark": "npm run compile && node ./out/benchmark",
7170
"debug": "npm run compile && node --nolazy --inspect-brk=9229 ./out/test",
71+
"lint": "eslint src --ext ts",
7272
"build": "vsce package -o build.vsix",
7373
"publish": "vsce publish patch"
7474
},
7575
"devDependencies": {
7676
"@types/mocha": "^2.2.42",
7777
"@types/node": "^8.10.25",
78+
"@typescript-eslint/eslint-plugin": "^5.20.0",
79+
"@typescript-eslint/parser": "^5.20.0",
80+
"eslint": "^8.13.0",
81+
"eslint-config-prettier": "^8.5.0",
7882
"electron-rebuild": "^2.3.5",
7983
"tree-sitter-agda": "github:pokey/tree-sitter-agda#e5fba6cabe8c7fc7993ced2b86704f3841215284",
8084
"tree-sitter-bash": "^0.19.0",
@@ -104,9 +108,9 @@
104108
"tree-sitter-typescript": "github:tree-sitter/tree-sitter-typescript#master",
105109
"tree-sitter-yaml": "^0.5.0",
106110
"tslint": "^6.0.0",
107-
"typescript": "^3.8.2",
108-
"vsce": "^1.73.0",
109-
"vscode": "^1.1.36"
111+
"typescript": "^4.5.5",
112+
"@types/vscode": "~1.58.0",
113+
"@vscode/test-electron": "^2.1.3"
110114
},
111115
"dependencies": {
112116
"jsonc-parser": "^2.1.0",

src/extension.ts

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,12 @@ export async function activate(context: vscode.ExtensionContext) {
6060
*/
6161
async function loadLanguage(languageId: string) {
6262
const language = languages[languageId];
63-
if (language == null) return false;
64-
if (language.parser != null) return true;
63+
if (language == null) {
64+
return false;
65+
}
66+
if (language.parser != null) {
67+
return true;
68+
}
6569

6670
const absolute = path.join(
6771
context.extensionPath,
@@ -79,9 +83,13 @@ export async function activate(context: vscode.ExtensionContext) {
7983

8084
async function open(document: vscode.TextDocument) {
8185
const uriString = document.uri.toString();
82-
if (uriString in trees) return;
86+
if (uriString in trees) {
87+
return;
88+
}
8389

84-
if (!(await loadLanguage(document.languageId))) return;
90+
if (!(await loadLanguage(document.languageId))) {
91+
return;
92+
}
8593

8694
const language = languages[document.languageId];
8795
const t = language.parser!.parse(document.getText()); // TODO don't use getText, use Parser.Input
@@ -90,11 +98,17 @@ export async function activate(context: vscode.ExtensionContext) {
9098

9199
function openIfLanguageLoaded(document: vscode.TextDocument) {
92100
const uriString = document.uri.toString();
93-
if (uriString in trees) return null;
101+
if (uriString in trees) {
102+
return null;
103+
}
94104

95105
const language = languages[document.languageId];
96-
if (language == null) return null;
97-
if (language.parser == null) return null;
106+
if (language == null) {
107+
return null;
108+
}
109+
if (language.parser == null) {
110+
return null;
111+
}
98112

99113
const t = language.parser.parse(document.getText()); // TODO don't use getText, use Parser.Input
100114
trees[uriString] = t;
@@ -104,12 +118,16 @@ export async function activate(context: vscode.ExtensionContext) {
104118
// NOTE: if you make this an async function, it seems to cause edit anomalies
105119
function edit(edit: vscode.TextDocumentChangeEvent) {
106120
const language = languages[edit.document.languageId];
107-
if (language == null || language.parser == null) return;
121+
if (language == null || language.parser == null) {
122+
return;
123+
}
108124
updateTree(language.parser, edit);
109125
}
110126

111127
function updateTree(parser: Parser, edit: vscode.TextDocumentChangeEvent) {
112-
if (edit.contentChanges.length == 0) return;
128+
if (edit.contentChanges.length === 0) {
129+
return;
130+
}
113131
const old = trees[edit.document.uri.toString()];
114132
for (const e of edit.contentChanges) {
115133
const startIndex = e.rangeOffset;
@@ -219,4 +237,6 @@ export async function activate(context: vscode.ExtensionContext) {
219237
}
220238

221239
// this method is called when your extension is deactivated
222-
export function deactivate() {}
240+
export function deactivate() {
241+
// Empty
242+
}

src/scopes.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export async function load() {
2727
colors.clear()
2828
// Find out current color theme
2929
const themeName = vscode.workspace.getConfiguration("workbench").get("colorTheme")
30-
if (typeof themeName != 'string') {
30+
if (typeof themeName !== 'string') {
3131
console.warn('workbench.colorTheme is', themeName)
3232
return
3333
}
@@ -52,7 +52,7 @@ async function loadThemeNamed(themeName: string) {
5252
if (packageJson.contributes && packageJson.contributes.themes) {
5353
for (const theme of packageJson.contributes.themes) {
5454
const id = theme.id || theme.label
55-
if (id == themeName) {
55+
if (id === themeName) {
5656
const themeRelativePath: string = theme.path
5757
const themeFullPath: string = path.join(extensionPath, themeRelativePath)
5858
await loadThemeFile(themeFullPath)
@@ -79,7 +79,7 @@ async function loadThemeFile(themePath: string) {
7979

8080
function loadColors(textMateRules: TextMateRule[]): void {
8181
for (const rule of textMateRules) {
82-
if (typeof rule.scope == 'string') {
82+
if (typeof rule.scope === 'string') {
8383
if (!colors.has(rule.scope)) {
8484
colors.set(rule.scope, rule.settings)
8585
}
@@ -94,7 +94,7 @@ function loadColors(textMateRules: TextMateRule[]): void {
9494
}
9595

9696
function checkFileExists(filePath: string): Promise<boolean> {
97-
return new Promise((resolve, reject) => {
97+
return new Promise((resolve, _reject) => {
9898
fs.stat(filePath, (err, stats) => {
9999
if (stats && stats.isFile()) {
100100
resolve(true)

tsconfig.json

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,12 @@
44
"target": "es6",
55
"outDir": "out",
66
"lib": [
7-
"es6"
7+
"es2020"
88
],
99
"sourceMap": true,
1010
"rootDir": "src",
11-
/* Strict Type-Checking Option */
12-
"strict": true, /* enable all strict type-checking options */
11+
"strict": true /* enable all strict type-checking options */
1312
/* Additional Checks */
14-
"noUnusedLocals": true /* Report errors on unused locals. */
1513
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
1614
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
1715
// "noUnusedParameters": true, /* Report errors on unused parameters. */
@@ -23,4 +21,4 @@
2321
"node_modules",
2422
"vendor"
2523
]
26-
}
24+
}

tslint.json

Lines changed: 0 additions & 10 deletions
This file was deleted.

0 commit comments

Comments
 (0)