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

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

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