Skip to content

Add support for # fmt: skip directives - #223

Merged
lionel- merged 5 commits into
mainfrom
feature/suppression
Feb 21, 2025
Merged

lionel- merged 5 commits into
mainfrom
feature/suppression

Conversation

@DavisVaughan

@DavisVaughan DavisVaughan commented Feb 13, 2025 •

Copy link
Copy Markdown
Collaborator

Closes #52

Motivating examples, until we add "official" support for these with fmt: tabular or fmt: align-right or something:

# fmt: skip
list(
  this      = 1,
  that      = 2,
  thisthing = 3,
  thatthing = 4,
  andthis   = 5
)

# fmt: skip
tribble(
  ~a, ~b,
   1,  2
)

Note that format directives are applied at the node level, meaning they are applied to whatever node the comment gets attached to (as determined by place_comment() in the formatter). If a node is skipped, all of its children are also skipped.

@lionel- I'm definitely open to more tests cases if you can think of any

@lionel- I went ahead and added a changelog bullet and some docs on # fmt: skip file, it felt weird to talk about just # fmt skip knowing we are about to add this too. I've also gone ahead and added FormatDirective::SkipFile. In the end it felt like a separate directive than FormatDirective::Skip rather than an argument to that one. I'd also be open to # fmt: skip-file if you like that better.

@DavisVaughan
DavisVaughan marked this pull request as ready for review February 13, 2025 20:59
@DavisVaughan
DavisVaughan requested a review from lionel- February 13, 2025 20:59
Comment thread docs/formatter.qmd Outdated

`# fmt: skip file` skips the entire file.
This must be placed at the top of the file before the first non-comment R code, otherwise the comment is ignored.
Use this for generated files, or as an alternative to `exclude` for individual files that you know you'd like to exclude from formatting.

@etiennebacher etiennebacher Feb 14, 2025 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very happy to see this land in air! I was just taking a look at how this is implemented and noticed something unclear to me in the docs.

Is the sentence about generated files actually useful for end users? It seems to me that people who develop frameworks should include this in the generated files, but end users shouldn't since it will be overwritten next time the file is generated. The example following this paragraph is also a bit confusing in this regard.

Comment thread crates/comments/src/directive.rs Resolved
Comment thread docs/formatter.qmd Resolved
Comment thread docs/formatter.qmd Resolved
@lionel-
lionel- force-pushed the feature/suppression branch from 0058a31 to 84d451e Compare February 21, 2025 11:00
@lionel-
lionel- merged commit 9c65bd6 into main Feb 21, 2025
@lionel-
lionel- deleted the feature/suppression branch February 21, 2025 11:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add suppression comment support

3 participants