Implement exclude and default-excludes TOML options#213
Merged
DavisVaughan merged 17 commits intomainfrom Feb 10, 2025
Merged
Conversation
lionel-
approved these changes
Feb 10, 2025
a9332e5 to
2ee91ed
Compare
…nts()` method `matched_path_or_any_parents()` assumes you have provided a `root`, and it enforces this assumption by requiring that, after root stripping, `path` cannot contain root-like components, including a leading `/` on Unix and leading `C:/` on Windows. This is a reasonable restriction for ignore, but we've asserted that all of our patterns are root-agnostic by requiring `**/`, so we have to have a custom implementation that throws this check away.
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 #128
This PR adds support for including and excluding files from the formatter using
.gitignorestyle patterns. There are 2 new options you can set inair.toml:exclude, i.e.exclude = ["renv/", "my-generated-file.R"]default-excludes, a boolean, defaults totrueAir now comes pre-loaded with a set of default files and folders to exclude, I will call them out inline below. If you'd like to format these files, you can set
default-excludes = false, but I imagine this will be extremely rare.The option name
I know we talked about naming this option
ignoreto match.gitignore, but both cargo and ruff have bothincludeandexcludeas TOML options which has a very nice symmetry in the naming scheme. Internally we have switched to also using anincludeoption that mirrorsexclude. In the future I think it is possible we will want to exposeinclude, it would be very easy to do so, particularly if we ever support Rmd or Qmd documents natively.gitignore syntax
Using
.gitignoreas the syntax rather than "standard" unix globs is quite nice. Mostly it gets us the ability to specify"file.R"as an equivalent to"**/file.R", andfolder/as an equivalent to**/folder/, which is likely a high proportion of real use cases. This is all implemented using theignorecrate, which I've learned cargo itself also uses for the exact same purposes as us.CLI
In the CLI, our parallel file discovery walker has gained the ability to include or exclude files based on these glob patterns. This ends up working really well, and is the exact same use case that ripgrep has, so everything wires up quite nicely. Since we walk down the directory tree, if we see that
foo/renv/is a directory to exclude, we never even walk into that directory, we just skip it entirely.LSP
The LSP is different from the CLI because we aren't discovering files, we are provided a full file path and are asked if we should format that particular file or not. This means that for
foo/renv/activate.R, we need to checkfoo/,foo/renv/andfoo/renv/activate.Rto see if any of those paths are excluded by a glob. Luckilyignorehas a method for this, but it is worth keeping in mind how different this is than the CLI method.