Skip to content

Commit 2e5f42c

Browse files
committed
Add biome for lint and format
1 parent e01be7e commit 2e5f42c

File tree

46 files changed

+173
-104
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+173
-104
lines changed

.prettierrc

Lines changed: 0 additions & 6 deletions
This file was deleted.

biome.json

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"$schema": "https://biomejs.dev/schemas/1.9.3/schema.json",
3+
"vcs": { "enabled": false, "clientKind": "git", "useIgnoreFile": false },
4+
"files": { "ignoreUnknown": false, "ignore": ["dist/*"] },
5+
"formatter": {
6+
"enabled": true,
7+
"useEditorconfig": true,
8+
"formatWithErrors": false,
9+
"indentStyle": "space",
10+
"indentWidth": 2,
11+
"lineEnding": "lf",
12+
"lineWidth": 120,
13+
"attributePosition": "auto",
14+
"bracketSpacing": true
15+
},
16+
"organizeImports": { "enabled": true },
17+
"linter": { "enabled": true, "rules": { "recommended": true } },
18+
"javascript": {
19+
"formatter": {
20+
"jsxQuoteStyle": "double",
21+
"quoteProperties": "asNeeded",
22+
"trailingCommas": "all",
23+
"semicolons": "always",
24+
"arrowParentheses": "always",
25+
"bracketSameLine": false,
26+
"quoteStyle": "single",
27+
"attributePosition": "auto",
28+
"bracketSpacing": true
29+
}
30+
}
31+
}

package.json

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@
66
"scripts": {
77
"build": "rollup --config rollup.config.mjs",
88
"test": "vitest run ./test/src/**/*.test.ts",
9-
"lint": "prettier --check \"{packages,test}/**/*.{js,ts}\"",
10-
"fix": "prettier --write \"{packages,test}/**/*.{js,ts}\""
9+
"lint": "biome check",
10+
"fix": "biome check --write"
1111
},
1212
"devDependencies": {
13-
"@rollup/plugin-typescript": "^12.1.0",
13+
"@biomejs/biome": "1.9.3",
1414
"@rollup/plugin-node-resolve": "^15.3.0",
15+
"@rollup/plugin-typescript": "^12.1.0",
1516
"@rspack/cli": "^1.0.8",
1617
"@rspack/core": "^1.0.8",
1718
"@types/node": "^20.0.0",
1819
"esbuild": "^0.24.0",
19-
"prettier": "^3.3.3",
2020
"parcel": "^2.12.0",
2121
"rolldown": "^0.13.2",
2222
"rollup": "^4.22.5",
@@ -26,10 +26,7 @@
2626
"webpack": "^5.95.0",
2727
"webpack-cli": "^5.1.4"
2828
},
29-
"workspaces": [
30-
"packages/*",
31-
"test"
32-
],
29+
"workspaces": ["packages/*", "test"],
3330
"volta": {
3431
"node": "20.18.0",
3532
"yarn": "1.22.22"

packages/cli/src/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { readFile, writeFile } from 'fs/promises';
2-
import { addDebugIdToSource, stringToUUID, addDebugIdToSourcemap, walk, DEFAULT_EXTENSIONS } from '@debugids/common';
1+
import { readFile, writeFile } from 'node:fs/promises';
2+
import { DEFAULT_EXTENSIONS, addDebugIdToSource, addDebugIdToSourcemap, stringToUUID, walk } from '@debugids/common';
33

44
async function groupSourceAndMapFiles(files: string[]): Promise<Array<[string, string | undefined]>> {
55
const sourceFiles = files.filter((f) => !f.endsWith('.map'));
@@ -21,8 +21,8 @@ async function groupSourceAndMapFiles(files: string[]): Promise<Array<[string, s
2121
const extensions = [...DEFAULT_EXTENSIONS, ...DEFAULT_EXTENSIONS.map((e) => `${e}.map`)];
2222
const results = await walk(process.argv[2], extensions);
2323
const groupedResults = await groupSourceAndMapFiles(results);
24-
let modifiedFiles: Array<{ source: string; map: string; debugId: string }> = [];
25-
let missingMaps = new Set<string>();
24+
const modifiedFiles: Array<{ source: string; map: string; debugId: string }> = [];
25+
const missingMaps = new Set<string>();
2626
let addedDebugIds = 0;
2727

2828
const promises = groupedResults.map(async ([source, map]) => {

packages/common/src/index.ts

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import * as crypto from 'crypto';
2-
import { opendir } from 'fs/promises';
3-
import { join } from 'path';
1+
import * as crypto from 'node:crypto';
2+
import { opendir } from 'node:fs/promises';
3+
import { join } from 'node:path';
44

55
export const DEFAULT_EXTENSIONS = ['.js', '.mjs', '.cjs'];
66

@@ -13,18 +13,7 @@ export function stringToUUID(str: string): string {
1313
// RFC 4122 section 4.4
1414
const v4variant = ['8', '9', 'a', 'b'][md5Hash.substring(16, 17).charCodeAt(0) % 4] as string;
1515

16-
return (
17-
md5Hash.substring(0, 8) +
18-
'-' +
19-
md5Hash.substring(8, 12) +
20-
'-4' +
21-
md5Hash.substring(13, 16) +
22-
'-' +
23-
v4variant +
24-
md5Hash.substring(17, 20) +
25-
'-' +
26-
md5Hash.substring(20)
27-
).toLowerCase();
16+
return `${md5Hash.substring(0, 8)}-${md5Hash.substring(8, 12)}-4${md5Hash.substring(13, 16)}-${v4variant}${md5Hash.substring(17, 20)}-${md5Hash.substring(20)}`.toLowerCase();
2817
}
2918

3019
export function addDebugIdToSource(input: string, debugId: string): string {
@@ -45,7 +34,7 @@ export function getDebugIdFromString(input: string): string | undefined {
4534
}
4635

4736
export async function walk(path: string, extensions: string[]): Promise<string[]> {
48-
let files = [];
37+
const files = [];
4938

5039
for await (const file of await opendir(path)) {
5140
if (file.isDirectory()) {

packages/esbuild/src/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
import { readFile, writeFile } from 'node:fs/promises';
2+
import * as path from 'node:path';
3+
import { DEFAULT_EXTENSIONS, addDebugIdToSource, addDebugIdToSourcemap, stringToUUID } from '@debugids/common';
14
import type { PluginBuild } from 'esbuild';
2-
import { addDebugIdToSource, DEFAULT_EXTENSIONS, stringToUUID, addDebugIdToSourcemap } from '@debugids/common';
3-
import { readFile, writeFile } from 'fs/promises';
4-
import * as path from 'path';
55

66
export default {
77
name: 'esbuild-plugin-debug-ids',

packages/node/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as fs from 'fs/promises';
1+
import * as fs from 'node:fs/promises';
22
import { getDebugIdFromString } from '@debugids/common';
33

44
async function getLastBytesFromFile(path: string, bytesToRead = 1024) {

packages/parcel/src/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
import { addDebugIdToSource, stringToUUID } from '@debugids/common';
12
import { Optimizer } from '@parcel/plugin';
2-
import { stringToUUID, addDebugIdToSource } from '@debugids/common';
33

44
export default new Optimizer({
55
async optimize({ contents, map }) {
@@ -15,12 +15,13 @@ export default new Optimizer({
1515
// the only way I could find to add the debugId to the sourcemap is to proxy
1616
// the map 'toVLQ()' method to add the debugId to the sourcemap object...
1717
const proxiedMap = new Proxy(map, {
18-
get: function (target, prop, receiver) {
18+
get: (target, prop, receiver) => {
1919
if (prop === 'toVLQ') {
2020
const original = Reflect.get(target, prop, receiver);
2121

2222
return function toVLQ(this: unknown) {
2323
const result = original.apply(this);
24+
// biome-ignore lint/suspicious/noExplicitAny: We're adding a debugId to the sourcemap
2425
(result as any).debugId = debugId;
2526
return result;
2627
};

packages/rollup/src/index.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
import { TextDecoder } from 'node:util';
2+
import { DEFAULT_EXTENSIONS, addDebugIdToSource, addDebugIdToSourcemap, stringToUUID } from '@debugids/common';
13
import type { OutputAsset, OutputChunk, Plugin } from 'rollup';
2-
import { addDebugIdToSourcemap, addDebugIdToSource, stringToUUID, DEFAULT_EXTENSIONS } from '@debugids/common';
3-
import { TextDecoder } from 'util';
44

55
function getString(input: string | Uint8Array): string {
66
if (typeof input === 'string') {
@@ -13,7 +13,7 @@ function getString(input: string | Uint8Array): string {
1313
export default function debugIds(): Plugin {
1414
return {
1515
name: 'rollup-plugin-debug-ids',
16-
generateBundle: function (_, bundle: { [fileName: string]: OutputAsset | OutputChunk }) {
16+
generateBundle: (_, bundle: { [fileName: string]: OutputAsset | OutputChunk }) => {
1717
for (const [key, value] of Object.entries(bundle)) {
1818
// We only add debugId where there is a linked sourcemap file
1919
if (!('sourcemapFileName' in value) || !value.sourcemapFileName) {
@@ -38,8 +38,9 @@ export default function debugIds(): Plugin {
3838
// vite has a plugin that runs after us which can modify the sourcemap so we
3939
// proxy the sourceMapFile to re-add the debugId if the source gets set again
4040
bundle[value.sourcemapFileName] = new Proxy(bundle[value.sourcemapFileName] as OutputAsset, {
41-
set: function <K extends keyof OutputAsset>(target: OutputAsset, prop: K, value: OutputAsset[K]) {
41+
set: <K extends keyof OutputAsset>(target: OutputAsset, prop: K, value: OutputAsset[K]) => {
4242
if (prop === 'source') {
43+
// biome-ignore lint/suspicious/noExplicitAny: Can't get types to work here
4344
(target as any)[prop] = addDebugIdToSourcemap(getString(value as string | Uint8Array), debugId);
4445
} else {
4546
target[prop] = value;

packages/webpack/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
import { DEFAULT_EXTENSIONS, addDebugIdToSource, addDebugIdToSourcemap, stringToUUID } from '@debugids/common';
12
import type { Compiler } from 'webpack';
2-
import { DEFAULT_EXTENSIONS, addDebugIdToSource, stringToUUID, addDebugIdToSourcemap } from '@debugids/common';
33

44
const PLUGIN_NAME = 'DebugIdWebpackPlugin';
55

0 commit comments

Comments
 (0)