nealrichardson / httptest2

Utilities for testing R 📦s that use httr2
https://enpiar.com/httptest2/
Other
26 stars 6 forks source link

Add ignore directives for formatter and linter for auto-generated `.R` files in `httptest2::with_mock_dir()` #43

Open IndrajeetPatil opened 3 weeks ago

IndrajeetPatil commented 3 weeks ago

Preamble

Is it possible to add directives to turn off formatter and linter for auto-generated .R files by httptest2::with_mock_dir()?

I work with CI systems that mark builds as failed if any lints or formatting issues are found. This is indeed going to be the case for these auto-generated files. But the code in these files need not follow a style guide or linter recommendations. Additionally, it's not even in the control of the user how this output is generated. Therefore, it would be nice if {httptest2} itself generated these files with ignore directives.

Solution

Tidyverse style guide formatter and linter can be turned off like so:

# nolint start
# styler: off

# add code for <httr2_response> class here
... 

# styler: on
# nolint end
nealrichardson commented 2 weeks ago

We could do that. If so, we'd need to put the change here: https://github.com/nealrichardson/httptest2/blob/main/R/capture-requests.R#L177 I would guess that would involve using deparse() instead of dput() to keep the result in a character vector, add the linter/styler comments to that, and then cat() to the file.

Alternatively, we could do something like this after L177:

if (requireNamespace("styler", quietly = TRUE)) {
  styler::style_file(f)
}

@IndrajeetPatil would you be interested in submitting a PR?

IndrajeetPatil commented 2 weeks ago

@nealrichardson Sure, I can take a stab at this next week :)