Skip to content

Commit

Permalink
Migrate from tslint to eslint and cleanup for stricter rules.
Browse files Browse the repository at this point in the history
  • Loading branch information
zobo committed Oct 18, 2023
1 parent 3194229 commit 0749443
Show file tree
Hide file tree
Showing 11 changed files with 317 additions and 818 deletions.
27 changes: 27 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
module.exports = {
"env": {
"es6": true,
"node": true
},
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": "tsconfig.json",
"sourceType": "module"
},
"extends": [
'eslint:recommended',
//'plugin:jsdoc/recommended',
'plugin:@typescript-eslint/eslint-recommended',
'plugin:@typescript-eslint/recommended',
'plugin:@typescript-eslint/recommended-requiring-type-checking',
'prettier',
],
"plugins": [
"eslint-plugin-jsdoc",
"@typescript-eslint",
],
"root": true,
"rules": {
'@typescript-eslint/no-unsafe-assignment': 'off',
}
};
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ jobs:
- name: Prettier
run: npm run prettier-check
- name: Lint
run: npm run tslint
run: npm run eslint
- run: xvfb-run -a npm test
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.vscode-test/
coverage/
out/
package-lock.json
Expand Down
1,003 changes: 237 additions & 766 deletions package-lock.json

Large diffs are not rendered by default.

27 changes: 13 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
"watch": "tsc -watch -p ./",
"pretest": "npm run compile",
"compile": "npm run clean && tsc -p ./",
"lint": "npm run tslint && npm run prettier",
"tslint": "tslint \"src/**/*.ts\"",
"lint": "npm run eslint && npm run prettier",
"eslint": "eslint \"src/**/*.ts\"",
"prettier": "prettier \"**/{*.json,*.yml,.*.yml,*.ts,.prettierrc,*.md}\" --write --list-different",
"prettier-check": "npm run prettier -- --write=false",
"test": "node ./out/test/runTests.js"
Expand Down Expand Up @@ -132,27 +132,26 @@
"author": "daniel@dantleech.com",
"license": "MIT",
"devDependencies": {
"@chemzqm/tsconfig": "^0.0.3",
"@chemzqm/tslint-config": "^1.0.18",
"@types/glob": "^7.1.1",
"@types/mocha": "^9.1.0",
"@types/mocha": "^10.0.0",
"@types/node": "^11.13.10",
"@types/vscode": "1.43.0",
"@typescript-eslint/eslint-plugin": "^5.19.0",
"@typescript-eslint/parser": "^5.19.0",
"@typescript-eslint/eslint-plugin": "^5.62.0",
"@typescript-eslint/parser": "^5.62.0",
"@vscode/test-electron": "^2.1.3",
"eslint": "^8.13.0",
"@vscode/vsce": "^2.21.1",
"eslint": "^8.51.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-jsdoc": "^39.6.4",
"glob": "^7.1.4",
"mocha": "^9.2.2",
"mocha": "^10.1.0",
"prettier": "2.7.1",
"rimraf": "~3.0.2",
"source-map-support": "^0.5.12",
"ts-loader": "~8.0.2",
"tslib": "^2.1.0",
"tslint": "^5.16.0",
"typescript": "^4.6.3",
"@vscode/vsce": "^2.21.1",
"vscode-test": "~1.4.0",
"prettier": "2.7.1"
"vscode-test": "~1.4.0"
},
"dependencies": {
"vscode-languageclient": "^6.1.3"
Expand All @@ -164,4 +163,4 @@
"sponsor": {
"url": "https://github.com/sponsors/dantleech"
}
}
}
56 changes: 34 additions & 22 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,34 @@ import { LanguageClient, ServerOptions, LanguageClientOptions, StreamInfo } from

import * as vscode from 'vscode'
import { spawn } from 'child_process'
import { existsSync, mkdir, mkdirSync } from 'fs'
import { basename, dirname } from 'path'
import { existsSync, mkdirSync } from 'fs'
import { dirname } from 'path'
import * as net from 'net'

const LanguageID = 'php'

let languageClient: LanguageClient

interface PhpactorConfig {
path?: string
enable: boolean
config: any
remote: {
enabled: boolean
host: string
port: number
}
launchServerArgs: string[]
}

export async function activate(context: vscode.ExtensionContext): Promise<void> {
if (process.platform === 'win32') {
vscode.window.showWarningMessage('Phpactor is not supported on Windows.')
void vscode.window.showWarningMessage('Phpactor is not supported on Windows.')
return
}

let workspaceConfig = vscode.workspace.getConfiguration()
const config = workspaceConfig.get('phpactor') as any
const workspaceConfig = vscode.workspace.getConfiguration()
const config = workspaceConfig.get<PhpactorConfig>('phpactor')!
const enable = config.enable

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

function getServerOptions(config): ServerOptions {
function getServerOptions(config: PhpactorConfig): ServerOptions {
let serverOptions
if (!config.remote.enabled) {
// launch language server via stdio
serverOptions = {
run: {
command: config.path,
command: config.path!,
args: ['language-server', ...config.launchServerArgs],
},
debug: {
Expand All @@ -55,13 +67,13 @@ function getServerOptions(config): ServerOptions {
// credits: https://github.com/itemis/xtext-languageserver-example/blob/master/vscode-extension/src/extension.ts
// launch language server via socket
serverOptions = () => {
let { host, port } = config.remote
let socket = net.connect({
const { host, port } = config.remote
const socket = net.connect({
host,
port,
})

let result = /*<StreamInfo>*/ {
const result = <StreamInfo>{
writer: socket,
reader: socket,
}
Expand All @@ -73,10 +85,10 @@ function getServerOptions(config): ServerOptions {
return serverOptions
}

function createClient(config: any): LanguageClient {
let serverOptions = getServerOptions(config)
function createClient(config: PhpactorConfig): LanguageClient {
const serverOptions = getServerOptions(config)

let clientOptions: LanguageClientOptions = {
const clientOptions: LanguageClientOptions = {
documentSelector: [
{ language: LanguageID, scheme: 'file' },
{ language: 'blade', scheme: 'file' },
Expand All @@ -91,7 +103,7 @@ function createClient(config: any): LanguageClient {
vscode.commands.registerCommand('phpactor.config.dump', dumpConfig)
vscode.commands.registerCommand('phpactor.services.list', servicesList)
vscode.commands.registerCommand('phpactor.status', status)
const updateConfig = { cwd: dirname(dirname(config.path)) }
const updateConfig = { cwd: dirname(dirname(config.path!)) }
vscode.commands.registerCommand('phpactor.update', updatePhpactor, updateConfig)

return languageClient
Expand All @@ -102,7 +114,7 @@ function reindex(): void {
return
}

languageClient.sendRequest('indexer/reindex')
void languageClient.sendRequest('indexer/reindex')
}

async function dumpConfig(): Promise<void> {
Expand All @@ -121,7 +133,7 @@ function servicesList(): void {
return
}

languageClient.sendRequest('service/running')
void languageClient.sendRequest('service/running')
}

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

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

return `${storagePath}/phpactor/bin/phpactor`
}

export async function updatePhpactor(): Promise<void> {
export async function updatePhpactor(this: { cwd: string }): Promise<void> {
const channel = vscode.window.createOutputChannel('Phpactor Update')
channel.appendLine(this.cwd)
await exec(channel, 'git', ['pull'], this.cwd)
await exec(channel, 'composer', ['install', '--no-dev'], this.cwd)
channel.appendLine('Phpactor updated')
vscode.window.showInformationMessage('Phpactor updated')
void vscode.window.showInformationMessage('Phpactor updated')
}

function exec(channel: vscode.OutputChannel, command: string, args: string[], cwd: string): Promise<void> {
Expand All @@ -168,10 +180,10 @@ function exec(channel: vscode.OutputChannel, command: string, args: string[], cw
cwd,
timeout: 30000,
})
child.stdout.on('data', data => {
child.stdout.on('data', (data: Buffer) => {
channel.append(data.toString('utf8'))
})
child.stderr.on('data', data => {
child.stderr.on('data', (data: Buffer) => {
channel.append(data.toString('utf8'))
})
child.on('close', code => {
Expand Down
2 changes: 1 addition & 1 deletion src/test/runTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ async function main(): Promise<void> {
}
}

main()
void main()
3 changes: 1 addition & 2 deletions src/test/suite/extension.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ import * as assert from 'assert'
// You can import and use all API from the 'vscode' module
// as well as import your extension to test it
import * as vscode from 'vscode'
import * as myExtension from '../../extension'

suite('Extension Test Suite', () => {
test('Extension is present', async () => {
test('Extension is present', () => {
assert.ok(vscode.extensions.getExtension('dantleech.vscode-phpactor'))
})
test('Extension activates', async () => {
Expand Down
4 changes: 2 additions & 2 deletions src/test/suite/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as path from 'path'
import Mocha from 'mocha'
import glob from 'glob'
import Mocha = require('mocha')
import glob = require('glob')

export function run(): Promise<void> {
// Create the mocha test
Expand Down
1 change: 0 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"extends": "./node_modules/@chemzqm/tsconfig/tsconfig.json",
"compilerOptions": {
"outDir": "out",
"target": "es2021",
Expand Down
9 changes: 0 additions & 9 deletions tslint.json

This file was deleted.

0 comments on commit 0749443

Please sign in to comment.