Skip to content

Commit

Permalink
update lint_dir to lint .qmd files by default; fixes #2150 (#2151)
Browse files Browse the repository at this point in the history
  • Loading branch information
dave-lovell authored Sep 15, 2023
1 parent 0d528cd commit 8d59c57
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 4 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* New `make_linter_from_xpath()` to facilitate making simple linters directly from a single XPath (#2064, @MichaelChirico). This is especially helpful for making on-the-fly/exploratory linters, but also extends to any case where the linter can be fully defined from a static lint message and single XPath.
* Toggle lint progress indicators with argument `show_progress` to `lint_dir()` and `lint_package()` (#972, @MichaelChirico). The default is still to show progress in `interactive()` sessions. Progress is also now shown with a "proper" progress bar (`utils::txtProgressBar()`), which in particular solves the issue of progress `.` spilling well past the width of the screen in large directories.
* `lint()`, `lint_dir()`, and `lint_package()` fail more gracefully when the user mis-spells an argument name (#2134, @MichaelChirico).
* Quarto files (.qmd) are included by `lint_dir()` by default (#2150, @dave-lovell).
* `fixed_regex_linter()`
+ Is pipe-aware, in particular removing false positives arong piping into {stringr} functions like `x |> str_replace(fixed("a"), "b")` (#1811, @MichaelChirico).
+ Gains an option `allow_unescaped` (default `FALSE`) to toggle linting regexes not requiring any escapes or character classes (#1689, @MichaelChirico). Thus `fixed_regex_linter(allow_unescaped = TRUE)` would lint on `grepl("[$]", x)` but not on `grepl("a", x)` since the latter does not use any regex special characters.
Expand Down
3 changes: 2 additions & 1 deletion R/lint.R
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ lint <- function(filename, linters = NULL, ..., cache = FALSE, parse_settings =
lint_dir <- function(path = ".", ...,
relative_path = TRUE,
exclusions = list("renv", "packrat"),
pattern = rex(".", one_of("Rr"), or("", "html", "md", "nw", "rst", "tex", "txt"), end),
pattern = rex(".", or(group(one_of("Rr"), or("", "html", "md", "nw", "rst", "tex", "txt")),
group(one_of("Qq"), "md")), end),
parse_settings = TRUE,
show_progress = NULL) {
if (has_positional_logical(list(...))) {
Expand Down
3 changes: 2 additions & 1 deletion man/lint.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

80 changes: 80 additions & 0 deletions tests/testthat/dummy_packages/package/vignettes/test.Qmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# Test #

Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod
tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At
vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren,
no sea takimata sanctus est Lorem ipsum dolor sit amet.

```{r}
a = 1
```

Test
====

Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod
tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At
vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren,
no sea takimata sanctus est Lorem ipsum dolor sit amet.

```{r}
b <- function(x) {
d = 1
}
```

```{r engine="python"}
a=[]
a[0]=1
```

```
Plain code blocks can be written after three or more backticks
- R Markdown: The Definitive Guide. Xie, Allaire and Grolemund (2.5.2)
```

```r
# This is a non-evaluated block of R code for formatting in markdown.
# It should not be linted
abc = 123
```

```cpp
// Some C++ code for formatting by markdown

```

Calls to a non-R knitr-engine using {engine_name} syntax.

```{python}
# Python that looks like R
a = list()
b = {2}
print(a)
```

```{python}
# Python that's definitely not R
a = []
a.append(2)
print(a)
```

The following are only supported by Quarto and shouldn't lint either.

```{.r}
1+1
```

```{{r}}
1+1
```

```{.python}
# Python that's definitely not R
a = []
a.append(2)
print(a)
```
2 changes: 1 addition & 1 deletion tests/testthat/test-lint_dir.R
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ test_that("respect directory exclusions from settings", {
test_that("lint_dir works with specific linters without specifying other arguments", {
withr::local_options(lintr.linter_file = "lintr_test_config")
the_dir <- test_path("dummy_packages", "package", "vignettes")
expect_length(lint_dir(the_dir, assignment_linter(), parse_settings = FALSE), 12L)
expect_length(lint_dir(the_dir, assignment_linter(), parse_settings = FALSE), 14L)
expect_length(lint_dir(the_dir, commented_code_linter(), parse_settings = FALSE), 0L)
})

Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-object_usage_linter.R
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ test_that("global variable detection works", {
test_that("package detection works", {
expect_length(
lint_package(test_path("dummy_packages", "package"), linters = object_usage_linter(), parse_settings = FALSE),
9L
10L
)
})

Expand Down

0 comments on commit 8d59c57

Please sign in to comment.