Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 691ab85

Browse files
committed
Add eslint
1 parent 8987efc commit 691ab85

File tree

11 files changed

+715
-93
lines changed

11 files changed

+715
-93
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ jobs:
1818
- name: Compile extension
1919
run: |
2020
yarn install --frozen-lockfile
21+
yarn lint
2122
yarn compile
2223
# Run tests (including a special build of extension w/ tsc, not esbuild)
2324
test:

package.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@
9999
"clean": "rm -rf ./out",
100100
"compile": "yarn run esbuild-base --sourcemap",
101101
"esbuild-base": "esbuild --bundle --external:vscode --external:vscode-languageclient --format=cjs --outfile=out/extension.js --platform=node src/extension.ts",
102+
"lint": "eslint .",
102103
"package": "vsce package --no-yarn --githubBranch main",
103104
"publish": "vsce publish --no-yarn --githubBranch main",
104105
"test": "node ./out/test/runTest.js",
@@ -115,13 +116,31 @@
115116
"@types/mocha": "^9.1.1",
116117
"@types/node": "^18.0.0",
117118
"@types/vscode": "^1.68.0",
119+
"@typescript-eslint/eslint-plugin": "^5.33.1",
120+
"@typescript-eslint/parser": "^5.33.1",
118121
"@vscode/test-electron": "^1.6.2",
119122
"esbuild": "^0.15.0",
123+
"eslint": "^8.22.0",
120124
"glob": "^8.0.3",
121125
"mocha": "^10.0.0",
122126
"typescript": "^4.7.4",
123127
"vsce": "^2.9.2"
124128
},
129+
"eslintConfig": {
130+
"parser": "@typescript-eslint/parser",
131+
"plugins": [
132+
"@typescript-eslint"
133+
],
134+
"extends": [
135+
"eslint:recommended",
136+
"plugin:@typescript-eslint/eslint-recommended",
137+
"plugin:@typescript-eslint/recommended"
138+
],
139+
"rules": {
140+
"quotes": ["error", "double"],
141+
"semi": "error"
142+
}
143+
},
125144
"__metadata": {
126145
"id": "b46118f9-0f6f-4320-9e2e-75c96492b4cb",
127146
"publisherDisplayName": "ruby-syntax-tree",

src/Visualize.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { commands, Disposable, languages, OutputChannel, ProviderResult, TextDocumentContentProvider, Uri, ViewColumn, window, workspace } from "vscode";
1+
import { Disposable, languages, OutputChannel, ProviderResult, TextDocumentContentProvider, Uri, ViewColumn, window, workspace } from "vscode";
22
import { LanguageClient } from "vscode-languageclient/node";
33

44
class Visualize implements Disposable, TextDocumentContentProvider {

src/extension.ts

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { promisify } from "util";
66
import { ExtensionContext, commands, window, workspace } from "vscode";
77
import { LanguageClient, ServerOptions } from "vscode-languageclient/node";
88

9-
import * as variables from './variables';
9+
import * as variables from "./variables";
1010
import Visualize from "./Visualize";
1111

1212
const promiseExec = promisify(exec);
@@ -92,7 +92,7 @@ export async function activate(context: ExtensionContext) {
9292
}
9393

9494
// Configure print width.
95-
args.push(`--print-width=${config.get<number>("printWidth")}`)
95+
args.push(`--print-width=${config.get<number>("printWidth")}`);
9696

9797
// There's a bit of complexity here. Basically, we try to locate
9898
// an stree executable in three places, in order of preference:
@@ -108,7 +108,7 @@ export async function activate(context: ExtensionContext) {
108108
// Explicit path varies between machines/users and is also victim to the
109109
// oversimplification problem.
110110
let run: ServerOptions = { command: "stree", args };
111-
let commandPath = advancedConfig.get<string>('commandPath');
111+
let commandPath = advancedConfig.get<string>("commandPath");
112112
if (commandPath) {
113113
commandPath = variables.substitute(commandPath);
114114
try {
@@ -128,7 +128,7 @@ export async function activate(context: ExtensionContext) {
128128
}
129129
}
130130

131-
outputChannel.appendLine(`Starting language server: ${run.command} ${run.args?.join(' ')}`);
131+
outputChannel.appendLine(`Starting language server: ${run.command} ${run.args?.join(" ")}`);
132132

133133
// Here, we instantiate the language client. This is the object that is
134134
// responsible for the communication and management of the Ruby subprocess.
@@ -147,26 +147,26 @@ export async function activate(context: ExtensionContext) {
147147
// add the various features to the extension. Each of them in turn
148148
// implements Disposable so that they clean up their own resources.
149149
visualizer = new Visualize(languageClient, outputChannel);
150-
context.subscriptions.push(
151-
visualizer
152-
);
153-
} catch (e: any) {
150+
context.subscriptions.push(visualizer);
151+
} catch (error) {
154152
languageClient = null;
155-
const items = ['Restart']
156-
let msg = 'Something went wrong.';
157-
if (typeof e === 'string') {
158-
if (/ENOENT/.test(e)) {
159-
msg = 'Command not found. Is the syntax_tree RubyGem installed?';
160-
items.unshift('Install Gem');
153+
154+
const items = ["Restart"];
155+
let msg = "Something went wrong.";
156+
157+
if (typeof error === "string") {
158+
if (/ENOENT/.test(error)) {
159+
msg = "Command not found. Is the syntax_tree gem installed?";
160+
items.unshift("Install Gem");
161161
}
162162
}
163163

164164
const action = await window.showErrorMessage(msg, ...items);
165165
switch (action) {
166-
case 'Install Gem':
166+
case "Install Gem":
167167
installGem();
168168
break;
169-
case 'Restart':
169+
case "Restart":
170170
startLanguageServer();
171171
break;
172172
}
@@ -196,12 +196,11 @@ export async function activate(context: ExtensionContext) {
196196
// This function is called when the user wants to recover from ENOENT
197197
// on start. It starts the language server afterward.
198198
async function installGem() {
199-
const cwd = getCWD();
200199
try {
201-
await promiseExec("gem install syntax_tree", { cwd });
200+
await promiseExec("gem install syntax_tree", { cwd: getCWD() });
202201
startLanguageServer();
203-
} catch (e) {
204-
outputChannel.appendLine("Error installing gem: " + e);
202+
} catch (error) {
203+
outputChannel.appendLine(`Error installing gem: ${error}`);
205204
}
206205
}
207206

src/test/runTest.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
import { runTests } from '@vscode/test-electron';
2-
import * as path from 'path';
1+
import { runTests } from "@vscode/test-electron";
2+
import * as path from "path";
33

4-
import { USER_DATA_DIR, WORKSPACE_DIR } from './suite/setup';
4+
import { USER_DATA_DIR, WORKSPACE_DIR } from "./suite/setup";
55

66
async function main() {
77
try {
88
// The folder containing the Extension Manifest package.json
99
// Passed to `--extensionDevelopmentPath`
10-
const extensionDevelopmentPath = path.resolve(__dirname, '../../');
10+
const extensionDevelopmentPath = path.resolve(__dirname, "../../");
1111

1212
// The path to the extension test script
1313
// Passed to --extensionTestsPath
14-
const extensionTestsPath = path.resolve(__dirname, './suite/index');
14+
const extensionTestsPath = path.resolve(__dirname, "./suite/index");
1515

1616
// Download VS Code, unzip it and run the integration test
17-
await runTests({ extensionDevelopmentPath, extensionTestsPath, launchArgs: ['--disable-extensions', '--disable-gpu', '--user-data-dir', USER_DATA_DIR, WORKSPACE_DIR] });
17+
await runTests({ extensionDevelopmentPath, extensionTestsPath, launchArgs: ["--disable-extensions", "--disable-gpu", "--user-data-dir", USER_DATA_DIR, WORKSPACE_DIR] });
1818
} catch (err) {
19-
console.error('Failed to run tests');
19+
console.error("Failed to run tests");
2020
process.exit(1);
2121
}
2222
}

src/test/suite/automation.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
import * as assert from 'assert';
2-
import * as path from 'path';
3-
import { TextEncoder } from 'util';
1+
import * as assert from "assert";
2+
import * as path from "path";
3+
import { TextEncoder } from "util";
44

5-
import { Uri, commands, window, workspace } from 'vscode';
5+
import { Uri, commands, window, workspace } from "vscode";
66

7-
import { WORKSPACE_DIR } from './setup';
7+
import { WORKSPACE_DIR } from "./setup";
88

99
export async function reset() {
10-
await commands.executeCommand('workbench.action.closeAllEditors');
10+
await commands.executeCommand("workbench.action.closeAllEditors");
1111
}
1212

1313
export async function createEditor(content: string) {
@@ -25,21 +25,21 @@ export function findNewestEditor() {
2525
}
2626

2727
export function formatDocument() {
28-
return commands.executeCommand('editor.action.formatDocument', 'ruby-syntax-tree.vscode-syntax-tree');
28+
return commands.executeCommand("editor.action.formatDocument", "ruby-syntax-tree.vscode-syntax-tree");
2929
}
3030

3131
export function restart() {
32-
return commands.executeCommand('syntaxTree.restart');
32+
return commands.executeCommand("syntaxTree.restart");
3333
}
3434

3535
export function start() {
36-
return commands.executeCommand('syntaxTree.start');
36+
return commands.executeCommand("syntaxTree.start");
3737
}
3838

3939
export function stop() {
40-
return commands.executeCommand('syntaxTree.stop');
40+
return commands.executeCommand("syntaxTree.stop");
4141
}
4242

4343
export function visualize() {
44-
return commands.executeCommand('syntaxTree.visualize');
44+
return commands.executeCommand("syntaxTree.visualize");
4545
}

src/test/suite/index.test.ts

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import * as assert from 'assert';
2-
import { before, beforeEach } from 'mocha';
3-
import { State } from 'vscode-languageclient';
1+
import * as assert from "assert";
2+
import { before, beforeEach } from "mocha";
3+
import { State } from "vscode-languageclient";
44

5-
import * as auto from './automation';
6-
import * as extension from '../../extension';
5+
import * as auto from "./automation";
6+
import * as extension from "../../extension";
77

8-
const UNFORMATTED = `class Foo; def bar; puts 'baz'; end; end`;
8+
const UNFORMATTED = "class Foo; def bar; puts 'baz'; end; end";
99

1010
const FORMATTED = `class Foo
1111
def bar
@@ -14,43 +14,43 @@ const FORMATTED = `class Foo
1414
end
1515
`;
1616

17-
suite('Syntax Tree', () => {
17+
suite("Syntax Tree", () => {
1818
beforeEach(auto.reset);
1919

20-
suite('lifecycle commands', () => {
21-
test('start', async () => {
20+
suite("lifecycle commands", () => {
21+
test("start", async () => {
2222
await auto.start();
23-
assert.notEqual(extension.languageClient, null)
24-
assert.equal(extension.languageClient?.state, State.Running)
23+
assert.notEqual(extension.languageClient, null);
24+
assert.equal(extension.languageClient?.state, State.Running);
2525
});
2626

27-
test('stop', async () => {
27+
test("stop", async () => {
2828
await auto.start();
2929
await auto.stop();
30-
assert.equal(extension.languageClient, null)
31-
})
30+
assert.equal(extension.languageClient, null);
31+
});
3232

33-
test('restart', async () => {
33+
test("restart", async () => {
3434
await auto.restart();
35-
assert.notEqual(extension.languageClient, null)
36-
assert.equal(extension.languageClient?.state, State.Running)
37-
})
35+
assert.notEqual(extension.languageClient, null);
36+
assert.equal(extension.languageClient?.state, State.Running);
37+
});
3838
});
3939

40-
suite('functional commands', () => {
40+
suite("functional commands", () => {
4141
before(auto.start);
4242

43-
test('format', async () => {
43+
test("format", async () => {
4444
const editor = await auto.createEditor(UNFORMATTED);
4545
await auto.formatDocument();
4646
assert.equal(editor.document.getText(), FORMATTED);
4747
});
4848

49-
test('visualize', async () => {
49+
test("visualize", async () => {
5050
await auto.createEditor(UNFORMATTED);
5151
await auto.visualize();
5252
const editor = auto.findNewestEditor();
5353
assert.match(editor.document.getText(), /^\(program/);
54-
})
55-
})
54+
});
55+
});
5656
});

src/test/suite/index.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import * as path from 'path';
2-
import * as Mocha from 'mocha';
3-
import * as glob from 'glob';
1+
import * as path from "path";
2+
import * as Mocha from "mocha";
3+
import * as glob from "glob";
44

5-
import { TIMEOUT_MS } from './setup';
5+
import { TIMEOUT_MS } from "./setup";
66

77
export function run(): Promise<void> {
88
const mocha = new Mocha({
@@ -11,13 +11,13 @@ export function run(): Promise<void> {
1111
forbidOnly: !!process.env.CI,
1212
slow: TIMEOUT_MS / 4,
1313
timeout: TIMEOUT_MS,
14-
ui: 'tdd'
14+
ui: "tdd"
1515
});
1616

17-
const testsRoot = path.resolve(__dirname, '..');
17+
const testsRoot = path.resolve(__dirname, "..");
1818

1919
return new Promise((c, e) => {
20-
glob('**/**.test.js', { cwd: testsRoot }, (err, files) => {
20+
glob("**/**.test.js", { cwd: testsRoot }, (err, files) => {
2121
if (err) {
2222
return e(err);
2323
}

src/test/suite/setup.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import * as fs from 'fs';
2-
import * as os from 'os';
3-
import * as path from 'path';
1+
import * as fs from "fs";
2+
import * as os from "os";
3+
import * as path from "path";
44

55
// Share scratch dir between runner and Code process via clever env trick
66
const inheritedScratchDir = process.env.RUBY_SYNTAX_TREE_TEST_SCRATCH_DIR;
@@ -13,13 +13,13 @@ export const TIMEOUT_MS = process.env.CI ? 30000 : 300000;
1313

1414
/// Holds profile, settings, etc - to give us a clean slate every time
1515
/// & avoid polluting developer's real profile
16-
export const USER_DATA_DIR = path.join(SCRATCH_DIR, 'user-data');
16+
export const USER_DATA_DIR = path.join(SCRATCH_DIR, "user-data");
1717

1818
/// Holds text documents that we author during tests.
19-
export const WORKSPACE_DIR = path.join(SCRATCH_DIR, 'workspace');
19+
export const WORKSPACE_DIR = path.join(SCRATCH_DIR, "workspace");
2020

2121
if (!inheritedScratchDir) { // We're the parent; adulting is hard!
2222
fs.mkdirSync(USER_DATA_DIR);
2323
fs.mkdirSync(WORKSPACE_DIR);
24-
console.log('Scratch folder:', SCRATCH_DIR);
24+
console.log("Scratch folder:", SCRATCH_DIR);
2525
}

src/variables.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
import * as os from 'os';
2-
import * as path from 'path';
1+
import * as os from "os";
2+
import * as path from "path";
33

4-
const substitution = new RegExp('\\$\\{([^}]*)\\}');
4+
const substitution = new RegExp("\\$\\{([^}]*)\\}");
55

66
export function substitute(s: string) {
77
let match = substitution.exec(s);
88
while (match) {
99
const variable = match[1];
1010
switch (variable) {
11-
case 'cwd':
11+
case "cwd":
1212
s = s.replace(match[0], process.cwd());
1313
break;
14-
case 'pathSeparator':
14+
case "pathSeparator":
1515
s = s.replace(match[0], path.sep);
1616
break;
17-
case 'userHome':
17+
case "userHome":
1818
s = s.replace(match[0], os.homedir());
1919
break;
2020
}

0 commit comments

Comments
 (0)