Skip to content

Commit 24bd5e0

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

File tree

16 files changed

+296
-894
lines changed

16 files changed

+296
-894
lines changed

biome.json

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

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: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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+
const biome = await Biome.create({
10+
distribution: Distribution.NODE,
11+
});
12+
13+
const biomeConfigPath = join(__dirname, "..", "..", "biome.json");
14+
const config = JSON.parse(readFileSync(biomeConfigPath, "utf-8"));
15+
16+
const { projectKey } = biome.openProject(biomeConfigPath);
17+
biome.applyConfiguration(projectKey, config);
18+
19+
export async function formatDir(dir) {
20+
const concurrency = [];
21+
22+
for await (const file of walk(dir, ["node_modules"])) {
23+
concurrency.push(
24+
promises.readFile(file, "utf-8").then((contents) => {
25+
const format = formatCode(contents, file);
26+
if (format) {
27+
return promises.writeFile(file, format, "utf-8");
28+
}
29+
})
30+
);
31+
}
32+
33+
await Promise.all(concurrency);
34+
}
35+
36+
export function formatCode(code, filePath) {
37+
const format = biome.formatContent(projectKey, code, {
38+
filePath,
39+
});
40+
41+
const lint = biome.lintContent(projectKey, format.content, {
42+
filePath,
43+
});
44+
45+
for (const diagnostic of lint.diagnostics) {
46+
if (diagnostic.severity === "error" || diagnostic.severity === "fatal") {
47+
const { category, severity, description, location } = diagnostic;
48+
console.log(`${category} - ${severity}\n\t${description}`);
49+
console.log(`\t\t${location.path.file.split("aws-sdk-js-v3")[1]}:${location.span.join(":")}`);
50+
}
51+
}
52+
53+
return format.content;
54+
}

scripts/biome/run-biome.mjs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { dirname, join } from "node:path";
2+
import { fileURLToPath } from "node:url";
3+
import { formatDir } from "./biome.mjs";
4+
5+
const __dirname = dirname(fileURLToPath(import.meta.url));
6+
7+
await formatDir(join(__dirname));
8+
await formatDir(join(__dirname, "..", "..", "packages", "middleware-sdk-s3"));

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...`);

scripts/generate-clients/code-eslint-fix.js

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

scripts/generate-clients/code-prettify.js

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,6 @@
1-
// @ts-check
2-
const { spawnProcess } = require("../utils/spawn-process");
3-
const path = require("path");
4-
51
const prettifyCode = async (dir) => {
6-
await spawnProcess(path.join(__dirname, "..", "..", "node_modules", ".bin", "pprettier"), [
7-
"--write",
8-
`${dir}/*/typescript-codegen/**/*.{ts,js,md,json}`,
9-
]);
10-
await spawnProcess(path.join(__dirname, "..", "..", "node_modules", ".bin", "pprettier"), [
11-
"--write",
12-
`${dir}/*/typescript-ssdk-codegen/**/*.{ts,js,md,json}`,
13-
]);
2+
const { formatDir } = await import("../biome/biome.mjs");
3+
await formatDir(dir);
144
};
155

166
module.exports = {

scripts/generate-clients/copy-to-clients.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// @ts-check
22
const { join } = require("path");
33
const { copySync, removeSync } = require("fs-extra");
4-
const prettier = require("prettier");
54
const semver = require("semver");
65
const { readdirSync, lstatSync, readFileSync, existsSync, writeFileSync } = require("fs");
76

@@ -178,7 +177,7 @@ const copyToClients = async (sourceDir, destinationDir, solo) => {
178177
] = `node ../../scripts/generate-clients/single-service --solo ${serviceName}`;
179178
}
180179

181-
writeFileSync(destSubPath, prettier.format(JSON.stringify(mergedManifest), { parser: "json-stringify" }));
180+
writeFileSync(destSubPath, JSON.stringify(mergedManifest, null, 2));
182181
} else if (packageSub === "typedoc.json") {
183182
// Skip writing typedoc.json
184183
// ToDo: Remove if typedoc.json is config driven or removed in smithy-typescript.
@@ -235,7 +234,7 @@ const copyServerTests = async (sourceDir, destinationDir) => {
235234
// don't generate documentation for private packages
236235
delete mergedManifest.scripts["build:docs"];
237236
}
238-
writeFileSync(destSubPath, prettier.format(JSON.stringify(mergedManifest), { parser: "json-stringify" }));
237+
writeFileSync(destSubPath, JSON.stringify(mergedManifest, null, 2));
239238
} else if (packageSub === "typedoc.json") {
240239
// Skip writing typedoc.json
241240
// ToDo: Remove if typedoc.json is config driven or removed in smithy-typescript.

scripts/generate-clients/generic.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ const { generateGenericClient } = require("./code-gen");
55
const { copyToClients } = require("./copy-to-clients");
66
const { CODE_GEN_GENERIC_CLIENT_OUTPUT_DIR } = require("./code-gen-dir");
77
const { prettifyCode } = require("./code-prettify");
8-
const { eslintFixCode } = require("./code-eslint-fix");
98

109
const PRIVATE_CLIENTS_DIR = path.normalize(path.join(__dirname, "..", "..", "private"));
1110

@@ -14,7 +13,6 @@ const PRIVATE_CLIENTS_DIR = path.normalize(path.join(__dirname, "..", "..", "pri
1413
try {
1514
await generateGenericClient();
1615

17-
await eslintFixCode();
1816
await prettifyCode(CODE_GEN_GENERIC_CLIENT_OUTPUT_DIR);
1917
await copyToClients(CODE_GEN_GENERIC_CLIENT_OUTPUT_DIR, PRIVATE_CLIENTS_DIR);
2018
emptyDirSync(CODE_GEN_GENERIC_CLIENT_OUTPUT_DIR);

0 commit comments

Comments
 (0)