Skip to content

Commit 0731955

Browse files
committed
chore: experiment with biomejs
1 parent 0f4697a commit 0731955

File tree

19 files changed

+454
-916
lines changed

19 files changed

+454
-916
lines changed

biome.codegen.json

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
{
2+
"$schema": "https://biomejs.dev/schemas/2.0.0/schema.json",
3+
"files": {
4+
"maxSize": 16000000,
5+
"includes": [
6+
"**/*.{mjs|js}",
7+
"**/*.ts",
8+
"**/*.json"
9+
]
10+
},
11+
"formatter": {
12+
"enabled": true,
13+
"indentStyle": "space",
14+
"lineWidth": 120,
15+
"indentWidth": 2,
16+
"lineEnding": "lf",
17+
"bracketSpacing": true,
18+
"bracketSameLine": false
19+
},
20+
"assist": {
21+
"enabled": true,
22+
"actions": {
23+
"source": {
24+
"organizeImports": "on"
25+
}
26+
}
27+
},
28+
"linter": {
29+
"rules": {
30+
"recommended": true,
31+
"complexity": {
32+
"noForEach": "off"
33+
},
34+
"correctness": {
35+
"noUndeclaredVariables": "off",
36+
"noUnusedVariables": "off",
37+
"noInvalidBuiltinInstantiation": "error"
38+
},
39+
"style": {
40+
"noNamespace": "error",
41+
"useConsistentArrayType": {
42+
"level": "off",
43+
"options": {
44+
"syntax": "shorthand"
45+
}
46+
},
47+
"noParameterAssign": "off",
48+
"useAsConstAssertion": "off",
49+
"useDefaultParameterLast": "off",
50+
"useEnumInitializers": "error",
51+
"useSingleVarDeclarator": "off",
52+
"noUnusedTemplateLiteral": "off",
53+
"useNumberNamespace": "off",
54+
"noInferrableTypes": "off",
55+
"noUselessElse": "off"
56+
},
57+
"nursery": {
58+
"useIterableCallbackReturn": "off"
59+
},
60+
"suspicious": {
61+
"noEmptyBlockStatements": "off",
62+
"noExplicitAny": "off",
63+
"noImplicitAnyLet": "off",
64+
"noEmptyBlock": "off",
65+
"noEmptyInterface": "off",
66+
"noAssignInExpressions": "off",
67+
"noSparseArray": "off"
68+
}
69+
}
70+
},
71+
"javascript": {
72+
"formatter": {
73+
"trailingCommas": "es5"
74+
}
75+
},
76+
"vcs": {
77+
"enabled": true,
78+
"clientKind": "git",
79+
"useIgnoreFile": true
80+
}
81+
}

biome.json

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
{
2+
"$schema": "https://biomejs.dev/schemas/2.0.0/schema.json",
3+
"files": {
4+
"maxSize": 16000000,
5+
"includes": [
6+
"**/*.{mjs|js}",
7+
"**/*.ts",
8+
"**/*.json"
9+
]
10+
},
11+
"formatter": {
12+
"enabled": true,
13+
"indentStyle": "space",
14+
"lineWidth": 120,
15+
"indentWidth": 2,
16+
"lineEnding": "lf",
17+
"bracketSpacing": true,
18+
"bracketSameLine": false
19+
},
20+
"assist": {
21+
"enabled": true,
22+
"actions": {
23+
"source": {
24+
"organizeImports": "on"
25+
}
26+
}
27+
},
28+
"linter": {
29+
"rules": {
30+
"recommended": true,
31+
"complexity": {
32+
"noForEach": "off"
33+
},
34+
"correctness": {
35+
"noUndeclaredVariables": "off",
36+
"noUnusedVariables": "info",
37+
"noInvalidBuiltinInstantiation": "error",
38+
"noSwitchDeclarations": "info"
39+
},
40+
"style": {
41+
"noNamespace": "error",
42+
"useConsistentArrayType": {
43+
"level": "info",
44+
"options": {
45+
"syntax": "shorthand"
46+
}
47+
},
48+
"noParameterAssign": "info",
49+
"useAsConstAssertion": "info",
50+
"useDefaultParameterLast": "info",
51+
"useEnumInitializers": "error",
52+
"useSingleVarDeclarator": "error",
53+
"noUnusedTemplateLiteral": "info",
54+
"useNumberNamespace": "info",
55+
"noInferrableTypes": "info",
56+
"noUselessElse": "info"
57+
},
58+
"nursery": {
59+
"useIterableCallbackReturn": "off"
60+
},
61+
"suspicious": {
62+
"noEmptyBlockStatements": "info",
63+
"noExplicitAny": "info",
64+
"noImplicitAnyLet": "info",
65+
"noEmptyBlock": "info",
66+
"noEmptyInterface": "info",
67+
"noAssignInExpressions": "info",
68+
"noSparseArray": "info",
69+
"noShadowRestrictedNames": "info"
70+
}
71+
}
72+
},
73+
"javascript": {
74+
"formatter": {
75+
"trailingCommas": "es5"
76+
}
77+
},
78+
"vcs": {
79+
"enabled": true,
80+
"clientKind": "git",
81+
"useIgnoreFile": true
82+
}
83+
}

package.json

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,9 @@
2929
"generate:clients:generic": "node ./scripts/generate-clients/generic",
3030
"generate:defaults-mode-provider": "./scripts/generate-defaults-mode-provider/index.js",
3131
"lerna:version": "lerna version --exact --conventional-commits --no-push --no-git-tag-version --no-commit-hooks --loglevel silent --yes",
32-
"lint:ci": "lerna exec --since origin/main --exclude-dependents --ignore '@aws-sdk/client-*' --ignore '@aws-sdk/aws-*' 'eslint --quiet src/**/*.ts'",
33-
"lint:release": "lerna exec --ignore '@aws-sdk/client-*' --ignore '@aws-sdk/aws-*' 'eslint --quiet src/**/*.ts'",
32+
"lint": "node scripts/biome/run-biome.mjs",
33+
"lint:ci": "node scripts/biome/run-biome.mjs",
34+
"lint:release": "node scripts/biome/run-biome.mjs",
3435
"lint:versions": "node scripts/runtime-dependency-version-check/runtime-dep-version-check.js",
3536
"lint:dependencies": "node scripts/runtime-dependency-version-check/check-dependencies.js",
3637
"local-publish": "node ./scripts/verdaccio-publish/index.js",
@@ -62,30 +63,24 @@
6263
},
6364
"license": "UNLICENSED",
6465
"devDependencies": {
66+
"@biomejs/biome": "2.0.0",
67+
"@biomejs/js-api": "1.0.0",
68+
"@biomejs/wasm-nodejs": "2.0.0",
6569
"@commitlint/cli": "17.0.2",
6670
"@commitlint/config-conventional": "17.0.2",
6771
"@cucumber/cucumber": "8.5.3",
6872
"@cucumber/pretty-formatter": "^1.0.0",
6973
"@fastify/formbody": "^7.4.0",
7074
"@microsoft/api-extractor": "7.52.7",
71-
"@mixer/parallel-prettier": "2.0.3",
7275
"@tsconfig/recommended": "1.0.1",
7376
"@types/fs-extra": "^8.0.1",
7477
"@types/jest": "29.5.11",
7578
"@types/jsdom": "20.0.1",
76-
"@typescript-eslint/eslint-plugin": "5.55.0",
77-
"@typescript-eslint/parser": "5.55.0",
7879
"async": "3.2.4",
7980
"concurrently": "7.0.0",
8081
"decomment": "0.9.5",
8182
"downlevel-dts": "0.10.1",
8283
"esbuild": "0.25.0",
83-
"eslint": "8.36.0",
84-
"eslint-config-prettier": "8.5.0",
85-
"eslint-plugin-prettier": "4.0.0",
86-
"eslint-plugin-simple-import-sort": "7.0.0",
87-
"eslint-plugin-sort-export-all": "1.2.2",
88-
"eslint-plugin-tsdoc": "0.2.17",
8984
"esprint": "3.6.0",
9085
"fastify": "^4.11.0",
9186
"figlet": "^1.5.0",
@@ -100,7 +95,6 @@
10095
"kill-port": "^2.0.1",
10196
"lerna": "5.5.2",
10297
"lint-staged": "^10.0.1",
103-
"prettier": "2.8.5",
10498
"rimraf": "3.0.2",
10599
"ts-jest": "29.1.1",
106100
"ts-loader": "9.4.2",
@@ -135,10 +129,9 @@
135129
},
136130
"lint-staged": {
137131
"{lib,packages}/**/src/**/*.ts": [
138-
"eslint --fix",
139-
"prettier --write"
132+
"echo yarn @biomejs/biome check --write"
140133
],
141-
"**/*.{ts,js,md,json}": "prettier --write"
134+
"**/*.{ts,js,md,json}": "echo yarn @biomejs/biome check --write"
142135
},
143136
"packageManager": "[email protected]"
144137
}

scripts/benchmark-size/runner/calculate-size/generate-project.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { execa as exec } from "execa";
22
import { promises as fsPromise } from "fs";
33
import { join } from "path";
4-
import prettier from "prettier";
54

65
import { PackageContext } from "../load-test-scope";
76
import type { PackageSizeReportOptions } from "./index";
@@ -14,9 +13,9 @@ export const generateProject = async (projectDir: string, options: PackageSizeRe
1413
};
1514
for (const [name, template] of Object.entries(options.templates)) {
1615
const filePath = join(projectDir, name);
17-
const file = prettier.format(template(contextWithPeerDep), {
18-
filepath: filePath,
19-
});
16+
const { formatCode } = await import("../../../biome/biome.mjs");
17+
const file = await formatCode(template(contextWithPeerDep), filePath);
18+
2019
await fsPromise.writeFile(filePath, file);
2120
}
2221

scripts/biome/biome.mjs

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
import { dirname, join } from "node:path";
2+
import { promises, readFileSync } from "node:fs";
3+
import { fileURLToPath } from "node:url";
4+
import { Biome, Distribution } from "@biomejs/js-api";
5+
import walk from "../utils/walk.js";
6+
7+
const __dirname = dirname(fileURLToPath(import.meta.url));
8+
9+
async function loadBiomeWithConfig(biomeConfigPath) {
10+
const biome = await Biome.create({
11+
distribution: Distribution.NODE,
12+
});
13+
const config = JSON.parse(readFileSync(biomeConfigPath, "utf-8"));
14+
const { projectKey } = biome.openProject(biomeConfigPath);
15+
biome.applyConfiguration(projectKey, config);
16+
return {
17+
biome,
18+
projectKey,
19+
};
20+
}
21+
22+
const coreInstance = await loadBiomeWithConfig(join(__dirname, "..", "..", "biome.json"));
23+
const codegenInstance = await loadBiomeWithConfig(join(__dirname, "..", "..", "biome.codegen.json"));
24+
25+
const skip = /browser-build|node_modules|dist-(es|cjs|types)|ruleset\.ts$|endpoints-ruleset\/temp/;
26+
const match = /\.(m?js|ts|json)$/;
27+
28+
export async function checkDir(dir, { lint = false, codegen = false } = {}) {
29+
const concurrency = [];
30+
31+
for await (const file of walk(dir, ["node_modules"])) {
32+
if (file.match(skip)) {
33+
continue;
34+
}
35+
if (file.match(match)) {
36+
concurrency.push(
37+
promises
38+
.readFile(file, "utf-8")
39+
.then((contents) => {
40+
const formatted = formatCode(contents, file, { codegen });
41+
if (formatted) {
42+
if (lint) {
43+
const linted = lintCode(formatted, file, { codegen });
44+
return promises.writeFile(file, linted, "utf-8");
45+
} else {
46+
return promises.writeFile(file, formatted, "utf-8");
47+
}
48+
}
49+
return Promise.resolve();
50+
})
51+
.catch(console.error)
52+
);
53+
}
54+
}
55+
56+
await Promise.all(concurrency);
57+
}
58+
59+
export function formatCode(code, filePath, { codegen } = {}) {
60+
const { biome, projectKey } = codegen ? codegenInstance : coreInstance;
61+
const format = biome.formatContent(projectKey, code, {
62+
filePath,
63+
});
64+
return format.content;
65+
}
66+
67+
export function lintCode(code, filePath, { codegen } = {}) {
68+
const { biome, projectKey } = codegen ? codegenInstance : coreInstance;
69+
const lint = biome.lintContent(projectKey, code, {
70+
filePath,
71+
});
72+
for (const diagnostic of lint.diagnostics) {
73+
if (diagnostic.severity === "error" || diagnostic.severity === "fatal") {
74+
const { category, severity, description, location } = diagnostic;
75+
console.log(`${category} - ${severity}\n\t${description}`);
76+
console.log(`\t\t${location.path.file.split("aws-sdk-js-v3")[1]}:${location.span.join(":")}`);
77+
}
78+
}
79+
return lint.content;
80+
}

scripts/biome/run-biome.mjs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { dirname, join } from "node:path";
2+
import { fileURLToPath } from "node:url";
3+
import { checkDir } from "./biome.mjs";
4+
5+
const __dirname = dirname(fileURLToPath(import.meta.url));
6+
7+
const timings = {};
8+
const formatTime = (ms) => {
9+
return (ms / 1000).toFixed(2) + "s";
10+
};
11+
12+
timings.start = performance.now();
13+
console.log("formatting and linting scripts/lib/packages");
14+
await checkDir(join(__dirname, "..", "..", "scripts"), { lint: true });
15+
await checkDir(join(__dirname, "..", "..", "lib"), { lint: true });
16+
await checkDir(join(__dirname, "..", "..", "packages"), { lint: true });
17+
timings.lintCore = performance.now();
18+
console.log("\t", formatTime(timings.lintCore - timings.start));
19+
20+
console.log("linting sample clients (s3/dynamodb)");
21+
await checkDir(join(__dirname, "..", "..", "clients", "client-s3"), { lint: true, codegen: true });
22+
await checkDir(join(__dirname, "..", "..", "clients", "client-dynamodb"), { lint: true, codegen: true });
23+
timings.lintSampleClients = performance.now();
24+
console.log("\t", formatTime(timings.lintSampleClients - timings.lintCore));
25+
26+
console.log("formatting all clients");
27+
await checkDir(join(__dirname, "..", "..", "clients"), { lint: false, codegen: true });
28+
timings.formatClients = performance.now();
29+
console.log("\t", formatTime(timings.formatClients - timings.lintSampleClients));
30+
31+
console.log("formatting all private packages");
32+
await checkDir(join(__dirname, "..", "..", "private"), { lint: false, codegen: true });
33+
timings.formatPrivate = performance.now();
34+
console.log("\t", formatTime(timings.formatPrivate - timings.formatClients));

scripts/downlevel-dts/downlevelWorkspace.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { exec } from "child_process";
33
import decomment from "decomment";
44
import { access, readFile, writeFile } from "fs/promises";
55
import { join } from "path";
6-
import prettier from "prettier";
76
import { promisify } from "util";
87

98
import { getAllFiles } from "./getAllFiles.mjs";
@@ -42,7 +41,8 @@ export const downlevelWorkspace = async (workspacesDir, workspaceName) => {
4241
const content = await readFile(downlevelTypesFilepath, "utf8");
4342
const decommentedContent = decomment(content);
4443
try {
45-
const formatted = prettier.format(decommentedContent, { parser: "typescript" });
44+
const { formatCode } = await import("../biome/biome.mjs");
45+
const formatted = await formatCode(decommentedContent, downlevelTypesFilepath);
4646
await writeFile(downlevelTypesFilepath, formatted);
4747
} catch (error) {
4848
console.warn(`Failed to format "${downlevelTypesFilepath}". Skipping...`);

0 commit comments

Comments
 (0)