Skip to content

Commit

Permalink
chore: migrate from eslint to biome (#317)
Browse files Browse the repository at this point in the history
  • Loading branch information
ghoullier authored Mar 11, 2024
1 parent 1f44f01 commit 6bca19b
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 49 deletions.
21 changes: 13 additions & 8 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
{
"typescript.enablePromptUseWorkspaceTsdk": true,
"typescript.inlayHints.variableTypes.enabled": true,
"typescript.inlayHints.variableTypes.suppressWhenTypeMatchesName": true,
"typescript.inlayHints.parameterTypes.enabled": true,
"typescript.inlayHints.parameterNames.suppressWhenArgumentMatchesName": true,
"typescript.inlayHints.parameterNames.enabled": "all",
"typescript.preferences.preferTypeOnlyAutoImports": true,
"typescript.tsdk": "./node_modules/typescript/lib"
"editor.codeActionsOnSave": {
"source.organizeImports.biome": "explicit",
"quickfix.biome": "explicit"
},
"editor.defaultFormatter": "biomejs.biome",
"typescript.enablePromptUseWorkspaceTsdk": true,
"typescript.inlayHints.variableTypes.enabled": true,
"typescript.inlayHints.variableTypes.suppressWhenTypeMatchesName": true,
"typescript.inlayHints.parameterTypes.enabled": true,
"typescript.inlayHints.parameterNames.suppressWhenArgumentMatchesName": true,
"typescript.inlayHints.parameterNames.enabled": "all",
"typescript.preferences.preferTypeOnlyAutoImports": true,
"typescript.tsdk": "./node_modules/typescript/lib"
}
16 changes: 16 additions & 0 deletions biome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"$schema": "https://biomejs.dev/schemas/1.6.0/schema.json",
"organizeImports": {
"enabled": true
},
"linter": {
"enabled": true,
"rules": {
"recommended": true
}
},
"formatter": {
"formatWithErrors": true,
"indentStyle": "space"
}
}
Binary file modified bun.lockb
Binary file not shown.
35 changes: 4 additions & 31 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,11 @@
"build:types": "tsc -p tsconfig.build.json",
"build": "bun build:lib && bun build:types",
"lint": "npm run lint:lib && npm run lint:exports && npm run lint:package",
"lint:lib": "eslint --ext .ts src",
"lint:lib": "biome check src/*.ts",
"lint:exports": "attw --pack . --ignore-rules no-resolution cjs-resolves-to-esm",
"lint:package": "publint ."
},
"files": [
"dist",
"package.json"
],
"files": ["dist", "package.json"],
"exports": {
".": {
"types": "./dist/index.d.ts",
Expand All @@ -27,38 +24,14 @@
},
"devDependencies": {
"@arethetypeswrong/cli": "0.15.1",
"@biomejs/biome": "1.6.0",
"@tsconfig/strictest": "2.0.3",
"@types/bun": "^1.0.5",
"@typescript-eslint/eslint-plugin": "7.2.0",
"@typescript-eslint/parser": "7.2.0",
"@types/bun": "1.0.8",
"bun-types": "1.0.30",
"eslint": "8.57.0",
"publint": "0.2.7",
"typescript": "5.4.2"
},
"publishConfig": {
"registry": "https://npm.pkg.github.com"
},
"eslintConfig": {
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/strict-type-checked",
"plugin:@typescript-eslint/stylistic-type-checked"
],
"plugins": [
"@typescript-eslint"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": true,
"tsconfigRootDir": "."
},
"root": true,
"rules": {
"@typescript-eslint/no-empty-interface": "off",
"@typescript-eslint/explicit-function-return-type": [
"error"
]
}
}
}
6 changes: 3 additions & 3 deletions src/Option.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { expect, test, mock, describe } from "bun:test";
import { describe, expect, mock, test } from "bun:test";

import { Option } from "./Option.ts";

Expand Down Expand Up @@ -31,7 +31,7 @@ describe("Option", () => {
const mapper = mock((value) => `<div>${value}</div>`);
const html = some.map(mapper);
expect(html.isOk()).toBe(true);
expect(html.orElse(`fallback`)).toBe(`<div>content</div>`);
expect(html.orElse("fallback")).toBe("<div>content</div>");
expect(mapper).toHaveBeenCalledTimes(1);
});

Expand All @@ -40,7 +40,7 @@ describe("Option", () => {
const mapper = mock((value) => Option.Some(`<div>${value}</div>`));
const html = some.flatMap(mapper);
expect(html.isOk()).toBe(true);
expect(html.orElse(`<div>fallback</div>`)).toBe(`<div>content</div>`);
expect(html.orElse("<div>fallback</div>")).toBe("<div>content</div>");
expect(mapper).toHaveBeenCalledTimes(1);
});
});
3 changes: 2 additions & 1 deletion src/Option.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ interface Some<Value> {
value: Value;
}

interface None {}
// biome-ignore lint/complexity/noBannedTypes: <explanation>
type None = {};

type $Option<Value> = Some<Value> | None;

Expand Down
4 changes: 2 additions & 2 deletions src/Result.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import { Result } from "./Result.ts";

describe("Result", () => {
test("should map value without change the original reference", () => {
const content = Result.Ok(`content`);
const content = Result.Ok("content");
const html = content.map((value) => `<div>${value}</div>`);
expect(html.ok().orElse("fallback")).toBe("<div>content</div>");
});

test("should correctly render when apply toString()", () => {
const content = Result.Ok(`content`);
const content = Result.Ok("content");
const html = content.map((value) => `<div>${value}</div>`);
expect(html.toString()).toBe("Ok ( <div>content</div> )");
});
Expand Down
8 changes: 4 additions & 4 deletions src/Result.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ export class Result<const Value, const Error> extends Container<
$Result<Value, Error>
> {
static Ok<Value, Error>(value: Value): Result<Value, Error> {
return new this({ value });
return new Result({ value });
}
static Error<Value, Error>(error: Error): Result<Value, Error> {
return new this({ error });
return new Result({ error });
}
isError(): boolean {
return "error" in this.value;
Expand All @@ -42,7 +42,7 @@ export class Result<const Value, const Error> extends Container<
return Result.Ok(mapper((this.value as Success<Value>).value));
}
flatMap<Output>(
mapper: Mapper<Value, Result<Output, Error>>
mapper: Mapper<Value, Result<Output, Error>>,
): Result<Output, Error> {
if (this.isError()) {
return Result.Error((this.value as Failure<Error>).error);
Expand All @@ -51,7 +51,7 @@ export class Result<const Value, const Error> extends Container<
}
match<Output>(
resolve: Mapper<Value, Output>,
reject: Mapper<Error, Output>
reject: Mapper<Error, Output>,
): Output {
if (this.isError()) {
return reject((this.value as Failure<Error>).error);
Expand Down

0 comments on commit 6bca19b

Please sign in to comment.