Skip to content

Commit

Permalink
chore(dev-deps): Replace eslint+prettier with biome (#254)
Browse files Browse the repository at this point in the history
  • Loading branch information
frodeaa authored Sep 28, 2024
1 parent 754d54e commit 4556deb
Show file tree
Hide file tree
Showing 8 changed files with 1,260 additions and 2,403 deletions.
1 change: 0 additions & 1 deletion .prettierignore

This file was deleted.

8 changes: 0 additions & 8 deletions .prettierrc.yml

This file was deleted.

50 changes: 50 additions & 0 deletions biome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
"organizeImports": {
"enabled": false
},
"files": {
"include": ["**/*.ts", "**/*.txt", "**/*.md", "**/*.json", "**/*.xml"],
"ignore": [
"**/*.d.ts",
"**/.build",
"**/.reports",
"**/.vscode/**",
"**/dist",
"**/node_modules"
]
},
"linter": {
"enabled": true,
"rules": {
"recommended": true
}
},
"vcs": {
"enabled": true,
"clientKind": "git",
"useIgnoreFile": true
},
"formatter": {
"enabled": true,
"indentStyle": "space",
"lineWidth": 80,
"indentWidth": 4,
"formatWithErrors": false,
"ignore": []
},
"javascript": {
"formatter": {
"semicolons": "always",
"trailingCommas": "all",
"arrowParentheses": "always",
"bracketSameLine": false,
"bracketSpacing": true
}
},
"json": {
"formatter": {
"indentWidth": 4,
"trailingCommas": "none"
}
}
}
23 changes: 0 additions & 23 deletions eslint.config.mjs

This file was deleted.

23 changes: 6 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,13 @@
"description": "",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"files": [
"CHANGELOG.md",
"dist"
],
"files": ["CHANGELOG.md", "dist"],
"scripts": {
"test": "jest",
"clean": "rm -rf dist",
"check": "yarn -s run lint && yarn -s run test",
"build": "yarn -s run clean && yarn -s run check && tsc -p tsconfig.build.json",
"prettier": "prettier --config ./.prettierrc.yml --check --log-level warn --cache .",
"eslint": "eslint -c eslint.config.mjs",
"lint": "yarn -s prettier && yarn eslint",
"lint": "biome check --config-path ./biome.json",
"semantic-release": "semantic-release",
"prepublishOnly": "yarn run build"
},
Expand All @@ -33,26 +28,20 @@
"jest": {
"preset": "ts-jest",
"testEnvironment": "node",
"testMatch": [
"**/__tests__/**/*.test.ts"
]
"testMatch": ["**/__tests__/**/*.test.ts"]
},
"dependencies": {
"@types/big.js": "6.2.2",
"big.js": "^6.1.1",
"currency-codes": "^2.1.0"
},
"devDependencies": {
"@eslint/js": "9.11.0",
"@biomejs/biome": "1.9.2",
"@semantic-release/git": "10.0.1",
"@types/jest": "29.5.13",
"eslint": "9.11.1",
"eslint-config-prettier": "9.1.0",
"jest": "29.7.0",
"prettier": "3.3.3",
"semantic-release": "24.1.1",
"semantic-release": "24.1.2",
"ts-jest": "29.2.5",
"typescript": "5.6.2",
"typescript-eslint": "8.7.0"
"typescript": "5.6.2"
}
}
6 changes: 3 additions & 3 deletions src/__tests__/money.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ describe("money", () => {
});

describe("fromLocaleString", () => {
[
for (const { locale, currency, fromStr, toStr } of [
{
locale: "no-NB",
currency: "NOK",
Expand Down Expand Up @@ -291,7 +291,7 @@ describe("money", () => {
fromStr: "-$11,111 US dollars",
toStr: "-11111.00",
},
].forEach(({ locale, currency, fromStr, toStr }) => {
]) {
it(`should parse (${locale} ${currency}) ${fromStr}`, () => {
const result = Money.fromLocaleString(
fromStr,
Expand All @@ -300,7 +300,7 @@ describe("money", () => {
).toString();
expect(result).toBe(toStr);
});
});
}
});

it("should add vat", () => {
Expand Down
24 changes: 15 additions & 9 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ type Factor = number | Big;
type Tags = {
includesVat: boolean;
isVat: boolean;
// biome-ignore lint/suspicious/noExplicitAny: allow any
[key: string]: any;
};

Expand Down Expand Up @@ -128,11 +129,16 @@ export class Money {
const decimalSign =
parts.find((p) => p.type === "decimal")?.value ?? ".";

str = str
.replace(new RegExp(`[^-\\d${escapeRegex(decimalSign)}]`, "g"), "")
.replace(decimalSign, ".");

return Money.of(str, currency, options);
return Money.of(
str
.replace(
new RegExp(`[^-\\d${escapeRegex(decimalSign)}]`, "g"),
"",
)
.replace(decimalSign, "."),
currency,
options,
);
}

/**
Expand Down Expand Up @@ -201,10 +207,8 @@ export class Money {
);
}

currency = currency ?? moneys[0].currency();

if (moneys.length === 0) {
return Money.of(0, currency, options);
return Money.of(0, currency ?? moneys[0].currency(), options);
}

return moneys
Expand Down Expand Up @@ -266,6 +270,7 @@ export class Money {
return this._data.tags?.[tagName] ?? defaultValue;
};

// biome-ignore lint/suspicious/noExplicitAny: allow any
setTag = <Name extends keyof Tags>(tagName: Name, value: any): Money => {
return new Money({
...this._data,
Expand All @@ -275,8 +280,9 @@ export class Money {

assertTag = <Name extends keyof Tags>(
tagName: Name,
// biome-ignore lint/suspicious/noExplicitAny: allow any
value: any,
cmp = (actual: any, value: any) => actual === value,
cmp = (actual: unknown, value: unknown) => actual === value,
): Money => {
const actualValue = this.getTag(tagName, undefined);
if (!cmp(actualValue, value)) {
Expand Down
Loading

0 comments on commit 4556deb

Please sign in to comment.