-
Notifications
You must be signed in to change notification settings - Fork 2k
fix: consistent formatting and numerous lint errors #600
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
3708f46
build: apply biomejs to gs files
jpoehnelt d2e7f21
style: format
jpoehnelt 9446f6d
style: check --write
jpoehnelt 791d72c
style: check --write --unsafe
jpoehnelt fdc6d6c
style: manual fixes
jpoehnelt cf80358
fix: Remove `--unsafe` flag from Biome format command and improve err…
jpoehnelt 3976323
refactor: Slides image and UI dialog samples into individual files
jpoehnelt 3390c16
fix: revert regression
jpoehnelt b477800
style: template literal
jpoehnelt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,120 @@ | ||
| /** | ||
| * Copyright 2025 Google LLC | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| import { exec } from "node:child_process"; | ||
| import { readdirSync, renameSync, statSync } from "node:fs"; | ||
| import { join, resolve } from "node:path"; | ||
| import { promisify } from "node:util"; | ||
|
|
||
| const execAsync = promisify(exec); | ||
|
|
||
| async function findGsFiles( | ||
| dir: string, | ||
| fileList: string[] = [], | ||
| ): Promise<string[]> { | ||
| const files = readdirSync(dir); | ||
| for (const file of files) { | ||
| const filePath = join(dir, file); | ||
| if ( | ||
| file === "node_modules" || | ||
| file === ".git" || | ||
| file === "dist" || | ||
| file === "target" || | ||
| file === "pkg" | ||
| ) { | ||
| continue; | ||
| } | ||
| const stat = statSync(filePath); | ||
| if (stat.isDirectory()) { | ||
| await findGsFiles(filePath, fileList); | ||
| } else if (file.endsWith(".gs") && file !== "moment.gs") { | ||
| fileList.push(filePath); | ||
| } | ||
| } | ||
| return fileList; | ||
| } | ||
|
|
||
| async function main() { | ||
| const command = process.argv[2]; // 'lint' or 'format' | ||
| if (command !== "lint" && command !== "format") { | ||
| console.error("Usage: tsx biome-gs.ts [lint|format]"); | ||
| process.exit(1); | ||
| } | ||
|
|
||
| const rootDir = resolve("."); | ||
| const gsFiles = await findGsFiles(rootDir); | ||
| const renamedFiles: { oldPath: string; newPath: string }[] = []; | ||
|
|
||
| const restoreFiles = () => { | ||
| for (const { oldPath, newPath } of renamedFiles) { | ||
| try { | ||
| renameSync(newPath, oldPath); | ||
| } catch (e) { | ||
| console.error(`Failed to restore ${newPath} to ${oldPath}:`, e); | ||
| } | ||
| } | ||
| renamedFiles.length = 0; | ||
| }; | ||
jpoehnelt marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| process.on("SIGINT", () => { | ||
| restoreFiles(); | ||
| process.exit(1); | ||
| }); | ||
| process.on("SIGTERM", () => { | ||
| restoreFiles(); | ||
| process.exit(1); | ||
| }); | ||
| process.on("exit", restoreFiles); | ||
|
|
||
| try { | ||
| // 1. Rename .gs to .gs.js | ||
| for (const gsFile of gsFiles) { | ||
| const jsFile = `${gsFile}.js`; | ||
| renameSync(gsFile, jsFile); | ||
| renamedFiles.push({ oldPath: gsFile, newPath: jsFile }); | ||
| } | ||
|
|
||
| // 2. Run Biome | ||
| const biomeArgs = command === "format" ? "check --write ." : "check ."; | ||
| console.log(`Running biome ${biomeArgs}...`); | ||
| try { | ||
| const { stdout, stderr } = await execAsync( | ||
| `pnpm exec biome ${biomeArgs}`, | ||
| { cwd: rootDir }, | ||
| ); | ||
| if (stdout) console.log(stdout.replace(/\.gs\.js/g, ".gs")); | ||
| if (stderr) console.error(stderr.replace(/\.gs\.js/g, ".gs")); | ||
| } catch (e: unknown) { | ||
| const err = e as { stdout?: string; stderr?: string }; | ||
| if (err.stdout) console.log(err.stdout.replace(/\.gs\.js/g, ".gs")); | ||
| if (err.stderr) console.error(err.stderr.replace(/\.gs\.js/g, ".gs")); | ||
| // Don't exit yet, we need to restore files | ||
| } | ||
jpoehnelt marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } catch (err) { | ||
| console.error("An error occurred:", err); | ||
| } finally { | ||
| restoreFiles(); | ||
| // Remove listeners to avoid double-running or issues on exit | ||
| process.removeAllListeners("exit"); | ||
| process.removeAllListeners("SIGINT"); | ||
| process.removeAllListeners("SIGTERM"); | ||
| } | ||
| } | ||
|
|
||
| main().catch((err) => { | ||
| console.error(err); | ||
| process.exit(1); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
findGsFilesfunction uses synchronous file system operations (readdirSync,statSync) within anasyncfunction. This mix of synchronous and asynchronous code is inefficient and can block the Node.js event loop, which can be slow for large repositories.A better approach is to use the promise-based APIs from
node:fs/promisesandPromise.allto perform directory traversal concurrently. This will significantly improve performance and make the code more robust.Please also update your imports from
node:fsto usereaddirfromnode:fs/promisesand remove the now-unusedstatSync.