Skip to content

Migrate linting/formatting to Biome + ESLint v9#77

Open
Vasco-jofra wants to merge 7 commits intomainfrom
VF/lint_and_format
Open

Migrate linting/formatting to Biome + ESLint v9#77
Vasco-jofra wants to merge 7 commits intomainfrom
VF/lint_and_format

Conversation

@Vasco-jofra
Copy link
Collaborator

Summary

  • Replace Trunk + Prettier with Biome (formatter) + ESLint v9 flat config + pre-commit hooks, matching the vscode-weaudit project setup
  • Upgrade TypeScript from 4.9 to 5.9, ESLint from 8 to 9, typescript-eslint from 5 to 8
  • Resolve all ESLint warnings (return type annotations, eslint-disable comments for intentional patterns, async/promise fixes) so the strict recommended-type-checked ruleset runs at error level with 0 violations
  • Add CI workflow (lint_and_format.yml) for biome check, eslint, and tsc
  • Add .git-blame-ignore-revs for the two formatting/annotation commits

Infrastructure changes

Removed Added
.trunk/ (8 files) .eslintrc.cjs (ESLint v9 flat config)
.github/workflows/lint.yml .github/workflows/lint_and_format.yml
justfile biome.json
prettier dep .pre-commit-config.yaml
.git-blame-ignore-revs

Code changes (no semantic changes)

  • Added explicit return type annotations to ~170 functions/methods/callbacks
  • Added eslint-disable comments for SARIF JSON parsing (no-unsafe-*) and naming patterns (naming-convention)
  • Removed unnecessary async from functions that don't await
  • Added void operator to fire-and-forget promises
  • Fixed == to ===, added curly braces, etc.

Test plan

  • npm run lint — 0 errors, 0 warnings
  • npm run format:check — all files clean
  • npm run typecheck — passes
  • npm run compile — passes

🤖 Generated with Claude Code

Vasco-jofra and others added 6 commits February 13, 2026 16:35
Replace Trunk orchestrator and Prettier with Biome formatter and ESLint v9
flat config to match vscode-weaudit's setup. Add pre-commit hooks and a
new CI workflow for consistent lint/format checks.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Reformat codebase with Biome (160 line width). Update eslint-disable
rule name from no-var-requires to no-require-imports for typescript-eslint
v8, remove trunk-ignore comment from webpack config, and fix executeCommand
type parameter in weAuditInterface.ts.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Add `void` to fire-and-forget promises (no-floating-promises)
- Remove `async` from functions with no `await` (require-await)
- Rename snake_case locals to camelCase (naming-convention)
- Use `String()` for unknown values in template literals (restrict-template-expressions)
- Use `===` instead of `==` (eqeqeq)
- Cast enum comparisons (no-unsafe-enum-comparison)
- Wrap rejection reason in Error (prefer-promise-reject-errors)
- Prefix unused catch variable with `_` (no-unused-vars)

Reduces warnings from 419 to 350. Remaining warnings are
explicit-function-return-type (176), no-unsafe-* (140), and
naming-convention for enum members (34).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add explicit return type annotations to all functions, methods, and
arrow callbacks. Add eslint-disable comments for intentional patterns
(UPPER_CASE properties, PascalCase enum members, untyped SARIF JSON
parsing). Remove the 11 downgraded rules from .eslintrc.cjs so they
inherit the default error level from recommended-type-checked.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@Vasco-jofra Vasco-jofra requested a review from fcasal as a code owner February 13, 2026 17:32

// Add an event listener to receive messages from the extension
window.addEventListener("message", (event) => {
window.addEventListener("message", (event): void => {

Check warning

Code scanning / CodeQL

Missing origin verification in `postMessage` handler Medium

Postmessage handler has no origin check.

Copilot Autofix

AI about 17 hours ago

In general, to fix missing origin verification for a postMessage handler, you must validate that the incoming message comes from an expected, trusted context before acting on it. This is usually done by checking event.origin against a whitelist of allowed origins and, where appropriate, also checking event.source or message shape (e.g., a type field) before processing event.data.

For this specific code in src/webviewSrc/main.ts, the best fix with minimal behavioral change is:

  • Wrap the body of the "message" event listener in a guard that ensures the event is from an expected context.
  • In a VS Code webview, event.origin has a fixed value (typically "vscode-webview://" + ...), but we should not hard-code a specific host/path if we’re not given it. Instead, we can:
    • Check that event.origin is strictly equal to window.origin. For content running inside a webview, legitimate messages from the extension are delivered with the same origin as the current document, while cross-origin frames would differ.
    • Optionally, also ensure event.source === window to restrict to same-window messages (this is conservative and safe given we have no other constraints).
  • Only when the origin check passes do we cast event.data to ExtensionToWebviewMsgTypes and call handleWebviewMessage(message).

Concretely:

  • In src/webviewSrc/main.ts, within init(), change the message event listener (lines 29–33) to:
    • Early-return if event.origin !== window.origin.
    • Optionally, also early-return if event.source !== window.
  • No new imports are needed, as window and event.origin are standard browser/webview APIs.
Suggested changeset 1
src/webviewSrc/main.ts

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/src/webviewSrc/main.ts b/src/webviewSrc/main.ts
--- a/src/webviewSrc/main.ts
+++ b/src/webviewSrc/main.ts
@@ -27,6 +27,10 @@
 
     // Add an event listener to receive messages from the extension
     window.addEventListener("message", (event): void => {
+        // Verify that the message comes from the same origin and window
+        if (event.origin !== window.origin || event.source !== window) {
+            return;
+        }
         // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
         const message: ExtensionToWebviewMsgTypes = event.data;
         handleWebviewMessage(message);
EOF
@@ -27,6 +27,10 @@

// Add an event listener to receive messages from the extension
window.addEventListener("message", (event): void => {
// Verify that the message comes from the same origin and window
if (event.origin !== window.origin || event.source !== window) {
return;
}
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const message: ExtensionToWebviewMsgTypes = event.data;
handleWebviewMessage(message);
Copilot is powered by AI and may make mistakes. Always verify output.
@fcasal
Copy link
Collaborator

fcasal commented Feb 13, 2026

I noticed that the current pull request setup does not trigger warnings on vscode if, for example, you remove one of the function declaration having a return void : void. In the weaudit codebase, the setup gives a warning for it (Missing return type on function.eslint[@typescript-eslint/explicit-function-return-type](https://typescript-eslint.io/rules/explicit-function-return-type))

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants