Skip to content

fix: formatting drift & linter in playground#2641

Merged
comatory merged 1 commit intomainfrom
ondrej/eng-9175-cosmoplayground-fix-formatting-drift-enable-ci-check
Apr 21, 2026
Merged

fix: formatting drift & linter in playground#2641
comatory merged 1 commit intomainfrom
ondrej/eng-9175-cosmoplayground-fix-formatting-drift-enable-ci-check

Conversation

@comatory
Copy link
Copy Markdown
Contributor

@comatory comatory commented Mar 12, 2026

Summary by CodeRabbit

Release Notes

  • New Features

    • Added code linting functionality to the Playground development workflow.
  • Chores

    • Added linting tools and configuration for code quality checks.
    • Integrated automatic linting step into continuous integration pipeline.
    • Added new lint and lint:fix commands to development scripts.
  • Style

    • Normalized code formatting across Playground components for consistency.

Checklist

This PR fixes formatting drift in playground/ package. CI was omitting checks. The package did not contain any
linter configured, so I added same eslint version as studio/. This app is not using Next, so instead
a common set of plugins were selected that make sense.

I set few of the rules to warning, to avoid bloating the size of this PR. It can be later addressed in subsequent
PR (removal of any).

Caution

I had to re-generate graphiql by running pnpm run --filter ./playground build:router. It was outdated.

@github-actions

This comment has been minimized.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 12, 2026

Walkthrough

This pull request adds ESLint configuration and linting capabilities to the playground directory, introduces new lint-related CI steps, and performs widespread quote style normalization from double to single quotes across the codebase with minor functional refinements.

Changes

Cohort / File(s) Summary
ESLint & Linting Setup
.github/workflows/playground-ci.yaml, playground/.eslintrc.json, playground/.eslintignore, playground/package.json
Adds ESLint configuration with TypeScript and React plugin support, introduces new lint and lint:fix scripts, adds ESLint-related dev dependencies, and adds CI step to run lint:fix after router build.
Formatting & Configuration
playground/.gitignore, playground/README.md, playground/postcss.config.js
Adds .eslintcache to gitignore, minor README formatting adjustments, and semicolon normalization in PostCSS config.
UI Components Formatting
playground/src/components/ui/badge.tsx, playground/src/components/ui/button.tsx, playground/src/components/ui/card.tsx, playground/src/components/ui/cli.tsx, playground/src/components/ui/dialog.tsx, playground/src/components/ui/separator.tsx, playground/src/components/ui/tabs.tsx, playground/src/components/ui/tooltip.tsx
Quote normalization to single quotes, import consolidation, inline formatting of components, and structural refactoring (card.tsx splits nested exports into individual exports, button.tsx adds disabled attribute logic, dialog.tsx adds close button, separator.tsx converts to inline arrow function).
Playground Components Formatting
playground/src/components/playground/monaco-dark-theme.ts, playground/src/components/playground/plan-view.tsx, playground/src/components/playground/view-load-stats.tsx, playground/src/components/playground/view-output.tsx
Quote normalization, single-line import consolidation, and JSX formatting adjustments without behavioral changes. Removes unused loader export from Monaco Editor import.
Component Logic Updates
playground/src/components/code-viewer.tsx, playground/src/components/empty-state.tsx, playground/src/components/playground/custom-scripts.tsx, playground/src/components/playground/index.tsx
Code-viewer adds dynamic prettier formatting via useEffect, custom-scripts removes useLocalStorage getter, index.tsx removes unused GraphQL imports and marks unused parameters with underscores, empty-state applies inline formatting.
Utility Libraries
playground/src/lib/random-uuid.ts, playground/src/lib/use-event-callback.ts, playground/src/lib/use-event-listener.ts, playground/src/lib/use-isomorphic-layout-effect.ts, playground/src/lib/utils.ts
Quote normalization to single quotes, import formatting, and minor function signature consolidation. random-uuid.ts updates TypeScript error suppression directive.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title 'fix: formatting drift & linter in playground' directly and clearly describes the main changes: fixing formatting issues and adding/configuring a linter in the playground package, which aligns with the primary objectives of the PR.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
📝 Coding Plan for PR comments
  • Generate coding plan

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 12, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 46.51%. Comparing base (5fa75d0) to head (c08cc1b).
⚠️ Report is 88 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff             @@
##             main    #2641       +/-   ##
===========================================
- Coverage   62.85%   46.51%   -16.35%     
===========================================
  Files         244     1043      +799     
  Lines       25831   141351   +115520     
  Branches        0     9680     +9680     
===========================================
+ Hits        16237    65753    +49516     
- Misses       8259    73885    +65626     
- Partials     1335     1713      +378     

see 812 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Mar 12, 2026

Router-nonroot image scan passed

✅ No security vulnerabilities found in image:

ghcr.io/wundergraph/cosmo/router:sha-785359baabdd2dbe4bf0b20b092328fef5050143-nonroot

@comatory comatory force-pushed the ondrej/eng-9175-cosmoplayground-fix-formatting-drift-enable-ci-check branch from b601eb0 to 8a90e02 Compare March 12, 2026 14:20
@github-actions

This comment has been minimized.

@comatory comatory force-pushed the ondrej/eng-9175-cosmoplayground-fix-formatting-drift-enable-ci-check branch from 8a90e02 to 353a75f Compare March 12, 2026 14:25
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
playground/src/components/code-viewer.tsx (1)

21-34: ⚠️ Potential issue | 🟠 Major

Preserve the raw snippet while async formatting runs.

content starts empty and the effect returns early for falsy code, so the viewer paints blank on first render and keeps showing the previous snippet when code becomes ''. Since formatting is async, an older completion or parse failure can also leave stale/empty content on screen. This surfaces in the eagerly mounted tab usages at playground/src/components/playground/fetch-flow.tsx (lines 240–258) and playground/src/components/playground/view-input.tsx (line 53, where input?.body?.query ?? '' explicitly passes an empty string).

Suggested fix
-  const [content, setContent] = useState('');
+  const [content, setContent] = useState(code);

   useEffect(() => {
-    const set = async (source: string) => {
-      const res = await prettier.format(source, {
-        parser: language,
-        plugins: [graphQLPlugin, estreePlugin, babelPlugin],
-      });
-      setContent(res);
-    };
-
-    if (!code) return;
-    set(code);
+    if (!code) {
+      setContent('');
+      return;
+    }
+
+    setContent(code);
+    let cancelled = false;
+
+    const formatCode = async () => {
+      try {
+        const res = await prettier.format(code, {
+          parser: language,
+          plugins: [graphQLPlugin, estreePlugin, babelPlugin],
+        });
+
+        if (!cancelled) {
+          setContent(res);
+        }
+      } catch {
+        if (!cancelled) {
+          setContent(code);
+        }
+      }
+    };
+
+    void formatCode();
+
+    return () => {
+      cancelled = true;
+    };
   }, [code, language]);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@playground/src/components/code-viewer.tsx` around lines 21 - 34, When code
changes we should synchronously show the raw snippet and only replace it when
the async formatter completes (and only if it’s still the latest request). In
the useEffect that declares set and calls prettier.format, immediately call
setContent(code) instead of returning early for falsy code, start the async
format, and use a local requestId/token (e.g., incrementing counter or
closure-scoped id) captured before awaiting prettier.format to ignore stale
results; on format success call setContent(formatted) only if the token matches,
and on error do not overwrite the raw snippet. Reference: content, setContent,
useEffect, set (async formatter), and prettier.format.
🧹 Nitpick comments (1)
.github/workflows/playground-ci.yaml (1)

32-33: Use the read-only lint target in CI instead of lint:fix.

lint:fix mutates the files and then relies on git-dirty-check to fail afterward, making lint/format drift surface as a secondary dirty-tree symptom instead of a direct check failure. The lint target provides read-only verification, which is the appropriate fit for CI; keep lint:fix for local cleanup.

♻️ Suggested change
-      - name: Lint & format
-        run: pnpm run --filter ./playground lint:fix
+      - name: Lint & format
+        run: pnpm run --filter ./playground lint
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.github/workflows/playground-ci.yaml around lines 32 - 33, Replace the CI
step that runs the mutating target "lint:fix" with the read-only verification
target "lint" so CI fails fast on lint/format issues (change the run command
from "pnpm run --filter ./playground lint:fix" to "pnpm run --filter
./playground lint"); keep "lint:fix" available for local cleanup and do not rely
on "git-dirty-check" to surface formatting drift.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@playground/src/components/playground/monaco-dark-theme.ts`:
- Around line 236-237: Two token scope strings are misspelled in the theme
tokens list: replace "upport.constant.meta.property-value" with
"support.constant.meta.property-value" and replace
"keyword.operator.assignement" with "keyword.operator.assignment" so Monaco can
match them; locate these literal strings in
playground/src/components/playground/monaco-dark-theme.ts within the tokens
array and update the token names accordingly.

In `@playground/src/components/ui/card.tsx`:
- Around line 17-19: The CardTitle forwards a ref but currently uses
HTMLParagraphElement for the ref generic while rendering an <h3>, causing a type
mismatch; update the React.forwardRef generic so the ref type is
HTMLHeadingElement and the props type matches an h3 (e.g., use
React.HTMLAttributes<HTMLHeadingElement> or
React.ComponentPropsWithoutRef<'h3'>) so React.forwardRef<HTMLHeadingElement,
React.HTMLAttributes<HTMLHeadingElement>>(...) (or the ComponentPropsWithoutRef
variant) keeps the ref and props types in sync for the CardTitle component.

---

Outside diff comments:
In `@playground/src/components/code-viewer.tsx`:
- Around line 21-34: When code changes we should synchronously show the raw
snippet and only replace it when the async formatter completes (and only if it’s
still the latest request). In the useEffect that declares set and calls
prettier.format, immediately call setContent(code) instead of returning early
for falsy code, start the async format, and use a local requestId/token (e.g.,
incrementing counter or closure-scoped id) captured before awaiting
prettier.format to ignore stale results; on format success call
setContent(formatted) only if the token matches, and on error do not overwrite
the raw snippet. Reference: content, setContent, useEffect, set (async
formatter), and prettier.format.

---

Nitpick comments:
In @.github/workflows/playground-ci.yaml:
- Around line 32-33: Replace the CI step that runs the mutating target
"lint:fix" with the read-only verification target "lint" so CI fails fast on
lint/format issues (change the run command from "pnpm run --filter ./playground
lint:fix" to "pnpm run --filter ./playground lint"); keep "lint:fix" available
for local cleanup and do not rely on "git-dirty-check" to surface formatting
drift.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 6de9b148-b30c-426a-8f10-382b972625dc

📥 Commits

Reviewing files that changed from the base of the PR and between c8b8408 and 353a75f.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (28)
  • .github/workflows/playground-ci.yaml
  • playground/.eslintignore
  • playground/.eslintrc.json
  • playground/.gitignore
  • playground/README.md
  • playground/package.json
  • playground/postcss.config.js
  • playground/src/components/code-viewer.tsx
  • playground/src/components/empty-state.tsx
  • playground/src/components/playground/custom-scripts.tsx
  • playground/src/components/playground/index.tsx
  • playground/src/components/playground/monaco-dark-theme.ts
  • playground/src/components/playground/plan-view.tsx
  • playground/src/components/playground/view-load-stats.tsx
  • playground/src/components/playground/view-output.tsx
  • playground/src/components/ui/badge.tsx
  • playground/src/components/ui/button.tsx
  • playground/src/components/ui/card.tsx
  • playground/src/components/ui/cli.tsx
  • playground/src/components/ui/dialog.tsx
  • playground/src/components/ui/separator.tsx
  • playground/src/components/ui/tabs.tsx
  • playground/src/components/ui/tooltip.tsx
  • playground/src/lib/random-uuid.ts
  • playground/src/lib/use-event-callback.ts
  • playground/src/lib/use-event-listener.ts
  • playground/src/lib/use-isomorphic-layout-effect.ts
  • playground/src/lib/utils.ts

Comment thread playground/src/components/playground/monaco-dark-theme.ts
Comment thread playground/src/components/ui/card.tsx
@github-actions
Copy link
Copy Markdown

This PR was marked stale due to lack of activity. It will be closed in 14 days.

@github-actions github-actions Bot added Stale and removed Stale labels Mar 28, 2026
@github-actions
Copy link
Copy Markdown

This PR was marked stale due to lack of activity. It will be closed in 14 days.

@github-actions github-actions Bot added Stale and removed Stale labels Apr 12, 2026
@comatory comatory force-pushed the ondrej/eng-9175-cosmoplayground-fix-formatting-drift-enable-ci-check branch from c08cc1b to 256ae24 Compare April 21, 2026 10:52
@comatory comatory marked this pull request as ready for review April 21, 2026 10:59
@comatory comatory requested review from a team, StarpTech and thisisnithin as code owners April 21, 2026 10:59
@comatory comatory requested a review from devsergiy April 21, 2026 10:59
@comatory comatory merged commit c7d1016 into main Apr 21, 2026
9 checks passed
@comatory comatory deleted the ondrej/eng-9175-cosmoplayground-fix-formatting-drift-enable-ci-check branch April 21, 2026 11:30
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