replace tslint with eslint

This commit is contained in:
Evert Prants 2021-12-15 18:33:13 +02:00
parent 1c98747c62
commit ffee7103e0
Signed by: evert
GPG Key ID: 1688DA83D222D0B5
9 changed files with 2722 additions and 173 deletions

1
.eslintignore Normal file
View File

@ -0,0 +1 @@
*.js

47
.eslintrc.js Normal file
View File

@ -0,0 +1,47 @@
module.exports = {
'env': {
'es2021': true,
'node': true
},
'extends': [
'eslint:recommended',
'plugin:@typescript-eslint/recommended'
],
'parser': '@typescript-eslint/parser',
'parserOptions': {
'ecmaVersion': 13,
'sourceType': 'module',
'project': 'tsconfig.json',
'tsconfigRootDir': __dirname,
},
'plugins': [
'@typescript-eslint'
],
'rules': {
'no-empty': [
'error',
{
'allowEmptyCatch': true,
}
],
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-unused-vars': 'off',
'indent': [
'error',
2
],
'linebreak-style': [
'error',
'unix'
],
'quotes': [
'error',
'single'
],
'semi': [
'error',
'always'
]
}
};

3
.gitignore vendored
View File

@ -2,5 +2,6 @@
/.out/ /.out/
deployment.json deployment.json
*.js *.js
!.eslintrc.js
*.d.ts *.d.ts
*.tsbuildinfo *.tsbuildinfo

View File

@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-non-null-assertion */
import { import {
Plugin, Plugin,
EventListener, EventListener,
@ -16,7 +17,7 @@ import tls, { TLSSocket } from 'tls';
import net, { Server, Socket } from 'net'; import net, { Server, Socket } from 'net';
interface ControlCommand { interface ControlCommand {
execute: Function; execute: (p: ControlPlugin, ...args: any[]) => Promise<any>;
name: string; name: string;
plugin: string; plugin: string;
} }
@ -647,7 +648,7 @@ class ControlPlugin extends Plugin {
}); });
}, (err) => { }, (err) => {
logger.error('[%s] Secure socket listen failed: %s', logger.error('[%s] Secure socket listen failed: %s',
this.name, err.message); this.name, err.message);
}); });
return; return;
} }

2616
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -18,6 +18,7 @@
"devDependencies": { "devDependencies": {
"@types/node": "^16.7.10", "@types/node": "^16.7.10",
"@types/node-cron": "^2.0.4", "@types/node-cron": "^2.0.4",
"@types/ws": "^8.2.0" "@types/ws": "^8.2.0",
"@typescript-eslint/eslint-plugin": "^5.7.0"
} }
} }

View File

@ -161,10 +161,11 @@ class SqueebotCommandsAPIPlugin extends Plugin {
} }
public async handlePrefix( public async handlePrefix(
msg: IMessage, msg: IMessage,
prefix: string, prefix: string,
plugins: string[], plugins: string[],
msr: MessageResolver): Promise<void> { msr: MessageResolver
): Promise<void> {
const text = msg.text; const text = msg.text;
const separate = text.split(' '); const separate = text.split(' ');
if (separate[0].indexOf(prefix) === 0) { if (separate[0].indexOf(prefix) === 0) {
@ -214,9 +215,12 @@ class SqueebotCommandsAPIPlugin extends Plugin {
const permitted = this.permissionMatcher(msg, sorted); const permitted = this.permissionMatcher(msg, sorted);
// Rate limit check // Rate limit check
if (permitted.length && if (permitted.length
this.config.get('rateLimits', []).length && && msg.fullRoomID
this.doLimiting(msg.fullRoomID!, msg.fullSenderID!)) { && msg.fullSenderID
&& this.config.get('rateLimits', []).length
&& this.doLimiting(msg.fullRoomID, msg.fullSenderID)
) {
logger.warn('[%s] User %s rate limited', this.name, msg.fullSenderID); logger.warn('[%s] User %s rate limited', this.name, msg.fullSenderID);
return; return;
} }
@ -494,39 +498,39 @@ class SqueebotCommandsAPIPlugin extends Plugin {
escaped = true; escaped = true;
} }
switch (strArray[strChar]) { switch (strArray[strChar]) {
case '\\': case '\\':
if (!escaped) { if (!escaped) {
escape = true; escape = true;
} else { } else {
addToArgs('\\'); addToArgs('\\');
} }
break; break;
case '"': case '"':
if (!escaped) { if (!escaped) {
if (!isString) {
isString = true;
} else {
isString = false;
}
} else {
addToArgs('"');
}
break;
case ' ':
if (!isString) { if (!isString) {
strARGC++; isString = true;
} else if (isString) { } else {
if (escaped) { isString = false;
addToArgs('\\');
}
addToArgs(' ');
} }
break; } else {
default: addToArgs('"');
}
break;
case ' ':
if (!isString) {
strARGC++;
} else if (isString) {
if (escaped) { if (escaped) {
addToArgs('\\'); addToArgs('\\');
} }
addToArgs(strArray[strChar]); addToArgs(' ');
}
break;
default:
if (escaped) {
addToArgs('\\');
}
addToArgs(strArray[strChar]);
} }
} }
return strARGS; return strARGS;
@ -540,11 +544,12 @@ class SqueebotCommandsAPIPlugin extends Plugin {
usage: '[<command>]', usage: '[<command>]',
description: 'Show command usage or list all available commands', description: 'Show command usage or list all available commands',
execute: async ( execute: async (
msg: IMessage, msg: IMessage,
msr: MessageResolver, msr: MessageResolver,
spec: CommandSpec, spec: CommandSpec,
prefix: string, prefix: string,
...args: any[]): Promise<boolean> => { ...args: any[]
): Promise<boolean> => {
this.helpCommand(msg, prefix, args); this.helpCommand(msg, prefix, args);
return true; return true;
} }
@ -557,11 +562,12 @@ class SqueebotCommandsAPIPlugin extends Plugin {
usage: '<command>', usage: '<command>',
description: 'Show the list of aliases for command', description: 'Show the list of aliases for command',
execute: async ( execute: async (
msg: IMessage, msg: IMessage,
msr: MessageResolver, msr: MessageResolver,
spec: CommandSpec, spec: CommandSpec,
prefix: string, prefix: string,
...args: any[]): Promise<boolean> => { ...args: any[]
): Promise<boolean> => {
this.aliasesCommand(msg, prefix, args); this.aliasesCommand(msg, prefix, args);
return true; return true;
} }

View File

@ -1,122 +0,0 @@
{
"extends": "tslint:recommended",
"rules": {
"align": {
"options": [
"parameters",
"statements"
]
},
"array-type": false,
"arrow-return-shorthand": true,
"curly": true,
"deprecation": {
"severity": "warning"
},
"eofline": true,
"import-spacing": true,
"indent": {
"options": [
"spaces"
]
},
"max-classes-per-file": false,
"max-line-length": [
true,
140
],
"member-ordering": [
true,
{
"order": [
"static-field",
"instance-field",
"static-method",
"instance-method"
]
}
],
"no-console": [
true,
"debug",
"info",
"time",
"timeEnd",
"trace"
],
"no-empty": false,
"no-inferrable-types": [
true,
"ignore-params"
],
"no-non-null-assertion": false,
"no-redundant-jsdoc": true,
"no-switch-case-fall-through": true,
"no-var-requires": false,
"object-literal-key-quotes": [
true,
"as-needed"
],
"quotemark": [
true,
"single"
],
"semicolon": {
"options": [
"always"
]
},
"space-before-function-paren": {
"options": {
"anonymous": "never",
"asyncArrow": "always",
"constructor": "never",
"method": "never",
"named": "never"
}
},
"typedef": [
true,
"call-signature"
],
"forin": false,
"ban-types": {
"function": false
},
"typedef-whitespace": {
"options": [
{
"call-signature": "nospace",
"index-signature": "nospace",
"parameter": "nospace",
"property-declaration": "nospace",
"variable-declaration": "nospace"
},
{
"call-signature": "onespace",
"index-signature": "onespace",
"parameter": "onespace",
"property-declaration": "onespace",
"variable-declaration": "onespace"
}
]
},
"variable-name": {
"options": [
"ban-keywords",
"check-format",
"allow-pascal-case"
]
},
"whitespace": {
"options": [
"check-branch",
"check-decl",
"check-operator",
"check-separator",
"check-type",
"check-typecast"
]
}
}
}

View File

@ -46,7 +46,7 @@ class XProtocolPlugin extends Plugin {
this.on('send', (data: any[]) => { this.on('send', (data: any[]) => {
const target = data[0]; const target = data[0];
this.sendTo(target, ...data.slice(1)).catch((error: Error) => { this.sendTo(target, ...data.slice(1)).catch((error: Error) => {
logger.error(`[xprotocol] Sending to protocol from event failed:`, error.message ?? error); logger.error('[xprotocol] Sending to protocol from event failed:', error.message ?? error);
}); });
}); });
} }