Skip to content

Commit

Permalink
refactor: use eslint instead of tslint
Browse files Browse the repository at this point in the history
  • Loading branch information
Yesterday17 committed Jun 24, 2020
1 parent 8e60b66 commit 1ad1c15
Show file tree
Hide file tree
Showing 48 changed files with 1,043 additions and 463 deletions.
36 changes: 36 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
module.exports = {
env: {
es6: true,
node: true,
},
parser: '@typescript-eslint/parser',
parserOptions: {
project: './tsconfig.json',
sourceType: 'module',
},
plugins: ['@typescript-eslint'],
extends: ['plugin:@typescript-eslint/recommended'],
rules: {
// '@typescript-eslint/class-name-casing': 'warn',
'@typescript-eslint/member-delimiter-style': [
'warn',
{
multiline: {
delimiter: 'semi',
requireLast: true,
},
singleline: {
delimiter: 'semi',
requireLast: false,
},
},
],
'@typescript-eslint/no-unused-expressions': 'warn',
'@typescript-eslint/semi': ['warn', 'always'],
'@typescript-eslint/no-empty-function': 'off',
curly: 'warn',
eqeqeq: ['error', 'always'],
'no-redeclare': 'warn',
'no-throw-literal': 'warn',
},
};
6 changes: 1 addition & 5 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,11 @@
{
"files.exclude": {
"*.vsix": true,
"api": true,
"assets": true,
"client": true,
"docs": true,
"i18n": true,
"language": true,
"server": true,
"test": true,
"yarn.lock": true,
"zenscript.code-workspace": true
"yarn.lock": true
}
}
4 changes: 0 additions & 4 deletions api/tsconfig.json

This file was deleted.

29 changes: 17 additions & 12 deletions client/command/historyEntry.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { window } from 'vscode';
import { window, TextEditor } from 'vscode';
import { CommandBase } from '../api/CommandBase';
import {
HistoryEntryGetRequestType,
Expand All @@ -8,30 +8,35 @@ import {
class HistoryEntryGet extends CommandBase {
public command = 'zenscript.command.gethistoryentry';
public handler = () => {
this.client.sendRequest(HistoryEntryGetRequestType).then(items => {
this.client.sendRequest(HistoryEntryGetRequestType).then((items) => {
if (items.length === 0) {
window.showInformationMessage('No HistoryEntry available!');
return;
}

window.showQuickPick(items.map(item => item.element)).then(selected => {
window.activeTextEditor.edit(builder => {
window.activeTextEditor.selections.forEach(selection => {
builder.replace(selection, selected);
this.client.sendRequest(HistoryEntryAddRequestType, selected);
const editor = window.activeTextEditor as TextEditor;

window
.showQuickPick(items.map((item) => item.element))
.then((selected: string) => {
editor.edit((builder) => {
editor.selections.forEach((selection) => {
builder.replace(selection, selected);
this.client.sendRequest(HistoryEntryAddRequestType, selected);
});
});
window.showInformationMessage(selected);
});
window.showInformationMessage(selected);
});
});
}
};
}

class HistoryEntryAdd extends CommandBase {
public command = 'zenscript.command.addhistoryentry';
public handler = () => {
// If anything is selected
if (
window.activeTextEditor &&
window.activeTextEditor.selection.start.compareTo(
window.activeTextEditor.selection.end
) !== 0
Expand All @@ -48,7 +53,7 @@ class HistoryEntryAdd extends CommandBase {
// Nothing is selected, open an inputbox
window
.showInputBox({ placeHolder: 'History entry to add:' })
.then(value => {
.then((value) => {
if (value) {
this.client
.sendRequest(HistoryEntryAddRequestType, value)
Expand All @@ -58,7 +63,7 @@ class HistoryEntryAdd extends CommandBase {
}
});
}
}
};
}

export const CommandHistoryEntryGet = new HistoryEntryGet();
Expand Down
2 changes: 1 addition & 1 deletion client/command/openFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class OpenFile extends CommandBase {
public command = 'zenscript.command.openfile';
public handler = (path: string) => {
window.showTextDocument(Uri.parse(path));
}
};
}

export const CommandOpenFile = new OpenFile();
6 changes: 3 additions & 3 deletions client/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { StatusBar } from './view/statusbar';

let client: LanguageClient;

export function activate(context: ExtensionContext) {
export function activate(context: ExtensionContext): void {
const serverModule = context.asAbsolutePath(
path.join('out', 'server', 'server.js')
);
Expand Down Expand Up @@ -76,9 +76,9 @@ export function activate(context: ExtensionContext) {
client.start();
}

export function deactivate(): Thenable<void> {
export async function deactivate(): Promise<void> {
if (!client) {
return;
}
return client.stop();
return await client.stop();
}
8 changes: 4 additions & 4 deletions client/request/fileSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ import {
} from '../../api/requests/FileSystemRequest';

export class FileSystemReadFileRequest {
static onRequest(client: LanguageClient) {
static onRequest(client: LanguageClient): void {
client.onRequest(FSReadFileRequestType, (uri) => {
return workspace.fs.readFile(uri);
});
}
}

export class FileSystemReadFileStringRequest {
static onRequest(client: LanguageClient) {
static onRequest(client: LanguageClient): void {
client.onRequest(FSReadFileStringRequestType, async (uri) => {
const data = await workspace.fs.readFile(uri);
return Buffer.from(data).toString('utf-8');
Expand All @@ -25,15 +25,15 @@ export class FileSystemReadFileStringRequest {
}

export class FileSystemReadDirectoryRequest {
static onRequest(client: LanguageClient) {
static onRequest(client: LanguageClient): void {
client.onRequest(FSReadDirectoryRequestType, (uri) => {
return workspace.fs.readDirectory(uri);
});
}
}

export class FileSystemStatRequest {
static onRequest(client: LanguageClient) {
static onRequest(client: LanguageClient): void {
client.onRequest(FSStatRequestType, (uri) => {
return workspace.fs.stat(uri);
});
Expand Down
2 changes: 1 addition & 1 deletion client/request/requests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ const Requests = [
StatusBarRequest,
];

export function applyRequests(client: LanguageClient) {
export function applyRequests(client: LanguageClient): void {
Requests.forEach((req) => req.onRequest(client));
}
2 changes: 1 addition & 1 deletion client/request/statusBar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ServerStatusRequestType } from '../../api/requests/ServerStatusRequest'
import { StatusBar } from '../view/statusbar';

export class StatusBarRequest {
static onRequest(client: LanguageClient) {
static onRequest(client: LanguageClient): void {
client.onRequest(ServerStatusRequestType, (ok) => {
StatusBar.show();
StatusBar.check(ok);
Expand Down
9 changes: 0 additions & 9 deletions client/tsconfig.json

This file was deleted.

8 changes: 5 additions & 3 deletions client/view/priority.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@ class PriorityProvider implements TreeDataProvider<PriorityItem>, Registerable {
// doesn't need tree view, so any node has no chlidren
return Promise.resolve([]);
} else {
return this.client.sendRequest(PriorityTreeGetRequestType).then(items => {
return items.map(item => new PriorityItem(item));
});
return this.client
.sendRequest(PriorityTreeGetRequestType)
.then((items) => {
return items.map((item) => new PriorityItem(item));
});
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,10 @@
"@types/node": "^10.17.18",
"@types/set-value": "^2.0.0",
"@types/vscode": "^1.43.0",
"@typescript-eslint/eslint-plugin": "^3.4.0",
"@typescript-eslint/parser": "^3.4.0",
"del": "^3.0.0",
"tslint": "^6.1.1",
"eslint": "^7.3.1",
"typescript": "^3.8.3",
"vsce": "^1.75.0",
"vscode-nls-dev": "^3.3.1"
Expand Down
12 changes: 7 additions & 5 deletions server/api/global.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/ban-types */
import {
Connection,
createConnection,
Expand All @@ -15,6 +16,7 @@ import {
EnchantmentEntry,
EntityEntry,
FluidEntry,
ItemEntry,
ModEntry,
ZSRCFile,
} from './rcFile';
Expand Down Expand Up @@ -46,7 +48,7 @@ class Global {
*/
console: RemoteConsole;

isProject: boolean = false;
isProject = false;
baseFolderUri: URI;
setting: ZenScriptSettings;
documentSettings: Map<string, Promise<ZenScriptSettings>> = new Map();
Expand All @@ -56,14 +58,14 @@ class Global {
directory: Directory;

mods: Map<string, ModEntry> = new Map();
items: RCStorage = new RCStorage('item', 3);
items: RCStorage<ItemEntry> = new RCStorage('item', 3);
enchantments: Map<string, EnchantmentEntry[]> = new Map();
entities: Map<string, EntityEntry[]> = new Map();
fluids: Map<string, FluidEntry> = new Map();
packages: Object;

global: Map<String, Object> = new Map();
globalFunction: Map<String, ZenFunction[]> = new Map();
global: Map<string, Object> = new Map();
globalFunction: Map<string, ZenFunction[]> = new Map();

// zs file
zsFiles: Map<string, ZenParsedFile> = new Map();
Expand Down Expand Up @@ -93,7 +95,7 @@ class Global {
this.bus = new StateEventBus();

this.isProject = false;
this.baseFolderUri = null;
this.baseFolderUri = undefined;

this.setting = undefined;
this.documentSettings = new Map();
Expand Down
22 changes: 11 additions & 11 deletions server/api/zenParsedFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ export class ZenParsedFile implements IPriority {
pkg: string; // package: scripts.xx.yy
private connection: Connection;

get path() {
get path(): string {
return this.uri.toString();
}
content: string;

private step: ParseStep = ParseStep.NotLoaded;
get isInterpreted() {
get isInterpreted(): boolean {
return this.step === ParseStep.Parsed;
}

Expand All @@ -47,11 +47,11 @@ export class ZenParsedFile implements IPriority {
ast: ASTNodeProgram;
bracketHandlers: any;

priority: number = 0;
ignoreBracketErrors: boolean = false;
loader: string = 'crafttweaker';
norun: boolean = false;
nowarn: boolean = false;
priority = 0;
ignoreBracketErrors = false;
loader = 'crafttweaker';
norun = false;
nowarn = false;

constructor(uri: URI, pkg: string, connection: Connection) {
this.uri = uri;
Expand All @@ -63,18 +63,18 @@ export class ZenParsedFile implements IPriority {
/**
* Load file from `this.path`
*/
async load() {
async load(): Promise<void> {
this.content = await fs.readFileString(this.uri, this.connection);
this.step = ParseStep.Loaded;
}

text(text: string) {
text(text: string): ZenParsedFile {
this.content = text;
this.step = ParseStep.Loaded;
return this;
}

parse() {
parse(): ZenParsedFile {
// Lexing
this.lexResult = ZSLexer.tokenize(this.content);
this.comments = this.lexResult.groups['COMMENT'];
Expand Down Expand Up @@ -104,7 +104,7 @@ export class ZenParsedFile implements IPriority {
/**
* Interprete file, generate ast.
*/
interprete() {
interprete(): ZenParsedFile {
if (this.parseErrors.length === 0) {
// Interpreting
this.ast = ZSInterpreter.visit(this.cst);
Expand Down
Loading

0 comments on commit 1ad1c15

Please sign in to comment.