Skip to content

Commit 3295a8d

Browse files
committed
chore: experiment with biomejs
1 parent c4fe747 commit 3295a8d

File tree

15 files changed

+285
-894
lines changed

15 files changed

+285
-894
lines changed

biome.json

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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": "error",
27+
"noInvalidBuiltinInstantiation": "error"
28+
},
29+
"style": {
30+
"noNamespace": "error",
31+
"useConsistentArrayType": {
32+
"level": "error",
33+
"options": {
34+
"syntax": "shorthand"
35+
}
36+
},
37+
"noParameterAssign": "error",
38+
"useAsConstAssertion": "error",
39+
"useDefaultParameterLast": "error",
40+
"useEnumInitializers": "error",
41+
"useSelfClosingElements": "error",
42+
"useSingleVarDeclarator": "error",
43+
"noUnusedTemplateLiteral": "error",
44+
"useNumberNamespace": "error",
45+
"noInferrableTypes": "error",
46+
"noUselessElse": "error"
47+
},
48+
"suspicious": {
49+
"noEmptyBlockStatements": "error",
50+
"noExplicitAny": "off"
51+
}
52+
}
53+
},
54+
"javascript": {
55+
"formatter": {
56+
"trailingCommas": "es5"
57+
}
58+
},
59+
"vcs": {
60+
"enabled": true,
61+
"clientKind": "git",
62+
"useIgnoreFile": true
63+
}
64+
}

package.json

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
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:ci": "lerna exec --since origin/main --exclude-dependents --ignore '@aws-sdk/client-*' --ignore '@aws-sdk/aws-*' 'npx @biomejs/biome lint src/**/*.ts'",
33+
"lint:release": "lerna exec --ignore '@aws-sdk/client-*' --ignore '@aws-sdk/aws-*' 'npx @biomejs/biome lint src/**/*.ts'",
3434
"lint:versions": "node scripts/runtime-dependency-version-check/runtime-dep-version-check.js",
3535
"lint:dependencies": "node scripts/runtime-dependency-version-check/check-dependencies.js",
3636
"local-publish": "node ./scripts/verdaccio-publish/index.js",
@@ -62,30 +62,24 @@
6262
},
6363
"license": "UNLICENSED",
6464
"devDependencies": {
65+
"@biomejs/biome": "2.0.0",
66+
"@biomejs/js-api": "1.0.0",
67+
"@biomejs/wasm-nodejs": "2.0.0",
6568
"@commitlint/cli": "17.0.2",
6669
"@commitlint/config-conventional": "17.0.2",
6770
"@cucumber/cucumber": "8.5.3",
6871
"@cucumber/pretty-formatter": "^1.0.0",
6972
"@fastify/formbody": "^7.4.0",
7073
"@microsoft/api-extractor": "7.52.7",
71-
"@mixer/parallel-prettier": "2.0.3",
7274
"@tsconfig/recommended": "1.0.1",
7375
"@types/fs-extra": "^8.0.1",
7476
"@types/jest": "29.5.11",
7577
"@types/jsdom": "20.0.1",
76-
"@typescript-eslint/eslint-plugin": "5.55.0",
77-
"@typescript-eslint/parser": "5.55.0",
7878
"async": "3.2.4",
7979
"concurrently": "7.0.0",
8080
"decomment": "0.9.5",
8181
"downlevel-dts": "0.10.1",
8282
"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",
8983
"esprint": "3.6.0",
9084
"fastify": "^4.11.0",
9185
"figlet": "^1.5.0",
@@ -100,7 +94,6 @@
10094
"kill-port": "^2.0.1",
10195
"lerna": "5.5.2",
10296
"lint-staged": "^10.0.1",
103-
"prettier": "2.8.5",
10497
"rimraf": "3.0.2",
10598
"ts-jest": "29.1.1",
10699
"ts-loader": "9.4.2",
@@ -135,10 +128,9 @@
135128
},
136129
"lint-staged": {
137130
"{lib,packages}/**/src/**/*.ts": [
138-
"eslint --fix",
139-
"prettier --write"
131+
"echo npx @biomejs/biome check --write"
140132
],
141-
"**/*.{ts,js,md,json}": "prettier --write"
133+
"**/*.{ts,js,md,json}": "echo npx @biomejs/biome check --write"
142134
},
143135
"packageManager": "[email protected]"
144136
}

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: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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+
if (file.endsWith(".ts") || file.endsWith(".js")) {
24+
if (file.endsWith("ruleset.ts")) {
25+
continue;
26+
}
27+
concurrency.push(
28+
promises.readFile(file, "utf-8").then((contents) => {
29+
return promises.writeFile(file, formatCode(contents, file), "utf-8");
30+
})
31+
);
32+
}
33+
}
34+
35+
await Promise.all(concurrency);
36+
}
37+
38+
export function formatCode(code, filePath) {
39+
const format = biome.formatContent(projectKey, code, {
40+
filePath,
41+
});
42+
43+
const lint = biome.lintContent(projectKey, format.content, {
44+
filePath,
45+
});
46+
47+
for (const diagnostic of lint.diagnostics) {
48+
if (diagnostic.severity === "error" || diagnostic.severity === "fatal") {
49+
console.log(diagnostic);
50+
}
51+
}
52+
53+
return format.content;
54+
}
55+
56+
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);

scripts/generate-clients/index.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ const {
1414
TEMP_CODE_GEN_INPUT_DIR,
1515
} = require("./code-gen-dir");
1616
const { prettifyCode } = require("./code-prettify");
17-
const { eslintFixCode } = require("./code-eslint-fix");
1817
const { buildSmithyTypeScript } = require("./build-smithy-typescript");
1918
const { SMITHY_TS_COMMIT } = require("./config");
2019
const { spawnProcess } = require("../utils/spawn-process");
@@ -86,7 +85,6 @@ const {
8685

8786
if (serverOnly === true) {
8887
await generateProtocolTests();
89-
await eslintFixCode();
9088
await prettifyCode(CODE_GEN_PROTOCOL_TESTS_OUTPUT_DIR);
9189
await copyServerTests(CODE_GEN_PROTOCOL_TESTS_OUTPUT_DIR, PRIVATE_CLIENTS_DIR);
9290

@@ -107,7 +105,6 @@ const {
107105
await generateProtocolTests();
108106
}
109107

110-
await eslintFixCode();
111108
if (!protocolTestsOnly) {
112109
await codeOrdering(CODE_GEN_SDK_OUTPUT_DIR);
113110
await prettifyCode(CODE_GEN_SDK_OUTPUT_DIR);

0 commit comments

Comments
 (0)