Skip to content

Commit

Permalink
stricter linting config
Browse files Browse the repository at this point in the history
  • Loading branch information
cdleveille committed Oct 22, 2024
1 parent 3e291f3 commit 2612bb6
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 30 deletions.
Binary file modified bun.lockb
Binary file not shown.
16 changes: 11 additions & 5 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,21 @@ export default [
{
ignores: ["node_modules/", "public/"]
},
...tseslint.config(eslint.configs.recommended, ...tseslint.configs.recommended, {
...tseslint.config(eslint.configs.recommended, ...tseslint.configs.recommendedTypeChecked, {
languageOptions: {
ecmaVersion: "latest",
sourceType: "module"
parserOptions: {
projectService: true,
tsconfigRootDir: import.meta.dirname
}
},
rules: {
"@typescript-eslint/ban-ts-comment": "off",
"@typescript-eslint/no-var-requires": "off",
"@typescript-eslint/no-require-imports": "off"
"@typescript-eslint/no-misused-promises": [
"error",
{
checksVoidReturn: false
}
]
}
})
];
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,18 @@
"type": "module",
"scripts": {
"compose": "docker compose -f \"./.fullstack-bun-dev-container/docker-compose.yml\" up -d --build",
"lint": "bunx eslint . && bunx prettier --check .",
"fix": "bunx eslint --fix . && bunx prettier --write .",
"lint": "eslint . && prettier --check .",
"fix": "eslint --fix . && prettier --write .",
"build": "bun ./scripts/build.ts",
"build:prod": "bun ./scripts/build.ts BUN_ENV=production && workbox injectManifest workbox-config.json",
"dev": "bun --watch ./src/server/index.ts",
"start": "bun ./src/server/index.ts"
},
"devDependencies": {
"@eslint/js": "^9.13.0",
"@types/compression": "^1.7.5",
"@types/cors": "^2.8.17",
"@types/eslint__js": "^8.42.3",
"@types/express": "^5.0.0",
"@types/react": "^18.3.11",
"@types/react-dom": "^18.3.1",
Expand Down
7 changes: 3 additions & 4 deletions processes/watch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@ const stopWatching = async () => {
process.on("exit", () => stopWatching);
process.on("SIGINT", () => stopWatching);

export const initWatch = async (emitReload: () => void) => {
const buildAndReloadClient = async () => {
export const initWatch = (emitReload: () => void) => {
watcher.on("change", async () => {
await buildClient();
emitReload();
};
watcher.on("change", buildAndReloadClient);
});
};
5 changes: 4 additions & 1 deletion src/client/hooks/useApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ export const useApi = () => {
const toAndFrom = useCallback(
async <T>({ event, data, callback }: TReqParams<T>) => {
return new Promise<T>((resolve, reject) => {
const timeout = setTimeout(() => reject(`Request timed out after ${TIMEOUT_MS}ms.`), TIMEOUT_MS);
const timeout = setTimeout(
() => reject(new Error(`Request timed out after ${TIMEOUT_MS}ms.`)),
TIMEOUT_MS
);
const onRes = (res: T) => {
socket.off(event, onRes);
clearTimeout(timeout);
Expand Down
18 changes: 9 additions & 9 deletions src/client/sw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ const isCacheFirstWithoutHash = (filename: string) => {
return false;
};

const onInstall = async () => {
const urlsToPrecache = ["/", ...(manifest?.length > 0 ? manifest.map(({ url }) => url) : [])];
const cache = await caches.open(cacheName);
await cache.addAll([...urlsToPrecache.map(url => url)]);
};

self.addEventListener("install", event => {
self.skipWaiting();
event.waitUntil(
(async () => {
const urlsToPrecache = ["/", ...(manifest?.length > 0 ? manifest.map(({ url }) => url) : [])];
const cache = await caches.open(cacheName);
await cache.addAll([...urlsToPrecache.map(url => url)]);
})()
);
void self.skipWaiting();
event.waitUntil(onInstall());
});

self.addEventListener("activate", event => {
Expand All @@ -57,7 +57,7 @@ const trimCache = (url: URL) => {
const hash = url.href.split(cacheFirstHashPrefix)[1];
const urlSuffixSplit = url.href.split(".");
const urlSuffix = urlSuffixSplit[urlSuffixSplit.length - 1];
(async () => {
void (async () => {
const cache = await caches.open(cacheName);
const requests = await cache.keys();
for (const request of requests) {
Expand Down
4 changes: 2 additions & 2 deletions src/client/utils/browser.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const accessStorage = (storage: Storage) => ({
setItem: (key: string, data: unknown) => storage.setItem(key, JSON.stringify(data)),
getItem: <T = unknown>(key: string): T | null => {
getItem: <T = unknown>(key: string) => {
const data = storage.getItem(key);
if (data !== null) return JSON.parse(data);
if (data !== null) return JSON.parse(data) as T;
return null;
},
removeItem: (key: string) => storage.removeItem(key)
Expand Down
2 changes: 1 addition & 1 deletion src/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ app.disable("x-powered-by");
app.use(express.static(path.resolve(Path.Public)));

const httpServer = createServer(app);
initSocket(httpServer);
await initSocket(httpServer);

initRoutes(app);

Expand Down
9 changes: 4 additions & 5 deletions src/server/services/socket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@ import { GREETINGS, SocketEvent } from "@constants";
import { Config } from "@helpers";
import { log } from "@services";

export const initSocket = (httpServer: HttpServer) => {
export const initSocket = async (httpServer: HttpServer) => {
const io = new Server(httpServer);

(async () => {
if (Config.IS_PROD) return;
if (!Config.IS_PROD) {
const { initWatch } = await import("@processes");
const emitReload = () => io.emit(SocketEvent.Reload);
await initWatch(emitReload);
})();
initWatch(emitReload);
}

io.on("connect", socket => {
socket.on(SocketEvent.Hello, (message: string) => {
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"allowImportingTsExtensions": true,
"resolveJsonModule": true,
"allowJs": true,
"checkJs": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"forceConsistentCasingInFileNames": true,
Expand All @@ -35,5 +36,5 @@
"@utils": ["./src/client/utils"]
}
},
"include": ["./**/*.ts", "./**/*.tsx", "./**/*.json"]
"include": ["./**/*.ts", "./**/*.tsx", "./**/*.js", "./**/*.jsx", "./**/*.json"]
}

0 comments on commit 2612bb6

Please sign in to comment.