Skip to content

Commit

Permalink
style: eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
kamiya10 committed Dec 2, 2024
1 parent 297ae93 commit 758948e
Show file tree
Hide file tree
Showing 13 changed files with 93 additions and 205 deletions.
40 changes: 40 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import js from '@eslint/js';
import ts from 'typescript-eslint';
import globals from 'globals';
import stylistic from '@stylistic/eslint-plugin';

export default ts.config(
{
files: [
'**/src/**/*.ts',
],
},
{
ignores: [
'**/dist/**/*',
'**/rollup.config.mjs',
'rollup.config.mjs',
'**/eslint.config.mjs',
'eslint.config.mjs',
],
},
js.configs.recommended,
...ts.configs.strictTypeChecked,
...ts.configs.stylisticTypeChecked,
stylistic.configs.customize({
arrowParens: true,
semi: true,
flat: true,
}),
{
languageOptions: {
globals: {
...globals.browser,
},
parserOptions: {
projectService: true,
tsconfigRootDir: import.meta.dirname,
},
},
},
);
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"@rollup/plugin-typescript": "^12.1.1",
"@stylistic/eslint-plugin": "^2.11.0",
"eslint": "^9.16.0",
"globals": "^15.13.0",
"rollup": "^4.28.0",
"tslib": "^2.8.1",
"typescript": "^5.7.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/trem-kit/rollup.config.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createConfig } from '../../shared/rollup.config.mjs';
import pkg from './package.json' with { type: 'json' };

export default createConfig(pkg);
export default createConfig(pkg);
22 changes: 14 additions & 8 deletions packages/trem-kit/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
type Awaitable<T> = T | Promise<T>;

type ConfigValue = string | number | boolean;
type ConfigValues = ConfigValue | Array<ConfigValue>;
type ConfigValues = ConfigValue | ConfigValue[];

interface Config<T extends ConfigValues = ConfigValues> {
name: string;
description: string;
default: T;
choices?: T extends Array<ConfigValue> ? T : never;
choices?: T extends ConfigValue[] ? T : never;
}

type ConfigDef = Record<string, Config>;
type ConfigDef = Record<string, Config>;

interface AppConfig<T extends ConfigDef> {
get<K extends keyof T>(key: K):
(
T[K]['default'] extends Array<ConfigValue>
? T[K]['choices'] extends Array<ConfigValue>
T[K]['default'] extends ConfigValue[]
? T[K]['choices'] extends ConfigValue[]
? T[K]['choices']
: T[K]['default']
: T[K]['default']
Expand All @@ -32,8 +32,13 @@ interface AppLogger {
debug(message: string): void;
}

interface Eew {}
interface Report {}
interface Eew {
/** TODO: type Eew objects */
}

interface Report {
/** TODO: type Report objects */
}

interface Events {
load: [];
Expand All @@ -60,6 +65,7 @@ export interface PluginDef<T extends ConfigDef> {
setup(app: App<T>): Awaitable<void>;
}

// eslint-disable-next-line @typescript-eslint/no-empty-object-type
export function definePlugin<T extends ConfigDef = {}>(plugin: PluginDef<T>) {
return plugin;
}
}
169 changes: 0 additions & 169 deletions plugins/websocket/.eslintrc.json

This file was deleted.

2 changes: 0 additions & 2 deletions plugins/websocket/.gitattributes

This file was deleted.

2 changes: 0 additions & 2 deletions plugins/websocket/.gitignore

This file was deleted.

2 changes: 1 addition & 1 deletion plugins/websocket/rollup.config.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createConfig } from '../../shared/rollup.config.mjs';
import pkg from './package.json' with { type: 'json' };

export default createConfig(pkg);
export default createConfig(pkg);
28 changes: 14 additions & 14 deletions plugins/websocket/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { definePlugin } from "@exptechtw/trem-kit";
import { definePlugin } from '@exptechtw/trem-kit';

enum Service {
TremRts = "trem.rts",
TremEew = "trem.eew",
TremIntensity = "trem.intensity",
Eew = "websocket.eew",
Report = "websocket.report",
Intensity = "cwa.intensity",
TremRts = 'trem.rts',
TremEew = 'trem.eew',
TremIntensity = 'trem.intensity',
Eew = 'websocket.eew',
Report = 'websocket.report',
Intensity = 'cwa.intensity',
}

export default definePlugin({
name: "websocket",
description: "WebSocket implementation for TREM-Lite",
name: 'websocket',
description: 'WebSocket implementation for TREM-Lite',
version: '1.0.0',
settings: {
key: {
Expand All @@ -29,21 +29,21 @@ export default definePlugin({
setup(app) {
let ws: WebSocket | null = null;
let url: string | null = null;

const destroy = () => {
if (ws) {
ws.close();
ws = null;
}
}
};

const connect = () => {
destroy();
url = `wss://lb-${Math.ceil(Math.random() * 4)}.exptech.dev`;
url = `wss://lb-${Math.ceil(Math.random() * 4).toString()}.exptech.dev`;
ws = new WebSocket(url);
}
};

app.on('load', connect);
app.on('unload', destroy);
},
});
});
9 changes: 9 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 758948e

Please sign in to comment.