diff --git a/biome.json b/biome.json new file mode 100644 index 000000000000..f630d7cae347 --- /dev/null +++ b/biome.json @@ -0,0 +1,80 @@ +{ + "$schema": "https://biomejs.dev/schemas/2.0.0/schema.json", + "files": { + "maxSize": 16000000, + "includes": ["{packages,lib,scripts,tests}/**/*.{mjs,js,ts,json}", "!**/dist-{cjs,es,types}/**", "!**/ruleset.ts"] + }, + "formatter": { + "enabled": true, + "indentStyle": "space", + "lineWidth": 120, + "indentWidth": 2, + "lineEnding": "lf", + "bracketSpacing": true, + "bracketSameLine": false + }, + "assist": { + "enabled": true, + "actions": { + "source": { + "organizeImports": "on" + } + } + }, + "linter": { + "rules": { + "recommended": true, + "complexity": { + "noForEach": "off" + }, + "correctness": { + "noUndeclaredVariables": "off", + "noUnusedVariables": "info", + "noInvalidBuiltinInstantiation": "error", + "noSwitchDeclarations": "info", + "noUnusedFunctionParameters": "info" + }, + "style": { + "noNamespace": "error", + "useConsistentArrayType": { + "level": "info", + "options": { + "syntax": "shorthand" + } + }, + "noParameterAssign": "info", + "useAsConstAssertion": "info", + "useDefaultParameterLast": "info", + "useEnumInitializers": "error", + "useSingleVarDeclarator": "error", + "noUnusedTemplateLiteral": "info", + "useNumberNamespace": "info", + "noInferrableTypes": "info", + "noUselessElse": "info" + }, + "nursery": { + "useIterableCallbackReturn": "off" + }, + "suspicious": { + "noEmptyBlockStatements": "info", + "noExplicitAny": "info", + "noImplicitAnyLet": "info", + "noEmptyBlock": "info", + "noEmptyInterface": "info", + "noAssignInExpressions": "info", + "noSparseArray": "info", + "noShadowRestrictedNames": "info" + } + } + }, + "javascript": { + "formatter": { + "trailingCommas": "es5" + } + }, + "vcs": { + "enabled": true, + "clientKind": "git", + "useIgnoreFile": true + } +} diff --git a/clients/biome.json b/clients/biome.json new file mode 100644 index 000000000000..e1eda9629d67 --- /dev/null +++ b/clients/biome.json @@ -0,0 +1,26 @@ +{ + "$schema": "https://biomejs.dev/schemas/2.0.0/schema.json", + "extends": "//", + "files": { + "maxSize": 16000000, + "includes": ["**/*.{mjs,js,ts,json}", "!**/dist-{cjs,es,types}/**", "!**/ruleset.ts"] + }, + "linter": { + "rules": { + "recommended": true, + "complexity": { + "noForEach": "off" + }, + "correctness": { + "noUndeclaredVariables": "off", + "noUnusedVariables": "off", + "noInvalidBuiltinInstantiation": "error", + "noSwitchDeclarations": "off", + "noUnusedFunctionParameters": "off" + }, + "style": "off", + "nursery": "off", + "suspicious": "off" + } + } +} diff --git a/package.json b/package.json index 55d4fc8d3746..20d87a89d0c4 100644 --- a/package.json +++ b/package.json @@ -62,6 +62,9 @@ }, "license": "UNLICENSED", "devDependencies": { + "@biomejs/biome": "2.0.0", + "@biomejs/cli-darwin-arm64": "2.0.0", + "@biomejs/cli-linux-x64-musl": "2.0.0", "@commitlint/cli": "17.0.2", "@commitlint/config-conventional": "17.0.2", "@cucumber/cucumber": "8.5.3", diff --git a/private/biome.json b/private/biome.json new file mode 100644 index 000000000000..1565c0dd0231 --- /dev/null +++ b/private/biome.json @@ -0,0 +1,25 @@ +{ + "$schema": "https://biomejs.dev/schemas/2.0.0/schema.json", + "extends": "//", + "files": { + "maxSize": 16000000, + "includes": ["**/*.{mjs,js,ts,json}", "!**/dist-{cjs,es,types}/**", "!**/ruleset.ts"] + }, + "linter": { + "rules": { + "recommended": true, + "complexity": { + "noForEach": "off" + }, + "correctness": { + "noUndeclaredVariables": "off", + "noUnusedVariables": "off", + "noInvalidBuiltinInstantiation": "error", + "noSwitchDeclarations": "off" + }, + "style": "off", + "nursery": "off", + "suspicious": "off" + } + } +} diff --git a/scripts/byte-count/get-cjs-byte-count.js b/scripts/byte-count/get-cjs-byte-count.js index da207121f810..415bb2c29eee 100644 --- a/scripts/byte-count/get-cjs-byte-count.js +++ b/scripts/byte-count/get-cjs-byte-count.js @@ -5,6 +5,7 @@ const { readdirSync, statSync, rmSync, writeFileSync } = require("fs"); const { spawnProcess } = require("../utils/spawn-process"); const walk = require("../utils/walk"); const assert = require("assert"); +const { listFolders } = require("../utils/list-folders"); /** * @@ -20,7 +21,7 @@ locations.clients = join(locations.root, "clients"); (async () => { const packs = []; - for await (const clientFolderName of readdirSync(locations.clients)) { + for await (const clientFolderName of listFolders(locations.clients)) { const clientLocation = join(locations.clients, clientFolderName); const clientPkgJsonLocation = join(clientLocation, "package.json"); const pkg = require(clientPkgJsonLocation); @@ -50,7 +51,7 @@ locations.clients = join(locations.root, "clients"); let bytes = 0; const packFiles = []; - for await (file of walk(locations.clients)) { + for await (const file of walk(locations.clients)) { if (file.includes("aws-sdk-client-") && file.endsWith(".tgz")) { bytes += statSync(file).size; packFiles.push(file); diff --git a/scripts/cli-dispatcher/index.js b/scripts/cli-dispatcher/index.js index 3c460f7e0fd7..801fb7d91dff 100644 --- a/scripts/cli-dispatcher/index.js +++ b/scripts/cli-dispatcher/index.js @@ -7,6 +7,7 @@ const readline = require("readline"); const findFolders = require("./lib/findFolders"); const findScripts = require("./lib/findScripts"); const Package = require("./lib/Package"); +const { listFolders } = require("../utils/list-folders"); /** * This script takes your command line arguments and infers the @@ -21,16 +22,16 @@ async function main() { const root = path.join(__dirname, "..", ".."); const argv = process.argv; - const clients = fs.readdirSync(path.join(root, "clients")); - const lib = fs.readdirSync(path.join(root, "lib")); - const packages = fs.readdirSync(path.join(root, "packages")); - const private = fs.readdirSync(path.join(root, "private")); + const clients = listFolders(path.join(root, "clients")); + const lib = listFolders(path.join(root, "lib")); + const packages = listFolders(path.join(root, "packages")); + const _private = listFolders(path.join(root, "private")); const allPackages = [ ...clients.map((c) => new Package(c, path.join(root, "clients", c))), ...lib.map((l) => new Package(l, path.join(root, "lib", l))), ...packages.map((p) => new Package(p, path.join(root, "packages", p))), - ...private.map((p) => new Package(p, path.join(root, "private", p))), + ..._private.map((p) => new Package(p, path.join(root, "private", p))), ]; const [node, dispatcher, ...rest] = argv; diff --git a/scripts/compilation/inline.js b/scripts/compilation/inline.js index 957b75c52593..3de7cd193ee9 100644 --- a/scripts/compilation/inline.js +++ b/scripts/compilation/inline.js @@ -7,17 +7,18 @@ const fs = require("fs"); const path = require("path"); const Inliner = require("./Inliner"); +const { listFolders } = require("../utils/list-folders"); const root = path.join(__dirname, "..", ".."); -const package = process.argv[2]; +const _package = process.argv[2]; -if (!package) { +if (!_package) { /** * If no package is selected, this script sets build:cjs scripts to * use this inliner script instead of only tsc. */ - const packages = fs.readdirSync(path.join(root, "packages")).map((pkg) => ({ + const packages = listFolders(path.join(root, "packages")).map((pkg) => ({ pkgJsonFilePath: path.join(root, "packages", pkg, "package.json"), pkg, })); @@ -30,7 +31,7 @@ if (!package) { ); packages.push( - ...fs.readdirSync(path.join(root, "clients")).map((pkg) => ({ + ...listFolders(path.join(root, "clients")).map((pkg) => ({ pkgJsonFilePath: path.join(root, "clients", pkg, "package.json"), pkg, })) @@ -43,7 +44,7 @@ if (!package) { } } else { (async () => { - const inliner = new Inliner(package); + const inliner = new Inliner(_package); await inliner.clean(); await inliner.tsc(); await inliner.discoverVariants(); diff --git a/scripts/compilation/set-nocheck.js b/scripts/compilation/set-nocheck.js index 2edcb85449be..d1144f277c4c 100644 --- a/scripts/compilation/set-nocheck.js +++ b/scripts/compilation/set-nocheck.js @@ -1,13 +1,14 @@ const fs = require("node:fs"); const path = require("node:path"); +const { listFolders } = require("../utils/list-folders"); const root = path.join(__dirname, "..", ".."); for (const packageFolder of [ - ...fs.readdirSync(path.join(root, "lib")).map((f) => path.join(root, "lib", f)), - ...fs.readdirSync(path.join(root, "packages")).map((f) => path.join(root, "packages", f)), - ...fs.readdirSync(path.join(root, "clients")).map((f) => path.join(root, "clients", f)), - ...fs.readdirSync(path.join(root, "private")).map((f) => path.join(root, "private", f)), + ...listFolders(path.join(root, "lib"), false), + ...listFolders(path.join(root, "packages"), false), + ...listFolders(path.join(root, "clients"), false), + ...listFolders(path.join(root, "private"), false), ]) { console.log(packageFolder); diff --git a/scripts/npm-registry/mark-version-as-latest.mjs b/scripts/npm-registry/mark-version-as-latest.mjs index a2575c78a764..c868ba51163c 100644 --- a/scripts/npm-registry/mark-version-as-latest.mjs +++ b/scripts/npm-registry/mark-version-as-latest.mjs @@ -8,10 +8,11 @@ */ // -import readline from "readline"; +import { fileURLToPath } from "node:url"; import fs from "fs"; import path, { dirname } from "path"; -import { fileURLToPath } from "node:url"; +import readline from "readline"; +import { listFolders } from "../utils/list-folders.js"; import { spawnProcessReturnValue } from "../utils/spawn-process.js"; const __dirname = dirname(fileURLToPath(import.meta.url)); @@ -34,7 +35,7 @@ const root = path.join(__dirname, "..", ".."); const packages = []; function recordPackages(dir) { - const packageFolders = fs.readdirSync(dir); + const packageFolders = listFolders(dir); for (const packageFolder of packageFolders) { const pkgJson = JSON.parse(fs.readFileSync(path.join(dir, packageFolder, "package.json"), "utf-8")); packages.push(pkgJson.name); diff --git a/scripts/runtime-dependency-version-check/check-dependencies.js b/scripts/runtime-dependency-version-check/check-dependencies.js index b37065d7a632..e4515bc51818 100644 --- a/scripts/runtime-dependency-version-check/check-dependencies.js +++ b/scripts/runtime-dependency-version-check/check-dependencies.js @@ -13,9 +13,10 @@ const _private = path.join(root, "private"); const topLevelFolders = [packages, _private]; const packageFolders = []; const walk = require("../utils/walk"); +const { listFolders } = require("../utils/list-folders"); for (const topLevelFolder of topLevelFolders) { - packageFolders.push(...fs.readdirSync(topLevelFolder)); + packageFolders.push(...listFolders(topLevelFolder)); } const node_libraries = [ diff --git a/scripts/runtime-dependency-version-check/runtime-dep-version-check.js b/scripts/runtime-dependency-version-check/runtime-dep-version-check.js index e55e8d37d901..1d61c5c0c99f 100644 --- a/scripts/runtime-dependency-version-check/runtime-dep-version-check.js +++ b/scripts/runtime-dependency-version-check/runtime-dep-version-check.js @@ -22,27 +22,21 @@ const fs = require("fs"); const path = require("path"); +const { listFolders } = require("../utils/list-folders"); const root = path.join(__dirname, "..", ".."); -const clients = fs.readdirSync(path.join(root, "clients")); -const lib = fs.readdirSync(path.join(root, "lib")); -const packages = fs.readdirSync(path.join(root, "packages")); -const _private = fs.readdirSync(path.join(root, "private")); +const clients = listFolders(path.join(root, "clients"), false); +const lib = listFolders(path.join(root, "lib"), false); +const packages = listFolders(path.join(root, "packages"), false); +const _private = listFolders(path.join(root, "private"), false); const setCanonicalVersion = process.argv.includes("--set-smithy-version"); const colocatedSmithy = fs.existsSync(path.join(root, "..", "smithy-typescript", "packages")); -const clientPackages = [ - ...clients.map((c) => path.join(root, "clients", c)), - ..._private.filter((p) => !p.endsWith("-test")).map((p) => path.join(root, "private", p)), -]; +const clientPackages = [...clients, ..._private.filter((p) => !p.endsWith("-test"))]; -const nonClientPackages = [ - ...lib.map((l) => path.join(root, "lib", l)), - ...packages.map((p) => path.join(root, "packages", p)), - ..._private.filter((p) => p.endsWith("-test")).map((p) => path.join(root, "private", p)), -]; +const nonClientPackages = [...lib, ...packages, ..._private.filter((p) => p.endsWith("-test"))]; const deps = { /* @namespace/name: { diff --git a/scripts/utils/list-folders.js b/scripts/utils/list-folders.js new file mode 100644 index 000000000000..59cb9c49c1bb --- /dev/null +++ b/scripts/utils/list-folders.js @@ -0,0 +1,25 @@ +const fs = require("node:fs"); +const path = require("node:path"); + +/** + * @param dir - directory. + * @param basenameOnly - if true, return only the basename of the subdirectories + * @returns {string[]} list of full-paths of subdirectories (not files) in the given directory. + */ +function listFolders(dir, basenameOnly = true) { + const folders = []; + for (const fileSystemEntry of fs.readdirSync(dir, { withFileTypes: true })) { + if (fileSystemEntry.isDirectory()) { + if (basenameOnly) { + folders.push(fileSystemEntry.name); + } else { + folders.push(path.join(dir, fileSystemEntry.name)); + } + } + } + return folders; +} + +module.exports = { + listFolders, +}; diff --git a/scripts/validation/package-graph-analyzer.js b/scripts/validation/package-graph-analyzer.js index e38479d08602..5084e88bf4c0 100644 --- a/scripts/validation/package-graph-analyzer.js +++ b/scripts/validation/package-graph-analyzer.js @@ -1,5 +1,6 @@ const fs = require("node:fs"); const path = require("node:path"); +const { listFolders } = require("../utils/list-folders"); const root = path.join(__dirname, "..", ".."); const packages = path.join(root, "packages"); @@ -26,7 +27,6 @@ const clients = path.join(root, "clients"); if (pkgJson.private !== true) { throw new Error("package in reserved folder is not marked private:", folder); - } else { } } } @@ -36,16 +36,13 @@ const clients = path.join(root, "clients"); */ { const hasPkgJson = (subfolder, pkg) => fs.existsSync(path.join(subfolder, pkg, "package.json")); - const packagesData = fs - .readdirSync(packages) + const packagesData = listFolders(packages) .filter(hasPkgJson.bind(null, "packages")) .map((pkg) => require(path.join(packages, pkg, "package.json"))); - const libsData = fs - .readdirSync(libs) + const libsData = listFolders(libs) .filter(hasPkgJson.bind(null, "libs")) .map((pkg) => require(path.join(libs, pkg, "package.json"))); - const clientsData = fs - .readdirSync(clients) + const clientsData = listFolders(clients) .filter(hasPkgJson.bind(null, "clients")) .map((pkg) => require(path.join(clients, pkg, "package.json"))); diff --git a/yarn.lock b/yarn.lock index 77853bb4efa2..e2b3a60a3402 100644 --- a/yarn.lock +++ b/yarn.lock @@ -24927,6 +24927,99 @@ __metadata: languageName: node linkType: hard +"@biomejs/biome@npm:2.0.0": + version: 2.0.0 + resolution: "@biomejs/biome@npm:2.0.0" + dependencies: + "@biomejs/cli-darwin-arm64": "npm:2.0.0" + "@biomejs/cli-darwin-x64": "npm:2.0.0" + "@biomejs/cli-linux-arm64": "npm:2.0.0" + "@biomejs/cli-linux-arm64-musl": "npm:2.0.0" + "@biomejs/cli-linux-x64": "npm:2.0.0" + "@biomejs/cli-linux-x64-musl": "npm:2.0.0" + "@biomejs/cli-win32-arm64": "npm:2.0.0" + "@biomejs/cli-win32-x64": "npm:2.0.0" + dependenciesMeta: + "@biomejs/cli-darwin-arm64": + optional: true + "@biomejs/cli-darwin-x64": + optional: true + "@biomejs/cli-linux-arm64": + optional: true + "@biomejs/cli-linux-arm64-musl": + optional: true + "@biomejs/cli-linux-x64": + optional: true + "@biomejs/cli-linux-x64-musl": + optional: true + "@biomejs/cli-win32-arm64": + optional: true + "@biomejs/cli-win32-x64": + optional: true + bin: + biome: bin/biome + checksum: 10c0/a255d2e84e303c6b1bd841877463f358415a35fb39dc4051dec80d9dd44e4f2f546e7e13804f7cd9f0932ca11664600f819e0b0dd75c55c2c0571ed771d86cb5 + languageName: node + linkType: hard + +"@biomejs/cli-darwin-arm64@npm:2.0.0": + version: 2.0.0 + resolution: "@biomejs/cli-darwin-arm64@npm:2.0.0" + checksum: 10c0/764c0c31fd9d3f7f6c865747dc21cfb41a18489ef9a0ee46ad77e90cb06c29d42c4e8c33a00287c61f20cf192a91977a83c66785f34a3fe537c828147737f4d9 + conditions: os=darwin & cpu=arm64 + languageName: node + linkType: hard + +"@biomejs/cli-darwin-x64@npm:2.0.0": + version: 2.0.0 + resolution: "@biomejs/cli-darwin-x64@npm:2.0.0" + conditions: os=darwin & cpu=x64 + languageName: node + linkType: hard + +"@biomejs/cli-linux-arm64-musl@npm:2.0.0": + version: 2.0.0 + resolution: "@biomejs/cli-linux-arm64-musl@npm:2.0.0" + conditions: os=linux & cpu=arm64 & libc=musl + languageName: node + linkType: hard + +"@biomejs/cli-linux-arm64@npm:2.0.0": + version: 2.0.0 + resolution: "@biomejs/cli-linux-arm64@npm:2.0.0" + conditions: os=linux & cpu=arm64 & libc=glibc + languageName: node + linkType: hard + +"@biomejs/cli-linux-x64-musl@npm:2.0.0": + version: 2.0.0 + resolution: "@biomejs/cli-linux-x64-musl@npm:2.0.0" + checksum: 10c0/a40735fe8d2f450415615abd8269057b93c1e2845b08b86df147621bb520c1c706d4b6d1cfb1efcf3d0f2ec7d97c5170a2e9a25cb50784b2bddecf4bfb81f5a6 + conditions: os=linux & cpu=x64 & libc=musl + languageName: node + linkType: hard + +"@biomejs/cli-linux-x64@npm:2.0.0": + version: 2.0.0 + resolution: "@biomejs/cli-linux-x64@npm:2.0.0" + conditions: os=linux & cpu=x64 & libc=glibc + languageName: node + linkType: hard + +"@biomejs/cli-win32-arm64@npm:2.0.0": + version: 2.0.0 + resolution: "@biomejs/cli-win32-arm64@npm:2.0.0" + conditions: os=win32 & cpu=arm64 + languageName: node + linkType: hard + +"@biomejs/cli-win32-x64@npm:2.0.0": + version: 2.0.0 + resolution: "@biomejs/cli-win32-x64@npm:2.0.0" + conditions: os=win32 & cpu=x64 + languageName: node + linkType: hard + "@cnakazawa/watch@npm:^1.0.3": version: 1.0.4 resolution: "@cnakazawa/watch@npm:1.0.4" @@ -30631,6 +30724,9 @@ __metadata: version: 0.0.0-use.local resolution: "aws-sdk-js-v3@workspace:." dependencies: + "@biomejs/biome": "npm:2.0.0" + "@biomejs/cli-darwin-arm64": "npm:2.0.0" + "@biomejs/cli-linux-x64-musl": "npm:2.0.0" "@commitlint/cli": "npm:17.0.2" "@commitlint/config-conventional": "npm:17.0.2" "@cucumber/cucumber": "npm:8.5.3"