introduce eslint

This commit is contained in:
syuilo 2021-07-30 01:18:19 +09:00
parent 0616534af7
commit 677ed40b40
7 changed files with 1620 additions and 15 deletions

5
.eslintignore Normal file
View file

@ -0,0 +1,5 @@
node_modules
/built
/coverage
/.eslintrc.js
/jest.config.ts

32
.eslintrc.js Normal file
View file

@ -0,0 +1,32 @@
module.exports = {
root: true,
parser: '@typescript-eslint/parser',
plugins: [
'@typescript-eslint',
],
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
],
rules: {
'indent': ['error', 'tab', {
'SwitchCase': 1,
'flatTernaryExpressions': true,
}],
'eol-last': ['error', 'always'],
'semi': ['error', 'always'],
'quotes': ['error', 'single'],
'keyword-spacing': ['error', {
'before': true,
'after': true,
}],
'no-multi-spaces': ['error'],
'no-var': ['error'],
'prefer-arrow-callback': ['error'],
'no-throw-literal': ['error'],
'no-param-reassign': ['warn'],
'no-constant-condition': ['warn'],
'no-empty-pattern': ['warn'],
'@typescript-eslint/no-inferrable-types': ['off'],
},
};

20
.github/workflows/lint.yml vendored Normal file
View file

@ -0,0 +1,20 @@
name: Lint
on: [push, pull_request]
jobs:
lint:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup Node.js
uses: actions/setup-node@v1
with:
node-version: 16.x
- name: Install
run: npm i
- name: Lint
run: npm run lint

1542
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -8,6 +8,7 @@
"build": "npm run tsc", "build": "npm run tsc",
"tsc": "tsc", "tsc": "tsc",
"tsd": "tsd", "tsd": "tsd",
"lint": "eslint . --ext .js,.jsx,.ts,.tsx",
"jest": "jest --coverage --detectOpenHandles", "jest": "jest --coverage --detectOpenHandles",
"test": "npm run jest && npm run tsd" "test": "npm run jest && npm run tsd"
}, },
@ -18,6 +19,9 @@
"devDependencies": { "devDependencies": {
"@types/jest": "^26.0.23", "@types/jest": "^26.0.23",
"@types/node": "16.0.0", "@types/node": "16.0.0",
"@typescript-eslint/eslint-plugin": "4.28.5",
"@typescript-eslint/parser": "4.28.5",
"eslint": "7.31.0",
"jest": "^27.0.6", "jest": "^27.0.6",
"jest-fetch-mock": "^3.0.3", "jest-fetch-mock": "^3.0.3",
"jest-websocket-mock": "^2.2.1", "jest-websocket-mock": "^2.2.1",

View file

@ -7,13 +7,15 @@ import {
type TODO = Record<string, any> | null; type TODO = Record<string, any> | null;
type NoParams = Record<string, never>;
type ShowUserReq = { username: string; host?: string; } | { userId: User['id']; }; type ShowUserReq = { username: string; host?: string; } | { userId: User['id']; };
export type Endpoints = { export type Endpoints = {
// admin // admin
'admin/abuse-user-reports': { req: TODO; res: TODO; }; 'admin/abuse-user-reports': { req: TODO; res: TODO; };
'admin/delete-all-files-of-a-user': { req: { userId: User['id']; }; res: null; }; 'admin/delete-all-files-of-a-user': { req: { userId: User['id']; }; res: null; };
'admin/delete-logs': { req: {}; res: null; }; 'admin/delete-logs': { req: NoParams; res: null; };
'admin/get-index-stats': { req: TODO; res: TODO; }; 'admin/get-index-stats': { req: TODO; res: TODO; };
'admin/get-table-stats': { req: TODO; res: TODO; }; 'admin/get-table-stats': { req: TODO; res: TODO; };
'admin/invite': { req: TODO; res: TODO; }; 'admin/invite': { req: TODO; res: TODO; };
@ -73,7 +75,7 @@ export type Endpoints = {
// antennas // antennas
'antennas/create': { req: TODO; res: Antenna; }; 'antennas/create': { req: TODO; res: Antenna; };
'antennas/delete': { req: { antennaId: Antenna['id']; }; res: null; }; 'antennas/delete': { req: { antennaId: Antenna['id']; }; res: null; };
'antennas/list': { req: {}; res: Antenna[]; }; 'antennas/list': { req: NoParams; res: Antenna[]; };
'antennas/notes': { req: { antennaId: Antenna['id']; limit?: number; sinceId?: Note['id']; untilId?: Note['id']; }; res: Note[]; }; 'antennas/notes': { req: { antennaId: Antenna['id']; limit?: number; sinceId?: Note['id']; untilId?: Note['id']; }; res: Note[]; };
'antennas/show': { req: { antennaId: Antenna['id']; }; res: Antenna; }; 'antennas/show': { req: { antennaId: Antenna['id']; }; res: Antenna; };
'antennas/update': { req: TODO; res: Antenna; }; 'antennas/update': { req: TODO; res: Antenna; };
@ -256,7 +258,7 @@ export type Endpoints = {
'clips/update': { req: TODO; res: TODO; }; 'clips/update': { req: TODO; res: TODO; };
// drive // drive
'drive': { req: {}; res: { capacity: number; usage: number; }; }; 'drive': { req: NoParams; res: { capacity: number; usage: number; }; };
'drive/files': { req: { folderId?: DriveFolder['id'] | null; type?: DriveFile['type'] | null; limit?: number; sinceId?: DriveFile['id']; untilId?: DriveFile['id']; }; res: DriveFile[]; }; 'drive/files': { req: { folderId?: DriveFolder['id'] | null; type?: DriveFile['type'] | null; limit?: number; sinceId?: DriveFile['id']; untilId?: DriveFile['id']; }; res: DriveFile[]; };
'drive/files/attached-notes': { req: TODO; res: TODO; }; 'drive/files/attached-notes': { req: TODO; res: TODO; };
'drive/files/check-existence': { req: TODO; res: TODO; }; 'drive/files/check-existence': { req: TODO; res: TODO; };
@ -279,7 +281,7 @@ export type Endpoints = {
'endpoint': { req: { endpoint: string; }; res: { params: { name: string; type: string; }[]; }; }; 'endpoint': { req: { endpoint: string; }; res: { params: { name: string; type: string; }[]; }; };
// endpoints // endpoints
'endpoints': { req: {}; res: string[]; }; 'endpoints': { req: NoParams; res: string[]; };
// federation // federation
'federation/dns': { req: { host: string; }; res: { 'federation/dns': { req: { host: string; }; res: {
@ -311,7 +313,7 @@ export type Endpoints = {
'following/delete': { req: { userId: User['id'] }; res: User; }; 'following/delete': { req: { userId: User['id'] }; res: User; };
'following/requests/accept': { req: { userId: User['id'] }; res: null; }; 'following/requests/accept': { req: { userId: User['id'] }; res: null; };
'following/requests/cancel': { req: { userId: User['id'] }; res: User; }; 'following/requests/cancel': { req: { userId: User['id'] }; res: User; };
'following/requests/list': { req: {}; res: FollowRequest[]; }; 'following/requests/list': { req: NoParams; res: FollowRequest[]; };
'following/requests/reject': { req: { userId: User['id'] }; res: null; }; 'following/requests/reject': { req: { userId: User['id'] }; res: null; };
// gallery // gallery
@ -334,7 +336,7 @@ export type Endpoints = {
'games/reversi/match/cancel': { req: TODO; res: TODO; }; 'games/reversi/match/cancel': { req: TODO; res: TODO; };
// get-online-users-count // get-online-users-count
'get-online-users-count': { req: {}; res: { count: number; }; }; 'get-online-users-count': { req: NoParams; res: { count: number; }; };
// hashtags // hashtags
'hashtags/list': { req: TODO; res: TODO; }; 'hashtags/list': { req: TODO; res: TODO; };
@ -344,7 +346,7 @@ export type Endpoints = {
'hashtags/users': { req: TODO; res: TODO; }; 'hashtags/users': { req: TODO; res: TODO; };
// i // i
'i': { req: {}; res: User; }; 'i': { req: NoParams; res: User; };
'i/apps': { req: TODO; res: TODO; }; 'i/apps': { req: TODO; res: TODO; };
'i/authorized-apps': { req: TODO; res: TODO; }; 'i/authorized-apps': { req: TODO; res: TODO; };
'i/change-password': { req: TODO; res: TODO; }; 'i/change-password': { req: TODO; res: TODO; };
@ -382,7 +384,7 @@ export type Endpoints = {
'i/registry/keys-with-type': { req: { scope?: string[]; }; res: Record<string, 'null' | 'array' | 'number' | 'string' | 'boolean' | 'object'>; }; 'i/registry/keys-with-type': { req: { scope?: string[]; }; res: Record<string, 'null' | 'array' | 'number' | 'string' | 'boolean' | 'object'>; };
'i/registry/keys': { req: { scope?: string[]; }; res: string[]; }; 'i/registry/keys': { req: { scope?: string[]; }; res: string[]; };
'i/registry/remove': { req: { key: string; scope?: string[]; }; res: null; }; 'i/registry/remove': { req: { key: string; scope?: string[]; }; res: null; };
'i/registry/scopes': { req: {}; res: string[][]; }; 'i/registry/scopes': { req: NoParams; res: string[][]; };
'i/registry/set': { req: { key: string; value: any; scope?: string[]; }; res: null; }; 'i/registry/set': { req: { key: string; value: any; scope?: string[]; }; res: null; };
'i/revoke-token': { req: TODO; res: TODO; }; 'i/revoke-token': { req: TODO; res: TODO; };
'i/signin-history': { req: { limit?: number; sinceId?: Signin['id']; untilId?: Signin['id']; }; res: Signin[]; }; 'i/signin-history': { req: { limit?: number; sinceId?: Signin['id']; untilId?: Signin['id']; }; res: Signin[]; };
@ -512,7 +514,7 @@ export type Endpoints = {
// notifications // notifications
'notifications/create': { req: { body: string; header?: string | null; icon?: string | null; }; res: null; }; 'notifications/create': { req: { body: string; header?: string | null; icon?: string | null; }; res: null; };
'notifications/mark-all-as-read': { req: {}; res: null; }; 'notifications/mark-all-as-read': { req: NoParams; res: null; };
'notifications/read': { req: { notificationId: Notification['id']; }; res: null; }; 'notifications/read': { req: { notificationId: Notification['id']; }; res: null; };
// page-push // page-push
@ -521,14 +523,14 @@ export type Endpoints = {
// pages // pages
'pages/create': { req: TODO; res: Page; }; 'pages/create': { req: TODO; res: Page; };
'pages/delete': { req: { pageId: Page['id']; }; res: null; }; 'pages/delete': { req: { pageId: Page['id']; }; res: null; };
'pages/featured': { req: {}; res: Page[]; }; 'pages/featured': { req: NoParams; res: Page[]; };
'pages/like': { req: { pageId: Page['id']; }; res: null; }; 'pages/like': { req: { pageId: Page['id']; }; res: null; };
'pages/show': { req: { pageId?: Page['id']; name?: string; username?: string; }; res: Page; }; 'pages/show': { req: { pageId?: Page['id']; name?: string; username?: string; }; res: Page; };
'pages/unlike': { req: { pageId: Page['id']; }; res: null; }; 'pages/unlike': { req: { pageId: Page['id']; }; res: null; };
'pages/update': { req: TODO; res: null; }; 'pages/update': { req: TODO; res: null; };
// ping // ping
'ping': { req: {}; res: { pong: number; }; }; 'ping': { req: NoParams; res: { pong: number; }; };
// pinned-users // pinned-users
'pinned-users': { req: TODO; res: TODO; }; 'pinned-users': { req: TODO; res: TODO; };
@ -547,10 +549,10 @@ export type Endpoints = {
'room/update': { req: TODO; res: TODO; }; 'room/update': { req: TODO; res: TODO; };
// stats // stats
'stats': { req: {}; res: Stats; }; 'stats': { req: NoParams; res: Stats; };
// server-info // server-info
'server-info': { req: {}; res: ServerInfo; }; 'server-info': { req: NoParams; res: ServerInfo; };
// sw // sw
'sw/register': { req: TODO; res: TODO; }; 'sw/register': { req: TODO; res: TODO; };
@ -578,7 +580,7 @@ export type Endpoints = {
'users/groups/update': { req: TODO; res: TODO; }; 'users/groups/update': { req: TODO; res: TODO; };
'users/lists/create': { req: { name: string; }; res: UserList; }; 'users/lists/create': { req: { name: string; }; res: UserList; };
'users/lists/delete': { req: { listId: UserList['id']; }; res: null; }; 'users/lists/delete': { req: { listId: UserList['id']; }; res: null; };
'users/lists/list': { req: {}; res: UserList[]; }; 'users/lists/list': { req: NoParams; res: UserList[]; };
'users/lists/pull': { req: { listId: UserList['id']; userId: User['id']; }; res: null; }; 'users/lists/pull': { req: { listId: UserList['id']; userId: User['id']; }; res: null; };
'users/lists/push': { req: { listId: UserList['id']; userId: User['id']; }; res: null; }; 'users/lists/push': { req: { listId: UserList['id']; userId: User['id']; }; res: null; };
'users/lists/show': { req: { listId: UserList['id']; }; res: UserList; }; 'users/lists/show': { req: { listId: UserList['id']; }; res: UserList; };

View file

@ -4,7 +4,7 @@ import ReconnectingWebsocket from 'reconnecting-websocket';
import { stringify } from 'querystring'; import { stringify } from 'querystring';
import { BroadcastEvents, Channels } from './streaming.types'; import { BroadcastEvents, Channels } from './streaming.types';
function urlQuery(obj: {}): string { function urlQuery(obj: Record<string, unknown>): string {
return stringify(Object.entries(obj) return stringify(Object.entries(obj)
.filter(([, v]) => Array.isArray(v) ? v.length : v !== undefined) .filter(([, v]) => Array.isArray(v) ? v.length : v !== undefined)
.reduce((a, [k, v]) => (a[k] = v, a), {} as Record<string, any>)); .reduce((a, [k, v]) => (a[k] = v, a), {} as Record<string, any>));