Skip to content

Commit 0749443

Browse files
committed
Migrate from tslint to eslint and cleanup for stricter rules.
https://code.visualstudio.com/api/advanced-topics/tslint-eslint-migration
1 parent 3194229 commit 0749443

11 files changed

+317
-818
lines changed

.eslintrc.js

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
module.exports = {
2+
"env": {
3+
"es6": true,
4+
"node": true
5+
},
6+
"parser": "@typescript-eslint/parser",
7+
"parserOptions": {
8+
"project": "tsconfig.json",
9+
"sourceType": "module"
10+
},
11+
"extends": [
12+
'eslint:recommended',
13+
//'plugin:jsdoc/recommended',
14+
'plugin:@typescript-eslint/eslint-recommended',
15+
'plugin:@typescript-eslint/recommended',
16+
'plugin:@typescript-eslint/recommended-requiring-type-checking',
17+
'prettier',
18+
],
19+
"plugins": [
20+
"eslint-plugin-jsdoc",
21+
"@typescript-eslint",
22+
],
23+
"root": true,
24+
"rules": {
25+
'@typescript-eslint/no-unsafe-assignment': 'off',
26+
}
27+
};

.github/workflows/ci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,5 @@ jobs:
2121
- name: Prettier
2222
run: npm run prettier-check
2323
- name: Lint
24-
run: npm run tslint
24+
run: npm run eslint
2525
- run: xvfb-run -a npm test

.prettierignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
.vscode-test/
12
coverage/
23
out/
34
package-lock.json

package-lock.json

+237-766
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+13-14
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
"watch": "tsc -watch -p ./",
2121
"pretest": "npm run compile",
2222
"compile": "npm run clean && tsc -p ./",
23-
"lint": "npm run tslint && npm run prettier",
24-
"tslint": "tslint \"src/**/*.ts\"",
23+
"lint": "npm run eslint && npm run prettier",
24+
"eslint": "eslint \"src/**/*.ts\"",
2525
"prettier": "prettier \"**/{*.json,*.yml,.*.yml,*.ts,.prettierrc,*.md}\" --write --list-different",
2626
"prettier-check": "npm run prettier -- --write=false",
2727
"test": "node ./out/test/runTests.js"
@@ -132,27 +132,26 @@
132132
"author": "[email protected]",
133133
"license": "MIT",
134134
"devDependencies": {
135-
"@chemzqm/tsconfig": "^0.0.3",
136-
"@chemzqm/tslint-config": "^1.0.18",
137135
"@types/glob": "^7.1.1",
138-
"@types/mocha": "^9.1.0",
136+
"@types/mocha": "^10.0.0",
139137
"@types/node": "^11.13.10",
140138
"@types/vscode": "1.43.0",
141-
"@typescript-eslint/eslint-plugin": "^5.19.0",
142-
"@typescript-eslint/parser": "^5.19.0",
139+
"@typescript-eslint/eslint-plugin": "^5.62.0",
140+
"@typescript-eslint/parser": "^5.62.0",
143141
"@vscode/test-electron": "^2.1.3",
144-
"eslint": "^8.13.0",
142+
"@vscode/vsce": "^2.21.1",
143+
"eslint": "^8.51.0",
144+
"eslint-config-prettier": "^8.5.0",
145+
"eslint-plugin-jsdoc": "^39.6.4",
145146
"glob": "^7.1.4",
146-
"mocha": "^9.2.2",
147+
"mocha": "^10.1.0",
148+
"prettier": "2.7.1",
147149
"rimraf": "~3.0.2",
148150
"source-map-support": "^0.5.12",
149151
"ts-loader": "~8.0.2",
150152
"tslib": "^2.1.0",
151-
"tslint": "^5.16.0",
152153
"typescript": "^4.6.3",
153-
"@vscode/vsce": "^2.21.1",
154-
"vscode-test": "~1.4.0",
155-
"prettier": "2.7.1"
154+
"vscode-test": "~1.4.0"
156155
},
157156
"dependencies": {
158157
"vscode-languageclient": "^6.1.3"
@@ -164,4 +163,4 @@
164163
"sponsor": {
165164
"url": "https://github.com/sponsors/dantleech"
166165
}
167-
}
166+
}

src/extension.ts

+34-22
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,34 @@ import { LanguageClient, ServerOptions, LanguageClientOptions, StreamInfo } from
22

33
import * as vscode from 'vscode'
44
import { spawn } from 'child_process'
5-
import { existsSync, mkdir, mkdirSync } from 'fs'
6-
import { basename, dirname } from 'path'
5+
import { existsSync, mkdirSync } from 'fs'
6+
import { dirname } from 'path'
77
import * as net from 'net'
88

99
const LanguageID = 'php'
1010

1111
let languageClient: LanguageClient
1212

13+
interface PhpactorConfig {
14+
path?: string
15+
enable: boolean
16+
config: any
17+
remote: {
18+
enabled: boolean
19+
host: string
20+
port: number
21+
}
22+
launchServerArgs: string[]
23+
}
24+
1325
export async function activate(context: vscode.ExtensionContext): Promise<void> {
1426
if (process.platform === 'win32') {
15-
vscode.window.showWarningMessage('Phpactor is not supported on Windows.')
27+
void vscode.window.showWarningMessage('Phpactor is not supported on Windows.')
1628
return
1729
}
1830

19-
let workspaceConfig = vscode.workspace.getConfiguration()
20-
const config = workspaceConfig.get('phpactor') as any
31+
const workspaceConfig = vscode.workspace.getConfiguration()
32+
const config = workspaceConfig.get<PhpactorConfig>('phpactor')!
2133
const enable = config.enable
2234

2335
if (!config.path) {
@@ -37,13 +49,13 @@ export function deactivate(): Promise<void> | undefined {
3749
return languageClient.stop()
3850
}
3951

40-
function getServerOptions(config): ServerOptions {
52+
function getServerOptions(config: PhpactorConfig): ServerOptions {
4153
let serverOptions
4254
if (!config.remote.enabled) {
4355
// launch language server via stdio
4456
serverOptions = {
4557
run: {
46-
command: config.path,
58+
command: config.path!,
4759
args: ['language-server', ...config.launchServerArgs],
4860
},
4961
debug: {
@@ -55,13 +67,13 @@ function getServerOptions(config): ServerOptions {
5567
// credits: https://github.com/itemis/xtext-languageserver-example/blob/master/vscode-extension/src/extension.ts
5668
// launch language server via socket
5769
serverOptions = () => {
58-
let { host, port } = config.remote
59-
let socket = net.connect({
70+
const { host, port } = config.remote
71+
const socket = net.connect({
6072
host,
6173
port,
6274
})
6375

64-
let result = /*<StreamInfo>*/ {
76+
const result = <StreamInfo>{
6577
writer: socket,
6678
reader: socket,
6779
}
@@ -73,10 +85,10 @@ function getServerOptions(config): ServerOptions {
7385
return serverOptions
7486
}
7587

76-
function createClient(config: any): LanguageClient {
77-
let serverOptions = getServerOptions(config)
88+
function createClient(config: PhpactorConfig): LanguageClient {
89+
const serverOptions = getServerOptions(config)
7890

79-
let clientOptions: LanguageClientOptions = {
91+
const clientOptions: LanguageClientOptions = {
8092
documentSelector: [
8193
{ language: LanguageID, scheme: 'file' },
8294
{ language: 'blade', scheme: 'file' },
@@ -91,7 +103,7 @@ function createClient(config: any): LanguageClient {
91103
vscode.commands.registerCommand('phpactor.config.dump', dumpConfig)
92104
vscode.commands.registerCommand('phpactor.services.list', servicesList)
93105
vscode.commands.registerCommand('phpactor.status', status)
94-
const updateConfig = { cwd: dirname(dirname(config.path)) }
106+
const updateConfig = { cwd: dirname(dirname(config.path!)) }
95107
vscode.commands.registerCommand('phpactor.update', updatePhpactor, updateConfig)
96108

97109
return languageClient
@@ -102,7 +114,7 @@ function reindex(): void {
102114
return
103115
}
104116

105-
languageClient.sendRequest('indexer/reindex')
117+
void languageClient.sendRequest('indexer/reindex')
106118
}
107119

108120
async function dumpConfig(): Promise<void> {
@@ -121,7 +133,7 @@ function servicesList(): void {
121133
return
122134
}
123135

124-
languageClient.sendRequest('service/running')
136+
void languageClient.sendRequest('service/running')
125137
}
126138

127139
async function status(): Promise<any> {
@@ -144,22 +156,22 @@ async function installPhpactor(storagePath: string): Promise<string> {
144156

145157
if (!existsSync(path)) {
146158
const channel = vscode.window.createOutputChannel('Phpactor Installation')
147-
vscode.window.showInformationMessage('Installing Phpactor')
159+
void vscode.window.showInformationMessage('Installing Phpactor')
148160
await exec(channel, 'git', ['clone', 'https://github.com/phpactor/phpactor', '--depth=1'], storagePath)
149161
await exec(channel, 'composer', ['install', '--no-dev'], path)
150-
vscode.window.showInformationMessage(`Phpactor installed at ${path}`)
162+
void vscode.window.showInformationMessage(`Phpactor installed at ${path}`)
151163
}
152164

153165
return `${storagePath}/phpactor/bin/phpactor`
154166
}
155167

156-
export async function updatePhpactor(): Promise<void> {
168+
export async function updatePhpactor(this: { cwd: string }): Promise<void> {
157169
const channel = vscode.window.createOutputChannel('Phpactor Update')
158170
channel.appendLine(this.cwd)
159171
await exec(channel, 'git', ['pull'], this.cwd)
160172
await exec(channel, 'composer', ['install', '--no-dev'], this.cwd)
161173
channel.appendLine('Phpactor updated')
162-
vscode.window.showInformationMessage('Phpactor updated')
174+
void vscode.window.showInformationMessage('Phpactor updated')
163175
}
164176

165177
function exec(channel: vscode.OutputChannel, command: string, args: string[], cwd: string): Promise<void> {
@@ -168,10 +180,10 @@ function exec(channel: vscode.OutputChannel, command: string, args: string[], cw
168180
cwd,
169181
timeout: 30000,
170182
})
171-
child.stdout.on('data', data => {
183+
child.stdout.on('data', (data: Buffer) => {
172184
channel.append(data.toString('utf8'))
173185
})
174-
child.stderr.on('data', data => {
186+
child.stderr.on('data', (data: Buffer) => {
175187
channel.append(data.toString('utf8'))
176188
})
177189
child.on('close', code => {

src/test/runTests.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@ async function main(): Promise<void> {
2121
}
2222
}
2323

24-
main()
24+
void main()

src/test/suite/extension.test.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@ import * as assert from 'assert'
33
// You can import and use all API from the 'vscode' module
44
// as well as import your extension to test it
55
import * as vscode from 'vscode'
6-
import * as myExtension from '../../extension'
76

87
suite('Extension Test Suite', () => {
9-
test('Extension is present', async () => {
8+
test('Extension is present', () => {
109
assert.ok(vscode.extensions.getExtension('dantleech.vscode-phpactor'))
1110
})
1211
test('Extension activates', async () => {

src/test/suite/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as path from 'path'
2-
import Mocha from 'mocha'
3-
import glob from 'glob'
2+
import Mocha = require('mocha')
3+
import glob = require('glob')
44

55
export function run(): Promise<void> {
66
// Create the mocha test

tsconfig.json

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
{
2-
"extends": "./node_modules/@chemzqm/tsconfig/tsconfig.json",
32
"compilerOptions": {
43
"outDir": "out",
54
"target": "es2021",

tslint.json

-9
This file was deleted.

0 commit comments

Comments
 (0)