replace tslint with eslint

This commit is contained in:
Evert Prants 2021-12-15 18:38:18 +02:00
parent e24a87d3e1
commit 1406f46b2e
Signed by: evert
GPG Key ID: 1688DA83D222D0B5
11 changed files with 4650 additions and 191 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/
deployment.json
*.js
!.eslintrc.js
*.d.ts
*.tsbuildinfo
*.tsbuildinfo

View File

@ -32,7 +32,6 @@ function addCommands(plugin: UtilityPlugin, commands: any): void {
}
try {
// tslint:disable-next-line: no-eval
const mesh = eval(script);
if (mesh === undefined) {
return true;

View File

@ -52,6 +52,7 @@ class Parsers {
return null;
}
// eslint-disable-next-line no-control-regex
result.description = response.name.replace(/[^\x00-\x7F]./g, '').replace(/\n/g, ' ');
result.maxPlayers = response.maxplayers;

4526
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -25,6 +25,13 @@
"@types/convert-units": "^2.3.5",
"@types/gamedig": "^3.0.1",
"@types/mathjs": "^9.4.1",
"@types/node": "^16.7.10"
"@types/node": "^16.7.10",
"@typescript-eslint/eslint-plugin": "^5.7.0",
"@typescript-eslint/eslint-plugin-tslint": "^5.7.0",
"@typescript-eslint/parser": "^5.7.0",
"eslint": "^8.4.1",
"eslint-plugin-import": "^2.25.3",
"eslint-plugin-jsdoc": "^37.2.2",
"eslint-plugin-prefer-arrow": "^1.2.3"
}
}

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": true,
"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

@ -43,8 +43,8 @@ async function mastodonResponse(msg: IMessage, url: string, type = 'Mastodon'):
const keys = [];
let end = sanitizeEscapedText(content.replace(/<\/p>/g, '\n') // Add newlines to paragraph endings
.replace(/<br \/>/g, '\n') // Add newlines instead of <br />
.replace(/(<([^>]+)>)/ig, '')); // Strip the rest of the HTML out
.replace(/<br \/>/g, '\n') // Add newlines instead of <br />
.replace(/(<([^>]+)>)/ig, '')); // Strip the rest of the HTML out
if (end.length > 220) {
end = end.substring(0, 220) + '…';
@ -75,29 +75,32 @@ class FediResponsePlugin extends Plugin {
@DependencyLoad('urlreply')
addUrlReply(urlreply: any): void {
urlreply.registerHandler(this.name, 'html/mastodon',
urlreply.registerHandler(
this.name,
'html/mastodon',
async (url: string, msg: IMessage, title: string, body: any): Promise<boolean> => {
const type = url.match('/notice/') ? 'Pleroma' : 'Mastodon';
let pass = false;
const type = url.match('/notice/') ? 'Pleroma' : 'Mastodon';
let pass = false;
if (type === 'Pleroma') {
pass = true;
} else {
const tag = body('a[href="https://joinmastodon.org/"]');
if (tag && tag.text() && tag.text().indexOf('Mastodon') !== -1) {
pass = true;
if (type === 'Pleroma') {
pass = true;
} else {
const tag = body('a[href="https://joinmastodon.org/"]');
if (tag && tag.text() && tag.text().indexOf('Mastodon') !== -1) {
pass = true;
}
}
if (pass) {
const mastodonTest = await mastodonResponse(msg, url, type);
if (mastodonTest) {
return true;
}
}
return false;
}
}
if (pass) {
const mastodonTest = await mastodonResponse(msg, url, type);
if (mastodonTest) {
return true;
}
}
return false;
});
);
}
}

View File

@ -10,9 +10,11 @@ import { IMessage } from '@squeebot/core/lib/types';
import cheerio from 'cheerio';
import * as urllib from 'url';
type ActionFn = (url: urllib.URL, msg: IMessage, data?: any) => Promise<any>;
interface URLHandler {
plugin: string;
action: Function;
action: ActionFn;
}
let urlHandlers: {[key: string]: URLHandler} = {};
@ -143,8 +145,9 @@ async function getYoutubeFromVideo(
}
const dislikeAPI = `https://returnyoutubedislikeapi.com/votes?videoId=${id}`;
let dislikeData = await httpGET(dislikeAPI);
let dislikeData;
try {
dislikeData = await httpGET(dislikeAPI);
dislikeData = JSON.parse(dislikeData);
} catch (e) {
dislikeData = null;
@ -219,7 +222,7 @@ async function getYoutubeFromVideo(
}
})
class URLReplyPlugin extends Plugin {
registerHandler(plugin: string, match: string, handler: Function): void {
registerHandler(plugin: string, match: string, handler: ActionFn): void {
if (!handler || typeof handler !== 'function') {
throw new Error('Expected handler function as third argument.');
}

View File

@ -72,7 +72,7 @@ export function RGBToHSL(r: number, g: number, b: number): {[key: string]: numbe
// Make negative hues positive behind 360°
if (h < 0) {
h += 360;
h += 360;
}
// Calculate lightness
@ -136,6 +136,13 @@ export function createUnitIndex(): void {
);
}
// degree(s) Celsius -> celsius
if (singular.startsWith('degree ')) {
unitIndex[abbr].push(
singular.split(' ')[1].toLowerCase(),
);
}
// " per " -> "/"
const appendages: string[] = [];
unitIndex[abbr].forEach((entry) => {
@ -187,27 +194,27 @@ export function ASCIIBinaryConverter(input: string, simplified: string[]): strin
let text = input.split(' ').slice(2).join(' ');
switch (simplified[0] ? simplified[0].toUpperCase() : null) {
case 'ENCODE':
strArr = text.split('');
case 'ENCODE':
strArr = text.split('');
for (i in strArr) {
response += ('0000000' +
for (i in strArr) {
response += ('0000000' +
parseInt(Buffer.from(strArr[i].toString(), 'utf8').toString('hex'), 16).toString(2)).slice(-8);
}
}
response = response.substr(1);
response = response.substr(1);
break;
case 'DECODE':
text = text.split(' ').join('');
i = 0;
break;
case 'DECODE':
text = text.split(' ').join('');
i = 0;
while (8 * (i + 1) <= text.length) {
response += Buffer.from(parseInt(text.substr(8 * i, 8), 2).toString(16), 'hex').toString('utf8');
i++;
}
while (8 * (i + 1) <= text.length) {
response += Buffer.from(parseInt(text.substr(8 * i, 8), 2).toString(16), 'hex').toString('utf8');
i++;
}
response = response.replace(/\n/g, '\\n').replace(/\r/g, '\\r');
response = response.replace(/\n/g, '\\n').replace(/\r/g, '\\r');
}
return response;
@ -219,20 +226,20 @@ export function ASCIIHexConverter(input: string, simplified: string[]): string {
let text = input.split(' ').slice(2).join(' ');
switch (simplified[0] ? simplified[0].toUpperCase() : null) {
case 'DECODE':
text = text.replace(/\s/g, '');
case 'DECODE':
text = text.replace(/\s/g, '');
for (i = 0; i < text.length; i += 2) {
response += String.fromCharCode(parseInt(text.substr(i, 2), 16));
}
for (i = 0; i < text.length; i += 2) {
response += String.fromCharCode(parseInt(text.substr(i, 2), 16));
}
response = response.replace(/\n/g, '\\n').replace(/\r/g, '\\r');
break;
case 'ENCODE':
for (i = 0; i < text.length; i++) {
response += text.charCodeAt(i).toString(16) + ' ';
}
break;
response = response.replace(/\n/g, '\\n').replace(/\r/g, '\\r');
break;
case 'ENCODE':
for (i = 0; i < text.length; i++) {
response += text.charCodeAt(i).toString(16) + ' ';
}
break;
}
return response;
@ -243,12 +250,12 @@ export function base64Converter(input: string, simplified: string[]): string {
const text = input.split(' ').slice(2).join(' ');
switch (simplified[0] ? simplified[0].toUpperCase() : null) {
case 'DECODE':
response = (Buffer.from(text, 'base64').toString('ascii')).replace(/\n/g, '\\n').replace(/\r/g, '\\r');
break;
case 'ENCODE':
response = Buffer.from(text).toString('base64');
break;
case 'DECODE':
response = (Buffer.from(text, 'base64').toString('ascii')).replace(/\n/g, '\\n').replace(/\r/g, '\\r');
break;
case 'ENCODE':
response = Buffer.from(text).toString('base64');
break;
}
return response;