Skip to content

Respect exclude, default_exclude, and default_include with directly supplied files#476

Merged
DavisVaughan merged 12 commits intomainfrom
feature/respect-exclude-include
Mar 13, 2026
Merged

Respect exclude, default_exclude, and default_include with directly supplied files#476
DavisVaughan merged 12 commits intomainfrom
feature/respect-exclude-include

Conversation

@DavisVaughan
Copy link
Collaborator

@DavisVaughan DavisVaughan commented Mar 6, 2026

Closes #472
Closes #473

This PR solves two issues

(Note that I have not added --force here, I did that in #478)

Issue 1 - Directly supplied exclude-ed paths

pre-commit invokes air on any "changed" files and has no idea about air's exclude rules. So it will happily call

air format standalone-file.R

if 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.R was formatted, even though our default_exclude rules would reject it.

With this PR, we now silently ignore standalone-file.R and 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-exclude which "forces exclude rules 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:

# [format]
# exclude = ["notme/"]
air format notme
# [format]
# exclude = ["notme/"]
air format notme/subdir/
# [format]
# exclude = ["notme/"]
air format notme/file.R
# [format]
# default_exclude = ["**/cpp11.R"]
air format cpp11.R

Issue 2 - Directly supplied non-include-ed paths

A related but different issue is related to this call to air

air format my-quarto.qmd

No exclude or default_exclude rule will exclude this, but we also don't have a default_include rule 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.txt right now, but we will add a --force flag in a follow up PR to allow this.

@DavisVaughan DavisVaughan requested a review from lionel- March 6, 2026 19:50
@DavisVaughan DavisVaughan mentioned this pull request Mar 9, 2026
@DavisVaughan DavisVaughan force-pushed the feature/respect-exclude-include branch 2 times, most recently from 1b6e414 to 3978563 Compare March 13, 2026 17:08
Base automatically changed from feature/stdin to main March 13, 2026 17:23
@DavisVaughan DavisVaughan force-pushed the feature/respect-exclude-include branch from 3978563 to 5ce43e4 Compare March 13, 2026 17:25
@DavisVaughan DavisVaughan merged commit d3ceeb6 into main Mar 13, 2026
6 checks passed
@DavisVaughan DavisVaughan deleted the feature/respect-exclude-include branch March 13, 2026 17:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants