Skip to content

Commit

Permalink
Merge pull request #86 from vscode-autohotkey/fixup-linter
Browse files Browse the repository at this point in the history
Update linter
  • Loading branch information
cweijan authored Nov 16, 2022
2 parents 32c61c0 + f632771 commit fd9357d
Show file tree
Hide file tree
Showing 26 changed files with 164 additions and 125 deletions.
17 changes: 17 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"root": true,
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 6,
"sourceType": "module"
},
"plugins": ["@typescript-eslint"],
"rules": {
"@typescript-eslint/naming-convention": "warn",
"@typescript-eslint/semi": "warn",
"curly": "warn",
"eqeqeq": "warn",
"no-throw-literal": "warn"
},
"ignorePatterns": ["out", "dist", "**/*.d.ts"]
}
14 changes: 0 additions & 14 deletions .eslintrc.js

This file was deleted.

13 changes: 10 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,18 @@
"scripts": {
"build": "rimraf out && node build.js --mode=production",
"dev": "rimraf out && node build.js",
"eslint": "npm run eslint_inner -- src && echo No ESLint problems",
"eslint_fix": "npm run eslint_inner -- --fix src",
"eslint_inner": "eslint --ext ts --max-warnings=0",
"format": "npm run format_inner -- --check .",
"format_fix": "npm run format_inner -- --write .",
"format_inner": "prettier",
"lint": "eslint src/**/*.ts",
"lint:fix": "eslint src/**/*.ts --fix",
"lint": "npm run tsc && npm run eslint && npm run format && npm run packagejson",
"packagejson": "sort-package-json --check",
"packagejson:fix": "sort-package-json",
"publish": "vsce publish",
"validate": "npm run packagejson && npm run build",
"tsc": "tsc --noEmit --skipLibCheck && echo No TSC problems",
"validate": "npm run lint && npm run build",
"vscode:prepublish": "npm run build"
},
"contributes": {
Expand Down Expand Up @@ -281,6 +284,10 @@
],
"lint-staged": {
"*": "prettier --check",
"src/**/*.ts": [
"npm run eslint_inner",
"npm run tsc"
],
"package.json": "npm run packagejson"
},
"dependencies": {
Expand Down
8 changes: 5 additions & 3 deletions src/common/codeUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ export class CodeUtil {
* @param origin any string
*/
public static purity(origin: string): string {
if (!origin) return '';
if (!origin) {
return '';
}
// TODO: untest
return origin
.replace(/;.+/, '')
Expand All @@ -16,7 +18,7 @@ export class CodeUtil {
}

public static join(array: any[], items: any | any[]) {
if (array == undefined || items == undefined) {
if (!array || !items) {
return;
}
if (Array.isArray(items)) {
Expand All @@ -35,7 +37,7 @@ export class CodeUtil {

const regs = [];
let temp: RegExpExecArray;
while ((temp = regex.exec(text)) != null) {
while ((temp = regex.exec(text))) {
regs.push(temp);
}

Expand Down
10 changes: 6 additions & 4 deletions src/common/fileManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ export class FileManager {
}

private static check(path: string) {
if (!fs.existsSync(path)) fs.mkdirSync(path);
if (!fs.existsSync(path)) {
fs.mkdirSync(path);
}
}

public static show(fileName: string) {
Expand Down Expand Up @@ -53,7 +55,7 @@ export class FileManager {
const recordPath = `${this.storagePath}/${fileName}`;
this.check(this.storagePath);
this.check(path.resolve(recordPath, '..'));
if (model == FileModel.WRITE) {
if (model === FileModel.write) {
fs.writeFileSync(recordPath, `${content}`, {
encoding: 'utf8',
});
Expand All @@ -68,6 +70,6 @@ export class FileManager {
}

export enum FileModel {
WRITE,
APPEND,
write,
append,
}
6 changes: 2 additions & 4 deletions src/common/global.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
import * as vscode from 'vscode';

export class Global {
public static CONFIG_PREFIX = 'vscode-ahk-plus';
public static configPrefix = 'vscode-ahk-plus';
private static statusBarItem: vscode.StatusBarItem;
/**
* get configuration from vscode setting.
* @param key config key
*/
public static getConfig<T>(key: string): T {
return vscode.workspace
.getConfiguration(this.CONFIG_PREFIX)
.get<T>(key);
return vscode.workspace.getConfiguration(this.configPrefix).get<T>(key);
}

public static updateStatusBarItems(text: string) {
Expand Down
4 changes: 3 additions & 1 deletion src/common/out.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import format from 'date-format';
import * as vscode from 'vscode';

function formatDate(date: Date) {
if (!date) return '';
if (!date) {
return '';
}
return format('yyyy-MM-dd hh:mm:ss', date);
}

Expand Down
14 changes: 10 additions & 4 deletions src/debugger/debugDispather.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,15 @@ export class DebugDispather extends EventEmitter {

private async initDebugger(
args: LaunchRequestArguments,
// AHK uses these variable names, let's keep them for now
// eslint-disable-next-line @typescript-eslint/naming-convention
dbgpSettings: { max_children?: number; max_data?: number } = {},
) {
if (this.port) return;
if (this.port) {
return;
}
// AHK uses these variable names, let's keep them for now
// eslint-disable-next-line @typescript-eslint/naming-convention
const { max_children = 300, max_data = 131072 } = dbgpSettings;
this.breakPointHandler = new BreakPointHandler();
this.stackHandler = new StackHandler();
Expand Down Expand Up @@ -205,12 +211,12 @@ export class DebugDispather extends EventEmitter {

const variables = await this.getVariable(
frameId,
VarScope.LOCAL,
VarScope.local,
variableName,
);
if (variables.length == 0) {
if (!variables.length) {
return null;
} else if (variables.length == 1) {
} else if (variables.length === 1) {
return variables[0].value;
} else {
const ahkVar = this.variableHandler.getVarByName(variableName);
Expand Down
6 changes: 3 additions & 3 deletions src/debugger/debugServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export class DebugServer extends EventEmitter {
tempData = tempData
? Buffer.concat([tempData, chunk])
: chunk;
if (tempData[tempData.length - 1] == END) {
if (tempData[tempData.length - 1] === END) {
this.process(tempData.toString());
tempData = null;
}
Expand Down Expand Up @@ -79,11 +79,11 @@ export class DebugServer extends EventEmitter {
});
public process(data: string) {
data = data.substr(data.indexOf('<?xml'));
if (data.indexOf(this.header) == -1) {
if (!data.includes(this.header)) {
data = this.header + data;
}
for (const part of data.split(this.header)) {
if (null == part || part.trim() == '') {
if (!part?.trim()) {
continue;
}
const xmlString = this.header + part;
Expand Down
30 changes: 15 additions & 15 deletions src/debugger/debugSession.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { commands } from 'vscode';
import {
BreakpointEvent,
ExitedEvent,
InitializedEvent,
LoggingDebugSession,
OutputEvent,
Expand All @@ -27,7 +26,10 @@ export interface LaunchRequestArguments
/** An absolute path to the AutoHotkey.exe. */
runtime: string;
dbgpSettings: {
// AHK uses these variable names, let's keep them for now
// eslint-disable-next-line @typescript-eslint/naming-convention
max_children?: number;
// eslint-disable-next-line @typescript-eslint/naming-convention
max_data?: number;
};
}
Expand All @@ -36,7 +38,7 @@ export interface LaunchRequestArguments
* debug session for vscode.
*/
export class DebugSession extends LoggingDebugSession {
private static THREAD_ID = 1;
private static threadId = 1;
private dispather: DebugDispather;

public constructor() {
Expand All @@ -49,9 +51,7 @@ export class DebugSession extends LoggingDebugSession {
this.dispather = new DebugDispather();
this.dispather
.on('break', (reason: string) => {
this.sendEvent(
new StoppedEvent(reason, DebugSession.THREAD_ID),
);
this.sendEvent(new StoppedEvent(reason, DebugSession.threadId));
})
.on('breakpointValidated', (bp: DebugProtocol.Breakpoint) => {
this.sendEvent(
Expand Down Expand Up @@ -187,23 +187,23 @@ export class DebugSession extends LoggingDebugSession {
args: DebugProtocol.PauseArguments,
request?: DebugProtocol.Request,
): void {
this.dispather.sendComand(Continue.BREAK);
this.dispather.sendComand(Continue.break);
this.sendResponse(response);
}

protected continueRequest(
response: DebugProtocol.ContinueResponse,
args: DebugProtocol.ContinueArguments,
): void {
this.dispather.sendComand(Continue.RUN);
this.dispather.sendComand(Continue.run);
this.sendResponse(response);
}

protected nextRequest(
response: DebugProtocol.NextResponse,
args: DebugProtocol.NextArguments,
): void {
this.dispather.sendComand(Continue.STEP_OVER);
this.dispather.sendComand(Continue.stepOver);
this.sendResponse(response);
}

Expand All @@ -212,7 +212,7 @@ export class DebugSession extends LoggingDebugSession {
args: DebugProtocol.StepInArguments,
request?: DebugProtocol.Request,
): void {
this.dispather.sendComand(Continue.STEP_INTO);
this.dispather.sendComand(Continue.stepInto);
this.sendResponse(response);
}

Expand All @@ -221,13 +221,13 @@ export class DebugSession extends LoggingDebugSession {
args: DebugProtocol.StepOutArguments,
request?: DebugProtocol.Request,
): void {
this.dispather.sendComand(Continue.STEP_OUT);
this.dispather.sendComand(Continue.stepOut);
this.sendResponse(response);
}

protected threadsRequest(response: DebugProtocol.ThreadsResponse): void {
response.body = {
threads: [new Thread(DebugSession.THREAD_ID, 'main thread')],
threads: [new Thread(DebugSession.threadId, 'main thread')],
};
this.sendResponse(response);
}
Expand All @@ -239,10 +239,10 @@ export class DebugSession extends LoggingDebugSession {
response.body = {
targets: [
...(await this.dispather.listVariables({
variablesReference: VscodeScope.LOCAL,
variablesReference: VscodeScope.local,
})),
...(await this.dispather.listVariables({
variablesReference: VscodeScope.GLOBAL,
variablesReference: VscodeScope.global,
})),
].map((variable) => {
return {
Expand All @@ -261,13 +261,13 @@ export class DebugSession extends LoggingDebugSession {
): Promise<void> {
const exp = args.expression.split('=');
let reply: string;
if (exp.length == 1) {
if (exp.length === 1) {
reply = await this.dispather.getVariableByEval(args.expression);
} else {
this.dispather.setVariable({
name: exp[0],
value: exp[1],
variablesReference: VscodeScope.LOCAL,
variablesReference: VscodeScope.local,
});
reply = `execute: ${args.expression}`;
}
Expand Down
2 changes: 1 addition & 1 deletion src/debugger/handler/breakpointHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export class BreakPointHandler {
new Source(basename(path), path),
);
const lineText = sourceLines[sourceBreakpoint.line];
if (lineText && lineText.trim().charAt(0) != ';') {
if (lineText && lineText.trim().charAt(0) !== ';') {
breakPoint.verified = true;
}
callback(breakPoint);
Expand Down
4 changes: 3 additions & 1 deletion src/debugger/handler/commandHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ export class CommandHandler {

public callback(transId: string, response: DbgpResponse) {
const fun = this.commandCallback[transId];
if (fun) fun(response);
if (fun) {
fun(response);
}
this.commandCallback[transId] = null;
}
}
Loading

0 comments on commit fd9357d

Please sign in to comment.