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'
]
}
};

1
.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

@ -75,7 +75,9 @@ 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;
@ -97,7 +99,8 @@ class FediResponsePlugin extends Plugin {
} }
return false; 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

@ -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) => {