Skip to content

fix: .prettierignore in apigen task#3318

Draft
Noel Cothren (noeldevelops) wants to merge 2 commits intomainfrom
ncothren/fix-apigen-prettier
Draft

fix: .prettierignore in apigen task#3318
Noel Cothren (noeldevelops) wants to merge 2 commits intomainfrom
ncothren/fix-apigen-prettier

Conversation

@noeldevelops
Copy link
Member

@noeldevelops Noel Cothren (noeldevelops) commented Mar 2, 2026

DRAFT

Testing locally and exploring alternatives first.*

TL;DR a recent PR to add a Claude hook for prettier also added a .prettierignore file + check, which caused my run of gulp apigen (the first since then) to skip re-formatting the client file changes.

*Claude's first fix was to add an option to ignore the ignore file in the prettier function. Another option is to have apigen run it's own formatting command. Or, maybe Prettier doesn't need to ignore src/clients; those files should always follow our prettier config since they get formatted after generation.

💡 Currently exploring the idea that we may not need this entire prettier() function, since the prettier cli handles all of that automatically — it reads .prettierrc, respects .prettierignore, discovers files from the glob, and writes them in place.

Summary

  • The .prettierignore added in set up claude hook for file formatting with Prettier #3256 includes src/clients/ to prevent the Claude Code formatting hook from reformatting auto-generated client code. However, the apigen gulp task's internal Prettier step uses the same prettier() helper, which consults .prettierignore — causing it to silently skip formatting for all generated client files.
  • This meant running gulp apigen produced raw openapi-generator output (4-space indent, single quotes) instead of Prettier-formatted output (2-space indent, double quotes per .prettierrc), creating thousands of lines of cosmetic diffs across every client even when only one spec changed.
  • Adds an ignoreIgnoreFile option to the prettier() helper so apigen can bypass .prettierignore while all other callers (e.g. the format task and Claude hook) remain unaffected.

Investigation

When updating the Flink SQL OpenAPI spec and running gulp apigen, all 10 generated clients showed massive formatting-only diffs (indentation, quote style, trailing whitespace). The root cause trace:

  1. apigen calls prettier() at Gulpfile.js:1001 to get a formatting transform
  2. prettier() calls getFileInfo(file.path, { ignorePath: ".prettierignore" }) for each file
  3. .prettierignore contains src/clients/, so fileInfo.ignored is true for every generated file
  4. The formatting transform continues past every file — no formatting is applied
  5. The raw openapi-generator-cli output (which uses different defaults than our .prettierrc) gets written as-is, differing from the previously Prettier-formatted files on main

Test plan

  • Run gulp apigen on a clean main checkout — verify no unexpected diffs in non-changed clients
  • Run gulp format — verify it still respects .prettierignore and skips src/clients/

🤖 Generated with Claude Code

The `.prettierignore` added in #3256 includes `src/clients/` to prevent
the Claude Code formatting hook from touching auto-generated code. However,
the `apigen` gulp task's internal Prettier step uses the same `prettier()`
helper, which consults `.prettierignore` — causing it to skip formatting
entirely for all generated client files.

This meant running `gulp apigen` produced raw openapi-generator output
(4-space indent, single quotes) instead of Prettier-formatted output
(2-space indent, double quotes per .prettierrc), creating large cosmetic
diffs across all clients even when only one spec changed.

Add an `ignoreIgnoreFile` option to the `prettier()` helper so `apigen`
can bypass `.prettierignore` while all other callers remain unaffected.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Updates the Gulp apigen workflow so generated OpenAPI client code in src/clients/ is still formatted by Prettier even though the repository’s .prettierignore intentionally excludes src/clients/ to protect generated code from other format hooks.

Changes:

  • Adds an ignoreIgnoreFile option to the internal prettier() gulp transform helper.
  • Updates apigen to call prettier({ ignoreIgnoreFile: true }), bypassing .prettierignore for the generation pipeline while keeping other tasks (e.g. gulp format) unchanged.

@noeldevelops Noel Cothren (noeldevelops) marked this pull request as draft March 2, 2026 20:44
Replace the custom Gulp streaming `prettier()` helper with direct
`npx prettier` CLI calls via `spawnSync`. The CLI handles config
resolution, .prettierignore, file discovery, and writing — eliminating
the need for the manual async iterator, Gulp src/dest/pipeline wiring,
and the `ignoreIgnoreFile` workaround from the previous commit.

For `apigen`, uses `--ignore-path /dev/null` to bypass .prettierignore
(which excludes src/clients/ to prevent other tools from reformatting
generated code).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@sonarqube-confluent
Copy link

Quality Gate passed Quality Gate passed

Issues
0 New issues
0 Fixed issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
No data about Duplication

See analysis details on SonarQube

@noeldevelops Noel Cothren (noeldevelops) changed the title fix: bypass .prettierignore in apigen task fix: .prettierignore in apigen task Mar 2, 2026
Comment on lines +1046 to +1049
const result = spawnSync(
"npx",
["prettier", "--write", "src/**/*.{ts,css,html,json}", "*.md", "*.js"],
{ stdio: "inherit", shell: IS_WINDOWS },
Copy link
Member Author

Choose a reason for hiding this comment

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

Dave Shoup (@shouples) this does everything the prettier() function below does

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