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/ /.out/
deployment.json deployment.json
*.js *.js
!.eslintrc.js
*.d.ts *.d.ts
*.tsbuildinfo *.tsbuildinfo

View File

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

View File

@ -52,6 +52,7 @@ class Parsers {
return null; return null;
} }
// eslint-disable-next-line no-control-regex
result.description = response.name.replace(/[^\x00-\x7F]./g, '').replace(/\n/g, ' '); result.description = response.name.replace(/[^\x00-\x7F]./g, '').replace(/\n/g, ' ');
result.maxPlayers = response.maxplayers; 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/convert-units": "^2.3.5",
"@types/gamedig": "^3.0.1", "@types/gamedig": "^3.0.1",
"@types/mathjs": "^9.4.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 = []; const keys = [];
let end = sanitizeEscapedText(content.replace(/<\/p>/g, '\n') // Add newlines to paragraph endings let end = sanitizeEscapedText(content.replace(/<\/p>/g, '\n') // Add newlines to paragraph endings
.replace(/<br \/>/g, '\n') // Add newlines instead of <br /> .replace(/<br \/>/g, '\n') // Add newlines instead of <br />
.replace(/(<([^>]+)>)/ig, '')); // Strip the rest of the HTML out .replace(/(<([^>]+)>)/ig, '')); // Strip the rest of the HTML out
if (end.length > 220) { if (end.length > 220) {
end = end.substring(0, 220) + '…'; end = end.substring(0, 220) + '…';
@ -75,29 +75,32 @@ class FediResponsePlugin extends Plugin {
@DependencyLoad('urlreply') @DependencyLoad('urlreply')
addUrlReply(urlreply: any): void { 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> => { async (url: string, msg: IMessage, title: string, body: any): Promise<boolean> => {
const type = url.match('/notice/') ? 'Pleroma' : 'Mastodon'; const type = url.match('/notice/') ? 'Pleroma' : 'Mastodon';
let pass = false; let pass = false;
if (type === 'Pleroma') { if (type === 'Pleroma') {
pass = true; pass = true;
} else { } else {
const tag = body('a[href="https://joinmastodon.org/"]'); const tag = body('a[href="https://joinmastodon.org/"]');
if (tag && tag.text() && tag.text().indexOf('Mastodon') !== -1) { if (tag && tag.text() && tag.text().indexOf('Mastodon') !== -1) {
pass = true; 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 cheerio from 'cheerio';
import * as urllib from 'url'; import * as urllib from 'url';
type ActionFn = (url: urllib.URL, msg: IMessage, data?: any) => Promise<any>;
interface URLHandler { interface URLHandler {
plugin: string; plugin: string;
action: Function; action: ActionFn;
} }
let urlHandlers: {[key: string]: URLHandler} = {}; let urlHandlers: {[key: string]: URLHandler} = {};
@ -143,8 +145,9 @@ async function getYoutubeFromVideo(
} }
const dislikeAPI = `https://returnyoutubedislikeapi.com/votes?videoId=${id}`; const dislikeAPI = `https://returnyoutubedislikeapi.com/votes?videoId=${id}`;
let dislikeData = await httpGET(dislikeAPI); let dislikeData;
try { try {
dislikeData = await httpGET(dislikeAPI);
dislikeData = JSON.parse(dislikeData); dislikeData = JSON.parse(dislikeData);
} catch (e) { } catch (e) {
dislikeData = null; dislikeData = null;
@ -219,7 +222,7 @@ async function getYoutubeFromVideo(
} }
}) })
class URLReplyPlugin extends Plugin { 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') { if (!handler || typeof handler !== 'function') {
throw new Error('Expected handler function as third argument.'); 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° // Make negative hues positive behind 360°
if (h < 0) { if (h < 0) {
h += 360; h += 360;
} }
// Calculate lightness // 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 " -> "/" // " per " -> "/"
const appendages: string[] = []; const appendages: string[] = [];
unitIndex[abbr].forEach((entry) => { unitIndex[abbr].forEach((entry) => {
@ -187,27 +194,27 @@ export function ASCIIBinaryConverter(input: string, simplified: string[]): strin
let text = input.split(' ').slice(2).join(' '); let text = input.split(' ').slice(2).join(' ');
switch (simplified[0] ? simplified[0].toUpperCase() : null) { switch (simplified[0] ? simplified[0].toUpperCase() : null) {
case 'ENCODE': case 'ENCODE':
strArr = text.split(''); strArr = text.split('');
for (i in strArr) { for (i in strArr) {
response += ('0000000' + response += ('0000000' +
parseInt(Buffer.from(strArr[i].toString(), 'utf8').toString('hex'), 16).toString(2)).slice(-8); parseInt(Buffer.from(strArr[i].toString(), 'utf8').toString('hex'), 16).toString(2)).slice(-8);
} }
response = response.substr(1); response = response.substr(1);
break; break;
case 'DECODE': case 'DECODE':
text = text.split(' ').join(''); text = text.split(' ').join('');
i = 0; i = 0;
while (8 * (i + 1) <= text.length) { while (8 * (i + 1) <= text.length) {
response += Buffer.from(parseInt(text.substr(8 * i, 8), 2).toString(16), 'hex').toString('utf8'); response += Buffer.from(parseInt(text.substr(8 * i, 8), 2).toString(16), 'hex').toString('utf8');
i++; i++;
} }
response = response.replace(/\n/g, '\\n').replace(/\r/g, '\\r'); response = response.replace(/\n/g, '\\n').replace(/\r/g, '\\r');
} }
return response; return response;
@ -219,20 +226,20 @@ export function ASCIIHexConverter(input: string, simplified: string[]): string {
let text = input.split(' ').slice(2).join(' '); let text = input.split(' ').slice(2).join(' ');
switch (simplified[0] ? simplified[0].toUpperCase() : null) { switch (simplified[0] ? simplified[0].toUpperCase() : null) {
case 'DECODE': case 'DECODE':
text = text.replace(/\s/g, ''); text = text.replace(/\s/g, '');
for (i = 0; i < text.length; i += 2) { for (i = 0; i < text.length; i += 2) {
response += String.fromCharCode(parseInt(text.substr(i, 2), 16)); response += String.fromCharCode(parseInt(text.substr(i, 2), 16));
} }
response = response.replace(/\n/g, '\\n').replace(/\r/g, '\\r'); response = response.replace(/\n/g, '\\n').replace(/\r/g, '\\r');
break; break;
case 'ENCODE': case 'ENCODE':
for (i = 0; i < text.length; i++) { for (i = 0; i < text.length; i++) {
response += text.charCodeAt(i).toString(16) + ' '; response += text.charCodeAt(i).toString(16) + ' ';
} }
break; break;
} }
return response; return response;
@ -243,12 +250,12 @@ export function base64Converter(input: string, simplified: string[]): string {
const text = input.split(' ').slice(2).join(' '); const text = input.split(' ').slice(2).join(' ');
switch (simplified[0] ? simplified[0].toUpperCase() : null) { switch (simplified[0] ? simplified[0].toUpperCase() : null) {
case 'DECODE': case 'DECODE':
response = (Buffer.from(text, 'base64').toString('ascii')).replace(/\n/g, '\\n').replace(/\r/g, '\\r'); response = (Buffer.from(text, 'base64').toString('ascii')).replace(/\n/g, '\\n').replace(/\r/g, '\\r');
break; break;
case 'ENCODE': case 'ENCODE':
response = Buffer.from(text).toString('base64'); response = Buffer.from(text).toString('base64');
break; break;
} }
return response; return response;