Respect exclude, default_exclude, and default_include with directly supplied files#476
Merged
DavisVaughan merged 12 commits intomainfrom Mar 13, 2026
Merged
Conversation
Merged
Merged
lionel-
approved these changes
Mar 12, 2026
01c6e33 to
634a933
Compare
1b6e414 to
3978563
Compare
Generated after Claude did a code review of this PR
3978563 to
5ce43e4
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #472
Closes #473
This PR solves two issues
(Note that I have not added
--forcehere, I did that in #478)Issue 1 - Directly supplied
exclude-ed pathspre-commit invokes air on any "changed" files and has no idea about air's
excluderules. So it will happily callif standalone-file.R changed (or was just added).
Similarly, RStudio will do this too when air is the external formatter, i.e. if you save in standalone-file.R then RStudio will call air on that file because RStudio doesn't know about exclude rules.
Before this PR, a directly supplied file on the command line like
air format standalone-file.Rwas formatted, even though ourdefault_excluderules would reject it.With this PR, we now silently ignore
standalone-file.Rand refuse to format it. Trace logs tell you that we refused it.ruff has also battled with this, but they took a different approach. They have
ruff format standalone-file.R --force-excludewhich "forcesexcluderules to be considered for paths directly supplied on the command line", but I think we should just change the default, because I don't think you'd ever really want this.Here are some examples, all of which we now ignore:
Issue 2 - Directly supplied non-
include-ed pathsA related but different issue is related to this call to air
No
excludeordefault_excluderule will exclude this, but we also don't have adefault_includerule that would include this (our default includes are just"**/*.[Rr]").Before this PR, we'd try to format this.
That has bitten many people who think air works on qmds and they have been very confused, especially if it happens to parse by accident, and then changes their qmd.
With this PR we now silently ignore this file.
This means that you can't do
air format trust-me.txtright now, but we will add a--forceflag in a follow up PR to allow this.