Skip to content

Commit c1ca230

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

File tree

16 files changed

+322
-894
lines changed

16 files changed

+322
-894
lines changed

biome.json

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
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+
"useSortedKeys": "on",
25+
"organizeImports": "on"
26+
}
27+
}
28+
},
29+
"linter": {
30+
"rules": {
31+
"recommended": true,
32+
"complexity": {
33+
"noForEach": "off"
34+
},
35+
"correctness": {
36+
"noUndeclaredVariables": "error",
37+
"noUnusedVariables": "info",
38+
"noInvalidBuiltinInstantiation": "error"
39+
},
40+
"style": {
41+
"noNamespace": "error",
42+
"useConsistentArrayType": {
43+
"level": "error",
44+
"options": {
45+
"syntax": "shorthand"
46+
}
47+
},
48+
"noParameterAssign": "info",
49+
"useAsConstAssertion": "error",
50+
"useDefaultParameterLast": "info",
51+
"useEnumInitializers": "error",
52+
"useSelfClosingElements": "error",
53+
"useSingleVarDeclarator": "error",
54+
"noUnusedTemplateLiteral": "info",
55+
"useNumberNamespace": "error",
56+
"noInferrableTypes": "error",
57+
"noUselessElse": "error"
58+
},
59+
"suspicious": {
60+
"noEmptyBlockStatements": "info",
61+
"noExplicitAny": "info",
62+
"noImplicitAnyLet": "info",
63+
"noEmptyBlock": "info",
64+
"noEmptyInterface": "info",
65+
"noAssignInExpressions": "info"
66+
}
67+
}
68+
},
69+
"javascript": {
70+
"formatter": {
71+
"trailingCommas": "es5"
72+
}
73+
},
74+
"vcs": {
75+
"enabled": true,
76+
"clientKind": "git",
77+
"useIgnoreFile": true
78+
}
79+
}

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: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
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+
const skip = /browser-build|node_modules|dist-(es|cjs|types)|ruleset\.ts$/;
20+
const match = /\.(m?js|ts|json)$/;
21+
22+
export async function formatDir(dir) {
23+
const concurrency = [];
24+
25+
for await (const file of walk(dir, ["node_modules"])) {
26+
if (file.match(skip)) {
27+
continue;
28+
}
29+
if (file.match(match)) {
30+
concurrency.push(
31+
promises
32+
.readFile(file, "utf-8")
33+
.then((contents) => {
34+
const formatted = formatCode(contents, file);
35+
if (formatted) {
36+
const linted = lintCode(formatted, file);
37+
return promises.writeFile(file, linted, "utf-8");
38+
}
39+
return Promise.resolve();
40+
})
41+
.catch(console.error)
42+
);
43+
}
44+
}
45+
46+
await Promise.all(concurrency);
47+
}
48+
49+
export function formatCode(code, filePath) {
50+
const format = biome.formatContent(projectKey, code, {
51+
filePath,
52+
});
53+
return format.content;
54+
}
55+
56+
export function lintCode(code, filePath) {
57+
const lint = biome.lintContent(projectKey, code, {
58+
filePath,
59+
});
60+
for (const diagnostic of lint.diagnostics) {
61+
if (diagnostic.severity === "error" || diagnostic.severity === "fatal") {
62+
const { category, severity, description, location } = diagnostic;
63+
console.log(`${category} - ${severity}\n\t${description}`);
64+
console.log(`\t\t${location.path.file.split("aws-sdk-js-v3")[1]}:${location.span.join(":")}`);
65+
}
66+
}
67+
return lint.content;
68+
}

scripts/biome/run-biome.mjs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
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"));
9+
await formatDir(join(__dirname, "..", "..", "clients", "client-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)