Skip to content

Commit 5a7200b

Browse files
committed
chore: migrate to eslint
1 parent 9f53f10 commit 5a7200b

File tree

5 files changed

+1015
-148
lines changed

5 files changed

+1015
-148
lines changed

.eslintignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/lib
2+
/test-workspace

package.json

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
"scripts": {
1818
"build": "tsc",
1919
"dev": "tsc --watch",
20-
"lint": "run-s lint:prettier lint:tslint",
20+
"lint": "run-s lint:prettier lint:eslint",
21+
"lint:eslint": "eslint . --ext .ts",
2122
"lint:prettier": "prettier --check **/*.{ts,md,yml,json}",
22-
"lint:tslint": "tslint -p .",
2323
"prepublishOnly": "yarn build"
2424
},
2525
"prettier": {
@@ -28,6 +28,12 @@
2828
"singleQuote": true,
2929
"trailingComma": "all"
3030
},
31+
"eslintConfig": {
32+
"extends": "@ark120202/eslint-config/node",
33+
"parserOptions": {
34+
"project": "tsconfig.json"
35+
}
36+
},
3137
"dependencies": {
3238
"mock-require": "^3.0.3",
3339
"resolve-from": "^5.0.0",
@@ -36,13 +42,13 @@
3642
"typescript-to-lua": "^0.20.0"
3743
},
3844
"devDependencies": {
39-
"@ark120202/tslint-config": "^4.0.2",
45+
"@ark120202/eslint-config": "^1.0.0",
4046
"@ark120202/typescript-config": "^2.0.0",
4147
"@types/mock-require": "^2.0.0",
4248
"@types/node": "^12.0.2",
49+
"eslint": "^5.16.0",
4350
"npm-run-all": "^4.1.5",
4451
"prettier": "^1.17.1",
45-
"tslint": "^5.16.0",
4652
"typescript": "^3.4.5"
4753
},
4854
"engines": {

src/index.ts

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ import path from 'path';
33
import resolveFrom from 'resolve-from';
44
import resolveGlobal from 'resolve-global';
55
import { ParsedCommandLine } from 'typescript-to-lua';
6-
import * as ts_module from 'typescript/lib/tsserverlibrary';
6+
import * as tsserverlibrary from 'typescript/lib/tsserverlibrary';
77

88
const pluginMarker = Symbol('pluginMarker');
99
class TSTLPlugin {
1010
constructor(
11-
private ts: typeof ts_module,
12-
private languageService: ts_module.LanguageService,
13-
private project: ts_module.server.Project,
14-
private serverHost: ts_module.server.ServerHost,
11+
private readonly ts: typeof tsserverlibrary,
12+
private readonly languageService: tsserverlibrary.LanguageService,
13+
private readonly project: tsserverlibrary.server.Project,
14+
private readonly serverHost: tsserverlibrary.server.ServerHost,
1515
) {}
1616

1717
private log(message: string) {
@@ -44,6 +44,7 @@ class TSTLPlugin {
4444
'typescript-to-lua';
4545

4646
this.log(`Loading typescript-to-lua from "${resolved}"`);
47+
// eslint-disable-next-line @typescript-eslint/no-require-imports
4748
this._tstl = require(resolved);
4849
}
4950

@@ -54,7 +55,7 @@ class TSTLPlugin {
5455
this.log('Wrapping language service');
5556
this.update();
5657

57-
const intercept: Partial<ts_module.LanguageService> = Object.create(null);
58+
const intercept: Partial<tsserverlibrary.LanguageService> = Object.create(null);
5859
(intercept as any)[pluginMarker] = this;
5960
intercept.getSemanticDiagnostics = this.getSemanticDiagnostics.bind(this);
6061
return new Proxy(this.languageService, {
@@ -75,37 +76,40 @@ class TSTLPlugin {
7576
return diagnostics;
7677
}
7778

78-
private getTstlDiagnostics(program: ts_module.Program, sourceFile: ts_module.SourceFile) {
79+
private getTstlDiagnostics(
80+
program: tsserverlibrary.Program,
81+
sourceFile: tsserverlibrary.SourceFile,
82+
) {
7983
if (this.parsedCommandLine != null && this.parsedCommandLine.raw.tstl != null) {
8084
Object.assign(program.getCompilerOptions(), this.parsedCommandLine.options);
8185

8286
const transformer = new this.tstl.LuaTransformer(program);
8387
try {
8488
transformer.transformSourceFile(sourceFile);
85-
} catch (err) {
86-
if (err instanceof this.tstl.TranspileError) {
87-
const diagnostic: ts_module.Diagnostic = {
89+
} catch (error) {
90+
if (error instanceof this.tstl.TranspileError) {
91+
const diagnostic: tsserverlibrary.Diagnostic = {
8892
category: this.ts.DiagnosticCategory.Error,
8993
code: 0,
90-
file: err.node.getSourceFile(),
91-
start: err.node.getStart(),
92-
length: err.node.getWidth(),
93-
messageText: err.message,
94+
file: error.node.getSourceFile(),
95+
start: error.node.getStart(),
96+
length: error.node.getWidth(),
97+
messageText: error.message,
9498
source: 'typescript-to-lua',
9599
};
96100

97101
return [diagnostic];
98102
}
99103

100-
this.log(`Error during transpilation: ${err.stack}`);
104+
this.log(`Error during transpilation: ${error.stack}`);
101105
}
102106
}
103107

104108
return [];
105109
}
106110
}
107111

108-
const init: ts_module.server.PluginModuleFactory = ({ typescript }) => {
112+
const init: tsserverlibrary.server.PluginModuleFactory = ({ typescript }) => {
109113
mockRequire('typescript', typescript);
110114

111115
return {

tslint.json

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)