Skip to content

Commit

Permalink
autoformat and test workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
hans-m-song committed May 27, 2024
1 parent 723eaa9 commit 0f6cb15
Show file tree
Hide file tree
Showing 19 changed files with 112 additions and 83 deletions.
63 changes: 63 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
module.exports = {
// files: ['src/**/*.{ts,tsx}'],
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'plugin:prettier/recommended',
],
env: {
node: true,
browser: true,
},
plugins: ['import', '@typescript-eslint', 'prettier'],
parser: '@typescript-eslint/parser',
rules: {
'import/order': [
'warn',
{
pathGroups: [
{
pattern: '~/**',
group: 'parent',
position: 'before',
},
],
groups: [
['builtin', 'external'],
['parent', 'sibling', 'index'],
],
'newlines-between': 'always',
alphabetize: {
order: 'asc',
caseInsensitive: true,
},
},
],
'@typescript-eslint/no-explicit-any': ['off', {}],
'@typescript-eslint/ban-types': [
'error',
{
types: {
Function: false,
'extend-defaults': true,
},
},
],
'no-unused-vars': ['off'],
'@typescript-eslint/no-unused-vars': [
'warn',
{
vars: 'all',
args: 'after-used',
ignoreRestSiblings: false,
argsIgnorePattern: '^_',
},
],
},
overrides: [
{
files: ['**/*.test.ts', '**/*.test.tsx'],
plugins: ['jest'],
},
],
};
27 changes: 27 additions & 0 deletions .github/workflows/_test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
on: push

jobs:
test:
runs-on: self-hosted

steps:
- uses: actions/checkout@v4

- uses: actions/setup-node@v4
with:
node-version-file: .nvmrc
cache: false

- name: Install dependencies
run: npm install

- name: Check generated files are up to date
run: |
npm run generate
git diff --exit-code
- name: Lint
run: npm run lint

- name: Test
run: npm run test:ci
64 changes: 0 additions & 64 deletions eslint.config.js

This file was deleted.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@
"start": "node dist/index.js",
"generate": "tsx bin/generate-queries.ts schema/queries.sql src/lib/cache/queries.ts",
"debug": "nodemon",
"lint": "eslint \"src/**/*.ts\"",
"lint": "eslint \"src/**/*.{ts,tsx}\"",
"lint:fix": "prettier --write ./src && yarn lint --fix",
"test": "jest",
"test:ci": "jest --runInBand --detectOpenHandles --silent",
"schema:diff": "atlas schema diff --from sqlite://local.db --to file://schema/tables.sql --dev-url 'sqlite://dev?mode=memory'",
"schema:apply": "atlas schema apply --url sqlite://local.db --to file://schema/tables.sql --dev-url 'sqlite://dev?mode=memory'"
},
Expand Down
2 changes: 1 addition & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FastifyReply, FastifyRequest } from 'fastify';
import { FastifyRequest } from 'fastify';
import pino from 'pino';

import { assertEnv, boolEnv, enumEnv, numEnv, obscure, serialiseError } from './lib/utils';
Expand Down
3 changes: 2 additions & 1 deletion src/lib/AsyncQueue.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { describe, it, expect, jest } from '@jest/globals';
import { AsyncQueue } from './AsyncQueue';
import { promisify } from 'util';

import { AsyncQueue } from './AsyncQueue';

const sleep = promisify(setTimeout);

describe('AsyncQueue', () => {
Expand Down
1 change: 1 addition & 0 deletions src/lib/AsyncQueue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export declare interface AsyncQueue<T = any> {
emit(event: JobEvent, job: Job<T>): boolean;
}

// eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging
export class AsyncQueue<T = any> extends EventEmitter {
concurrency: number;
items: Job<T>[] = [];
Expand Down
2 changes: 1 addition & 1 deletion src/lib/AudioFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import fs from 'fs/promises';
import path from 'path';
import { isMatching, P } from 'ts-pattern';

import { log } from '../config';
import { Bucket } from './Bucket';
import { download, downloaderOutputDir } from './Downloader';
import { GuardType } from './utils';
import { log } from '../config';

export type AudioFileMetadata = GuardType<typeof isAudioFileMetadata>;
export const isAudioFileMetadata = isMatching({
Expand Down
2 changes: 1 addition & 1 deletion src/lib/CountDown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export class CountDown {
}

get ticking() {
return typeof this.ticker != undefined && this.remainder < this.duration;
return typeof this.ticker !== 'undefined' && this.remainder < this.duration;
}

get runtime() {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/Downloader.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { ChildProcessWithoutNullStreams, spawn } from 'child_process';
import path from 'path';

import { AsyncQueue } from './AsyncQueue';
import { trimToJsonObject, tryParseJSON } from './utils';
import { config, log } from '../config';
import { AsyncQueue } from './AsyncQueue';

export const downloaderCacheDir = path.join(config.cacheDir, 'ytdl');
export const downloaderOutputDir = path.join(config.cacheDir, 'out');
Expand Down
4 changes: 2 additions & 2 deletions src/lib/PlaylistItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ export class PlaylistItem extends AudioFile {
value: this.timer.ticking
? `${runtime} / ${duration}`
: playlist.current?.videoId !== this.videoId
? `${duration} (eta ${eta})`
: duration,
? `${duration} (eta ${eta})`
: duration,
inline: true,
},
]);
Expand Down
2 changes: 1 addition & 1 deletion src/lib/Spotify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import 'dotenv/config';

import axios, { AxiosInstance } from 'axios';

import { config, log } from '../config';
import { encodeQueryParams } from './utils';
import { config, log } from '../config';

interface AccessTokenResponse {
access_token: string;
Expand Down
2 changes: 1 addition & 1 deletion src/lib/audio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import {
VoiceBasedChannel,
} from 'discord.js';

import { log } from '../config';
import { getPlayer, Player } from './Player';
import { log } from '../config';

type VoiceCommandOptions = { allowConnect?: boolean; allowRetry?: boolean };

Expand Down
2 changes: 1 addition & 1 deletion src/lib/cache/database.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Client, ResultSet, createClient } from '@libsql/client';
import { ZodSchema, z } from 'zod';

import { config, log } from '../../config';
import { ZodSchema, z } from 'zod';

export const expandResultSet = (results: ResultSet): any[] => {
if (results.rows.length < 1) {
Expand Down
4 changes: 2 additions & 2 deletions src/server/fragments/QueueTable.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import React from 'preact/compat';

import { Button } from './Button';
import { Link } from './Link';
import { Pagination } from './Pagination';
import { QueuedSong } from '../../lib/cache';
import { secToTimeFragments } from '../../lib/utils';
import { Trigger } from '../consts';
import { Pagination } from './Pagination';
import { Link } from './Link';

export interface QueueTableProps {
channelId: string;
Expand Down
2 changes: 1 addition & 1 deletion src/server/fragments/SongSearchForm.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { QueryResult } from '../../lib/Youtube';
import { Button } from './Button';
import { Link } from './Link';
import { QueryResult } from '../../lib/Youtube';

export interface SongSearchFormProps {
channelId?: string;
Expand Down
2 changes: 1 addition & 1 deletion src/server/fragments/SongTable.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import React from 'preact/compat';

import { Button } from './Button';
import { Link } from './Link';
import { Pagination } from './Pagination';
import { Song } from '../../lib/cache';
import { secToTimeFragments, slugify } from '../../lib/utils';
import { Trigger } from '../consts';
import { Link } from './Link';

export interface SongTableProps {
channelId?: string;
Expand Down
4 changes: 2 additions & 2 deletions src/server/router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@ import React from 'preact/compat';
import { render } from 'preact-render-to-string';

import { ContentType, Header, Trigger } from './consts';
import { ChannelList } from './fragments/ChannelList';
import { Diagnostics } from './fragments/Diagnostics';
import { ErrorSurface } from './fragments/ErrorSurface';
import { QueueTable } from './fragments/QueueTable';
import { SongForm } from './fragments/SongForm';
import { SongSearchResultsTable } from './fragments/SongSearchForm';
import { SongTable } from './fragments/SongTable';
import { Channels } from './views/Channels';
import { Layout } from './views/Layout';
import { Queue } from './views/Queue';
import { Songs } from './views/Songs';
import { QueueDAO, SongDAO, SongSchema } from '../lib/cache';
import { Pagination } from '../lib/cache/database';
import { version } from '../lib/Downloader';
import { Youtube } from '../lib/Youtube';
import { Channels } from './views/Channels';
import { ChannelList } from './fragments/ChannelList';

export const router = async (app: FastifyInstance) => {
app.get('/', async (_, reply) => reply.redirect('/diagnostics'));
Expand Down
4 changes: 2 additions & 2 deletions src/server/views/Songs.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React from 'preact/compat';

import { SongSearchForm } from '../fragments/SongSearchForm';
import { SongForm } from '../fragments/SongForm';
import { Trigger } from '../consts';
import { SongForm } from '../fragments/SongForm';
import { SongSearchForm } from '../fragments/SongSearchForm';

export interface SongProps {
channelId: string;
Expand Down

0 comments on commit 0f6cb15

Please sign in to comment.