Skip to content
This repository has been archived by the owner on Jun 24, 2024. It is now read-only.

Commit

Permalink
refactor: replace prettier/eslint with biome
Browse files Browse the repository at this point in the history
a

update biome
  • Loading branch information
Vahor committed Apr 20, 2024
1 parent 83791e0 commit f877071
Show file tree
Hide file tree
Showing 174 changed files with 4,932 additions and 6,514 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/code-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ jobs:
- name: Install deps
run: pnpm install --frozen-lockfile --prefer-offline

- name: Run eslint
- name: Run lint
run: pnpm lint

- name: Run prettier
- name: Run format check
run: pnpm format:check

- name: Run typescript
Expand Down
32 changes: 32 additions & 0 deletions biome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"$schema": "https://biomejs.dev/schemas/1.7.0/schema.json",
"organizeImports": {
"enabled": true
},
"linter": {
"enabled": true,
"rules": {
"recommended": true,
"style": {
"noNonNullAssertion": "off",
"useSelfClosingElements": "off"
},
"a11y": {
"noSvgWithoutTitle": "off"
}
}
},
"vcs": {
"enabled": true,
"clientKind": "git",
"useIgnoreFile": true
},
"files": {
"ignore": [
"./dist/**",
"./node_modules/**",
"./.next/**",
"./.react-email/**"
]
}
}
8 changes: 2 additions & 6 deletions docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,5 @@
},
"dependencies": {
"mintlify": "latest"
},
"devDependencies": {
"@pedaki/prettier-config": "0.5.3"
},
"prettier": "@pedaki/prettier-config"
}
}
}
9 changes: 2 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"publish-release": "node --no-warnings=ExperimentalWarning scripts/publish-release.mjs"
},
"devDependencies": {
"@biomejs/biome": "^1.7.0",
"@manypkg/get-packages": "^2.2.1",
"@types/fs-extra": "^11.0.4",
"@types/node": "^20.12.7",
Expand All @@ -52,17 +53,11 @@
"typescript": "5.4.5",
"vitest": "^1.5.0"
},
"lint-staged": {
"*.{js,jsx,ts,tsx}": [
"prettier --write",
"eslint --fix"
]
},
"engines": {
"node": "^18 || ^20",
"pnpm": ">=8.0.0",
"yarn": "use-pnpm",
"npm": "use-pnpm"
},
"packageManager": "pnpm@9.0.4"
}
}
2 changes: 0 additions & 2 deletions packages/common/.eslintignore

This file was deleted.

7 changes: 0 additions & 7 deletions packages/common/.eslintrc.cjs

This file was deleted.

4 changes: 0 additions & 4 deletions packages/common/.prettierignore

This file was deleted.

85 changes: 41 additions & 44 deletions packages/common/package.json
Original file line number Diff line number Diff line change
@@ -1,45 +1,42 @@
{
"name": "@pedaki/common",
"version": "0.5.3",
"author": "Nathan David <me@vahor.fr>",
"repository": {
"type": "git",
"url": "https://github.com/PedakiHQ/pedaki",
"directory": "packages/common"
},
"homepage": "https://www.pedaki.fr",
"license": "CC-BY-NC-SA-4.0",
"private": false,
"type": "module",
"publishConfig": {
"directory": "dist"
},
"scripts": {
"build": "tsup",
"lint": "eslint .",
"typecheck": "tsc --noEmit",
"format": "prettier --write .",
"format:check": "prettier --check ."
},
"devDependencies": {
"@pedaki/eslint-config": "0.5.3",
"@pedaki/prettier-config": "0.5.3",
"@types/bcryptjs": "^2.4.6",
"@types/memory-cache": "latest",
"@types/react": "^18.2.79",
"react": "^18.2.0"
},
"peerDependencies": {
"bcryptjs": "^2.4.3",
"memory-cache": "^0.2.0",
"nanoid": "^5.0.0",
"sonner": "^1.0.0"
},
"engines": {
"node": "^18 || ^20",
"pnpm": ">=9.0.0",
"yarn": "use-pnpm",
"npm": "use-pnpm"
},
"prettier": "@pedaki/prettier-config"
}
"name": "@pedaki/common",
"version": "0.5.3",
"author": "Nathan David <me@vahor.fr>",
"repository": {
"type": "git",
"url": "https://github.com/PedakiHQ/pedaki",
"directory": "packages/common"
},
"homepage": "https://www.pedaki.fr",
"license": "CC-BY-NC-SA-4.0",
"private": false,
"type": "module",
"publishConfig": {
"directory": "dist"
},
"scripts": {
"build": "tsup",
"format": "pnpx @biomejs/biome format ./ --write",
"lint": "pnpx @biomejs/biome lint ./ --apply",
"format:check": "pnpx @biomejs/biome format ./",
"typecheck": "tsc --noEmit"
},
"devDependencies": {
"@types/bcryptjs": "^2.4.6",
"@types/memory-cache": "latest",
"@types/react": "^18.2.79",
"react": "^18.2.0"
},
"peerDependencies": {
"bcryptjs": "^2.4.3",
"memory-cache": "^0.2.0",
"nanoid": "^5.0.0",
"sonner": "^1.0.0"
},
"engines": {
"node": "^18 || ^20",
"pnpm": ">=9.0.0",
"yarn": "use-pnpm",
"npm": "use-pnpm"
}
}
168 changes: 87 additions & 81 deletions packages/common/src/cache/cache.test.ts
Original file line number Diff line number Diff line change
@@ -1,114 +1,120 @@
import { afterEach, beforeEach, describe, expect, test, vi } from 'vitest';
import { cache, getCache, isStale, revalidate, revalidateAll } from './cache.ts';
import { afterEach, beforeEach, describe, expect, test, vi } from "vitest";
import {
cache,
getCache,
isStale,
revalidate,
revalidateAll,
} from "./cache.ts";

describe('cache - memory', () => {
const value = 'test';
const asyncFn = () => Promise.resolve(value);
const syncFn = () => value;
const key = 'key';
const mock = vi.fn().mockImplementation(asyncFn);
describe("cache - memory", () => {
const value = "test";
const asyncFn = () => Promise.resolve(value);
const syncFn = () => value;
const key = "key";
const mock = vi.fn().mockImplementation(asyncFn);

beforeEach(() => {
revalidateAll();
});
beforeEach(() => {
revalidateAll();
});

afterEach(() => {
vi.restoreAllMocks();
});
afterEach(() => {
vi.restoreAllMocks();
});

test('cache a value (async)', async () => {
const result = await cache(asyncFn, key);
expect(result).toBe(value);
});
test("cache a value (async)", async () => {
const result = await cache(asyncFn, key);
expect(result).toBe(value);
});

test('cache a value (sync)', async () => {
const result = await cache(syncFn, key);
expect(result).toBe(value);
});
test("cache a value (sync)", async () => {
const result = await cache(syncFn, key);
expect(result).toBe(value);
});

describe('with ttl', () => {
test('without keepStale', async () => {
await cache(value, key, { ttl: 1000, keepStale: false });
describe("with ttl", () => {
test("without keepStale", async () => {
await cache(value, key, { ttl: 1000, keepStale: false });

let cached = await getCache(key);
expect(isStale(cached!, 1000)).toBe(false);
let cached = await getCache(key);
expect(isStale(cached!, 1000)).toBe(false);

vi.useFakeTimers();
vi.advanceTimersByTime(10000);
vi.useFakeTimers();
vi.advanceTimersByTime(10000);

cached = await getCache(key);
expect(cached).toBeNull();
});
cached = await getCache(key);
expect(cached).toBeNull();
});

test('with keepStale', async () => {
await cache(value, key, { ttl: 1000, keepStale: true });
test("with keepStale", async () => {
await cache(value, key, { ttl: 1000, keepStale: true });

let cached = await getCache(key);
expect(isStale(cached!, 1000)).toBe(false);
let cached = await getCache(key);
expect(isStale(cached!, 1000)).toBe(false);

vi.useFakeTimers();
vi.advanceTimersByTime(10000);
vi.useFakeTimers();
vi.advanceTimersByTime(10000);

cached = await getCache(key);
expect(cached).not.toBeNull();
cached = await getCache(key);
expect(cached).not.toBeNull();

expect(isStale(cached!, 1000)).toBe(true);
});
});
expect(isStale(cached!, 1000)).toBe(true);
});
});

describe('ignoreCache', () => {
test('without ignoreCache', async () => {
await cache(mock, key, { ignoreCache: false });
await cache(mock, key, { ignoreCache: false });
describe("ignoreCache", () => {
test("without ignoreCache", async () => {
await cache(mock, key, { ignoreCache: false });
await cache(mock, key, { ignoreCache: false });

expect(mock).toHaveBeenCalledTimes(1);
});
expect(mock).toHaveBeenCalledTimes(1);
});

test('with ignoreCache', async () => {
await cache(mock, key, { ignoreCache: true });
await cache(mock, key, { ignoreCache: true });
test("with ignoreCache", async () => {
await cache(mock, key, { ignoreCache: true });
await cache(mock, key, { ignoreCache: true });

expect(mock).toHaveBeenCalledTimes(2);
});
});
expect(mock).toHaveBeenCalledTimes(2);
});
});

describe('revalidate', () => {
test('revalidate a key', async () => {
await cache(mock, key);
await cache(mock, key);
describe("revalidate", () => {
test("revalidate a key", async () => {
await cache(mock, key);
await cache(mock, key);

expect(mock).toHaveBeenCalledTimes(1);
expect(mock).toHaveBeenCalledTimes(1);

const before = await getCache(key);
expect(before).not.toBeNull();
const before = await getCache(key);
expect(before).not.toBeNull();

revalidate(key);
revalidate(key);

const after = await getCache(key);
expect(after).toBeNull();
const after = await getCache(key);
expect(after).toBeNull();

await cache(mock, key);
await cache(mock, key);

expect(mock).toHaveBeenCalledTimes(2);
});
expect(mock).toHaveBeenCalledTimes(2);
});

test('revalidate all keys', async () => {
await cache(mock, key);
await cache(mock, key);
test("revalidate all keys", async () => {
await cache(mock, key);
await cache(mock, key);

expect(mock).toHaveBeenCalledTimes(1);
expect(mock).toHaveBeenCalledTimes(1);

const before = await getCache(key);
expect(before).not.toBeNull();
const before = await getCache(key);
expect(before).not.toBeNull();

revalidateAll();
revalidateAll();

const after = await getCache(key);
expect(after).toBeNull();
const after = await getCache(key);
expect(after).toBeNull();

await cache(mock, key);
await cache(mock, key);

expect(mock).toHaveBeenCalledTimes(2);
});
});
expect(mock).toHaveBeenCalledTimes(2);
});
});
});
Loading

0 comments on commit f877071

Please sign in to comment.