You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by "rusackas (via GitHub)" <gi...@apache.org> on 2026/07/10 22:49:44 UTC
[PR] fix(pre-commit): prettier hook drops first file and never batches [superset]
rusackas opened a new pull request, #41944:
URL: https://github.com/apache/superset/pull/41944
### SUMMARY
Thanks to @mikebridge for the tip on this one.
The `prettier-frontend` pre-commit hook's `entry` runs as `bash -c '<script>' file1 file2 ...` with no separator before the file args pre-commit appends. Under `bash -c` semantics, the first argument after the script string becomes `$0`, not part of `"$@"`, so the first staged frontend file is silently dropped from the `for file in "$@"` loop every time. With exactly one staged file, the loop body never runs at all, meaning prettier silently doesn't format it.
Separately, the loop invoked `npx prettier --write` once per file instead of batching, which adds `npx`/config-resolution startup overhead per file rather than once per commit.
This fix adds a `--` placeholder right after the script string to consume the `$0` slot (so every real file lands in `"$@"`), and replaces the per-file loop with one that just builds a path-stripped array, then calls prettier once with the full file list.
### TESTING INSTRUCTIONS
Verified the bug and the fix empirically:
```
$ bash -c 'echo "0=$0"; for file in "$@"; do echo "loop got: $file"; done' fileA.tsx fileB.tsx fileC.tsx
0=fileA.tsx
loop got: fileB.tsx
loop got: fileC.tsx
```
Confirms `fileA.tsx` never reaches the loop under the old entry.
After the fix, with a placeholder consuming `$0`, all files land in the array and get passed to a single `prettier --write` call:
```
$ bash -c 'cd superset-frontend && files=(); for f in "$@"; do files+=("${f#superset-frontend/}"); done; npx --yes prettier@3.8.4 --write "${files[@]}"' -- superset-frontend/src/testdir/a.tsx superset-frontend/src/testdir/b.tsx
src/testdir/a.tsx 31ms
src/testdir/b.tsx 2ms
```
Both test files (deliberately malformed) came back correctly formatted in one prettier invocation.
### ADDITIONAL INFORMATION
- [ ] Has associated issue:
- [ ] Required feature flags:
- [ ] Changes UI
- [ ] Includes DB Migration (follow approval process in [SIP-59](https://github.com/apache/superset/issues/13351))
- [ ] Migration is atomic, supports rollback & is backwards-compatible
- [ ] Confirm DB migration upgrade and downgrade tested
- [ ] Runtime estimates and downtime expectations provided
- [ ] Introduces new feature or API
- [ ] Removes existing feature or API
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(pre-commit): prettier hook drops first file and never batches [superset]
Posted by "bito-code-review[bot] (via GitHub)" <gi...@apache.org>.
bito-code-review[bot] commented on PR #41944:
URL: https://github.com/apache/superset/pull/41944#issuecomment-4940278145
<!-- Bito Reply -->
The change correctly implements the `--` separator in the `prettier-frontend` hook within `.pre-commit-config.yaml`. By collecting the filenames into an array and passing them after the `--` separator, the command ensures that any files with names starting with hyphens are treated as positional arguments rather than CLI flags, preventing potential execution errors.
**.pre-commit-config.yaml**
```
entry: bash -c 'cd superset-frontend && files=(); for f in "$@"; do files+=("${f#superset-frontend/}"); done; npx prettier --write "${files[@]}"' --
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(pre-commit): prettier hook drops first file and never batches [superset]
Posted by "bito-code-review[bot] (via GitHub)" <gi...@apache.org>.
bito-code-review[bot] commented on PR #41944:
URL: https://github.com/apache/superset/pull/41944#issuecomment-4942119400
AI Code Review is in progress (usually takes 3 to 15 minutes unless it's a very large PR).
<details>
<summary>
Bito Usage Guide
</summary>
**Commands**
Type the following command in the pull request comment and save the comment.
- `/review` - Manually triggers a full AI review.
- `/pause` - Pauses automatic reviews on this pull request.
- `/resume` - Resumes automatic reviews.
- `/resolve` - Marks all Bito-posted review comments as resolved.
- `/abort` - Cancels all in-progress reviews.
Refer to the <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/available-commands" target="_blank" rel="noopener noreferrer">documentation</a> for additional commands.
**Configuration**
This repository uses `Superset` You can customize the agent settings <a href="https://alpha.bito.ai/home/ai-agents/code-review-agent" target="_blank" rel="noopener noreferrer">here</a> or contact your Bito workspace admin at evan@preset.io.
**Documentation & Help**
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/getting-started/install-run-using-bito-cloud/create-or-customize-an-agent-instance" target="_blank" rel="noopener noreferrer">Customize agent settings</a>
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/implementing-custom-code-review-rules" target="_blank" rel="noopener noreferrer">Review rules</a>
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent" target="_blank" rel="noopener noreferrer">General documentation</a>
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/faqs" target="_blank" rel="noopener noreferrer">FAQ</a>
</details>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(pre-commit): prettier hook drops first file and never batches [superset]
Posted by "bito-code-review[bot] (via GitHub)" <gi...@apache.org>.
bito-code-review[bot] commented on PR #41944:
URL: https://github.com/apache/superset/pull/41944#issuecomment-4940149590
AI Code Review is in progress (usually takes 3 to 15 minutes unless it's a very large PR).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(pre-commit): prettier hook drops first file and never batches [superset]
Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #41944:
URL: https://github.com/apache/superset/pull/41944#discussion_r3562473336
##########
.pre-commit-config.yaml:
##########
@@ -63,7 +63,7 @@ repos:
hooks:
- id: prettier-frontend
name: prettier (frontend)
- entry: bash -c 'cd superset-frontend && for file in "$@"; do npx prettier --write "${file#superset-frontend/}"; done'
+ entry: bash -c 'cd superset-frontend && files=(); for f in "$@"; do files+=("${f#superset-frontend/}"); done; npx prettier --write "${files[@]}"' --
Review Comment:
When invoking Prettier with a list of files, add a `--` end-of-options separator before the filenames so a file whose basename starts with `-`/`--` can’t be interpreted as a CLI option (e.g. `--plugin=...`). Without this, a specially-named file under `superset-frontend/` could cause Prettier to treat it as a flag instead of a path, breaking the hook and potentially changing execution behavior.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(pre-commit): prettier hook drops first file and never batches [superset]
Posted by "hainenber (via GitHub)" <gi...@apache.org>.
hainenber merged PR #41944:
URL: https://github.com/apache/superset/pull/41944
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org