-
Notifications
You must be signed in to change notification settings - Fork 824
prettier: set pass_filenames: false to avoid multiple passes
#6690
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
base: master
Are you sure you want to change the base?
Conversation
Updated `.prettierignore` to ingnore the typical Python environment files from `.venv` If you are running pre-commit locally you probably have a Python environment setup. This PR speeds up the prettier hook and avoids multiple passes through the targetted files.
Summary of ChangesHello @jbampton, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request optimizes the Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
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.
Code Review
This pull request aims to fix an issue where the prettier pre-commit hook processes files multiple times by setting pass_filenames: false. It also correctly adds the .venv directory to .prettierignore.
While setting pass_filenames: false is the right direction, the current implementation is incomplete and will likely cause the prettier hook to fail by hanging in CI. A corresponding change to the hook's entry is required to make prettier scan for files correctly. I've left a detailed comment explaining the necessary fix. Once that is addressed, this PR will be a great improvement to the project's tooling.
Updated
.prettierignoreto ignore the typical Python environment files from.venvIf you are running pre-commit locally you probably have a Python environment setup.
This PR speeds up the prettier hook and avoids multiple passes through the targetted files.
If you have a look at this job run:
https://github.com/mruby/mruby/actions/runs/20506201194/job/58921074132
You will see that the pre-commit manual hooks failed for the prettier check.
You can see there in the list of files under the prettier failed hook that there is the main group of files but they are repeated about 4 times in the list. So prettier is doing about 4 passes through file list and extra over head etc.
And now my terminal log with a git explanation of how I tested this by adding 3 extra lines to the end of
docker-compose.ymland then running prettier locally and the files list is only printed once as in each file path is listed only once. Right at the end of the list only thedocker composefile was formattedFrom Google:
"When to use pass_filenames: false
Directory-based linters/tools: Some tools, especially in languages like Go or Terraform, perform analysis based on the entire directory context. Passing individual files can lead to false positives (e.g., "unused symbol" errors).
Tools that manage their own file discovery: If your hook's entry command (e.g., a Makefile target or a specific CLI tool) already finds the required files to check, you should set pass_filenames: false to avoid passing extra command-line arguments that the tool might not handle correctly.
Performance: For large codebases, running a tool on the whole project (pass_filenames: false) might be slow. The default pass_filenames: true behavior is often recommended for faster local checks, as it only runs on the changed files.
Hooks that use always_run: true: When a hook is set to run regardless of which files have changed, you often also set pass_filenames: false so that the command runs once on the entire project as intended."
So the prettier hook uses an entry command that finds its own files:
mruby/.pre-commit-config.yaml
Line 23 in 9f0950d