Skip to content

Commit

Permalink
Merge branch 'main' into allow-fn-brace
Browse files Browse the repository at this point in the history
  • Loading branch information
salim-b committed Jul 13, 2024
2 parents 9e1568c + 73e55d3 commit 9fe4c56
Show file tree
Hide file tree
Showing 119 changed files with 1,110 additions and 728 deletions.
5 changes: 0 additions & 5 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,9 @@ jobs:
- {os: macOS-latest, r: 'release'}

- {os: windows-latest, r: 'release'}
# Use 3.6 to trigger usage of RTools35
- {os: windows-latest, r: '3.6'}
# use 4.1 to check with rtools40's older compiler
- {os: windows-latest, r: '4.1'}

# Use older ubuntu to maximise backward compatibility
- {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'}
- {os: ubuntu-latest, r: 'devel', http-user-agent: 'release', locale: 'en_US'}
- {os: ubuntu-latest, r: 'release', http-user-agent: 'release', locale: 'zh_CN'}
Expand All @@ -43,7 +40,6 @@ jobs:
- {os: ubuntu-latest, r: 'oldrel-2'}
- {os: ubuntu-latest, r: 'oldrel-3'}
- {os: ubuntu-latest, r: 'oldrel-4'}
- {os: ubuntu-latest, r: '3.6'}

env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
Expand Down Expand Up @@ -72,7 +68,6 @@ jobs:
http-user-agent: ${{ matrix.config.http-user-agent }}
use-public-rspm: true

# `{patrick}` imports `{purrr}`, and so needs to be ignored on R < 3.5
- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: |
Expand Down
10 changes: 6 additions & 4 deletions .github/workflows/check-all-examples.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@

on:
push:
branches: [main, master]
branches: main
pull_request:
branches: [main, master]
branches: main

name: check-all-examples

Expand All @@ -32,11 +32,13 @@ jobs:
with:
pak-version: devel
extra-packages: |
any::devtools
any::pkgload
local::.
- name: Run examples
run: |
options(crayon.enabled = TRUE)
devtools::run_examples(fresh = TRUE, run_dontrun = TRUE, run_donttest = TRUE)
pkgload::load_all()
setwd("man")
for (rd in list.files(pattern = "\\.Rd")) pkgload::run_example(rd, run_dontrun = TRUE, run_donttest = TRUE, quiet = TRUE)
shell: Rscript {0}
1 change: 1 addition & 0 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ jobs:
- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: |
any::cyclocomp
r-lib/lintr
local::.
needs: lint
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pkgdown.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:

- name: Deploy to GitHub pages 🚀
if: github.event_name != 'pull_request'
uses: JamesIves/github-pages-deploy-action@v4.5.0
uses: JamesIves/github-pages-deploy-action@v4.6.3
with:
clean: false
branch: gh-pages
Expand Down
71 changes: 71 additions & 0 deletions .github/workflows/test-coverage-examples.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
on:
schedule:
# * is a special character in YAML so you have to quote this string
# Trigger once a month at 10:00 on the first day of every month
- cron: "00 10 1 * *"

name: test-coverage-examples

jobs:
test-coverage-examples:
runs-on: ubuntu-latest
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}

steps:
- uses: actions/checkout@v4

- uses: r-lib/actions/setup-r@v2
with:
use-public-rspm: true

- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: |
any::covr
local::.
- name: Test example coverage
run: |
options(crayon.enabled = TRUE)
library(covr)
files_to_exclude <- c(
# examples present but not run
"R/lint.R",
"R/use_lintr.R",
# mostly internal utilities
"R/actions.R",
"R/cache.R",
"R/deprecated.R",
"R/exclude.R",
"R/extract.R",
"R/ids_with_token.R",
"R/lintr-deprecated.R",
"R/make_linter_from_regex.R",
"R/make_linter_from_xpath.R",
"R/namespace.R",
"R/methods.R",
"R/settings.R",
"R/shared_constants.R",
"R/with.R",
"R/with_id.R",
"R/zzz.R"
)
coverage <- covr::package_coverage(
type = "examples",
quiet = TRUE,
commentDonttest = FALSE,
commentDontrun = FALSE,
line_exclusions = files_to_exclude
)
print(coverage)
percent_coverage <- as.integer(covr::percent_coverage(coverage))
threshold <- 90
cli::cli_rule()
if (percent_coverage < threshold) {
cli::cli_abort("Code coverage using examples ({percent_coverage}%) is below the required threshold ({threshold}%).")
} else {
cli::cli_alert_success("Code coverage using examples ({percent_coverage}%) is above the required threshold ({threshold}%).")
}
cli::cli_rule()
shell: Rscript {0}
8 changes: 7 additions & 1 deletion .github/workflows/test-package-vigilant.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,13 @@ jobs:
- name: Run Tests
run: |
## --------------------------------------------------------------------
options(crayon.enabled = TRUE, warn = 2L)
options(
crayon.enabled = TRUE,
warn = 2L,
warnPartialMatchArgs = TRUE,
warnPartialMatchAttr = TRUE,
warnPartialMatchDollar = TRUE
)
if (Sys.getenv("_R_CHECK_FORCE_SUGGESTS_", "") == "") Sys.setenv("_R_CHECK_FORCE_SUGGESTS_" = "false")
testthat::test_dir("tests")
shell: Rscript {0}
8 changes: 7 additions & 1 deletion .lintr
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ linters: all_linters(
undesirable_function_linter(modify_defaults(
defaults = default_undesirable_functions,
library = NULL,
options = NULL
options = NULL,
message = "use cli::cli_inform()",
warning = "use cli::cli_warn()",
stop = "use cli::cli_abort()",
normalizePath = "use normalize_path()"
)),
undesirable_operator_linter(modify_defaults(
defaults = default_undesirable_operators,
Expand All @@ -25,6 +29,8 @@ linters: all_linters(
absolute_path_linter = NULL,
library_call_linter = NULL,
nonportable_path_linter = NULL,
# We now require R>=4.0.0
strings_as_factors_linter = NULL,
todo_comment_linter = NULL,
# TODO(#2327): Enable this.
unreachable_code_linter = NULL
Expand Down
2 changes: 1 addition & 1 deletion COPYING
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2014-2022, James Hester
Copyright (c) 2014-2024, James Hester

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
Expand Down
11 changes: 6 additions & 5 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: lintr
Title: A 'Linter' for R Code
Version: 3.1.1.9000
Version: 3.1.2.9000
Authors@R: c(
person("Jim", "Hester", , role = "aut"),
person("Florent", "Angly", role = "aut",
Expand All @@ -18,14 +18,14 @@ Description: Checks adherence to a given style, syntax errors and possible
'RStudio IDE', 'Emacs', 'Vim', 'Sublime Text', 'Atom' and 'Visual
Studio Code'.
License: MIT + file LICENSE
URL: https://github.com/r-lib/lintr, https://lintr.r-lib.org
URL: https://lintr.r-lib.org, https://github.com/r-lib/lintr
BugReports: https://github.com/r-lib/lintr/issues
Depends:
R (>= 3.6)
R (>= 4.0)
Imports:
backports (>= 1.1.7),
cli (>= 3.4.0),
codetools,
cyclocomp,
digest,
glue,
knitr,
Expand All @@ -36,7 +36,7 @@ Imports:
xmlparsedata (>= 1.0.5)
Suggests:
bookdown,
cli,
cyclocomp,
jsonlite,
patrick (>= 0.2.0),
rlang,
Expand Down Expand Up @@ -202,6 +202,7 @@ Collate:
'with.R'
'with_id.R'
'xml_nodes_to_lints.R'
'xml_utils.R'
'yoda_test_linter.R'
'zzz.R'
Language: en-US
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
YEAR: 2014-2016
YEAR: 2014-2024
COPYRIGHT HOLDER: James Hester
12 changes: 5 additions & 7 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
# Generated by roxygen2: do not edit by hand


if (getRversion() >= "4.0.0") {
importFrom(tools, R_user_dir)
} else {
importFrom(backports, R_user_dir)
}
S3method("[",lints)
S3method(as.data.frame,lints)
S3method(format,lint)
Expand Down Expand Up @@ -57,6 +51,7 @@ export(expect_length_linter)
export(expect_lint)
export(expect_lint_free)
export(expect_named_linter)
export(expect_no_lint)
export(expect_not_linter)
export(expect_null_linter)
export(expect_s3_class_linter)
Expand Down Expand Up @@ -171,7 +166,9 @@ export(with_id)
export(xml_nodes_to_lints)
export(xp_call_name)
export(yoda_test_linter)
importFrom(cyclocomp,cyclocomp)
importFrom(cli,cli_abort)
importFrom(cli,cli_inform)
importFrom(cli,cli_warn)
importFrom(glue,glue)
importFrom(glue,glue_collapse)
importFrom(rex,character_class)
Expand All @@ -180,6 +177,7 @@ importFrom(rex,re_substitutes)
importFrom(rex,regex)
importFrom(rex,rex)
importFrom(stats,na.omit)
importFrom(tools,R_user_dir)
importFrom(utils,capture.output)
importFrom(utils,getParseData)
importFrom(utils,getTxtProgressBar)
Expand Down
20 changes: 19 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,19 @@
* Adjusted various lint messages for consistency in readability (#1330, @MichaelChirico). In general, we favor lint messages to be phrased like "Action, reason" to but the "what" piece of the message front-and-center. This may be a breaking change for code that tests the specific phrasing of lints.
* `extraction_operator_linter()` is deprecated. Although switching from `$` to `[[` has some robustness benefits for package code, it can lead to non-idiomatic code in many contexts (e.g. R6 classes, Shiny applications, etc.) (#2409, @IndrajeetPatil). To enable the detection of the `$` operator for extraction through partial matching, use `options(warnPartialMatchDollar = TRUE)`.
* `unnecessary_nested_if_linter()` is deprecated and subsumed into the new/more general `unnecessary_nesting_linter()`.
* Drop support for posting GitHub comments from inside Travis, Wercker, and Jenkins CI tools (spurred by #2148, @MichaelChirico). We rely on GitHub Actions for linting in CI, and don't see any active users relying on these alternatives. We welcome and encourage community contributions to get support for different CI system going again.
* Drop support for posting GitHub comments from inside GitHub comment bot, Travis, Wercker, and Jenkins CI tools (spurred by #2148, @MichaelChirico). We rely on GitHub Actions for linting in CI, and don't see any active users relying on these alternatives. We welcome and encourage community contributions to get support for different CI system going again.
* `cyclocomp_linter()` is no longer part of the default linters (#2555, @IndrajeetPatil) because the tidyverse style guide doesn't contain any guidelines on meeting certain complexity requirements. Note that users with `cyclocomp_linter()` in their configs may now need to install {cyclocomp} intentionally, in particular in CI/CD pipelines.
* `scalar_in_linter` is now configurable to allow other `%in%` like operators to be linted. The data.table operator `%chin%` is no longer linted by default; use `in_operators = "%chin%"` to continue linting it. (@F-Noelle)
* `lint()` and friends now normalize paths to forward slashes on Windows (@olivroy, #2613).

## Bug fixes

* `expect_identical_linter()` also skips `expect_equal()` comparison to _negative_ non-integers like `-1.034` (#2411, @Bisaloo). This is a parity fix since _positive_ reals have always been skipped because "high-precision" comparisons are typically done to get tests within `tolerance`, so `expect_identical()` is not a great substitution.
* `object_name_linter()` no longer errors when user-supplied `regexes=` have capture groups (#2188, @MichaelChirico).
* `.lintr` config validation correctly accepts regular expressions which only compile under `perl = TRUE` (#2375, @MichaelChirico). These have always been valid (since `rex::re_matches()`, which powers the lint exclusion logic, also uses this setting), but the new up-front validation in v3.1.1 incorrectly used `perl = FALSE`.
* `.lintr` configs set by option `lintr.linter_file` or environment variable `R_LINTR_LINTER_FILE` can point to subdirectories (#2512, @MichaelChirico).
* `indentation_linter()` returns `ranges[1L]==1L` when the offending line has 0 spaces (#2550, @MichaelChirico).
* `literal_coercion_linter()` doesn't surface a warning about NAs during coercion for code like `as.integer("a")` (#2566, @MichaelChirico).

## Changes to default linters

Expand Down Expand Up @@ -50,6 +56,9 @@
* `vector_logic_linter()` is extended to recognize incorrect usage of scalar operators `&&` and `||` inside subsetting expressions like `dplyr::filter(x, A && B)` (#2166, @MichaelChirico).
* `any_is_na_linter()` is extended to catch the unusual usage `NA %in% x` (#2113, @MichaelChirico).
* `brace_linter()`' has a new argument `function_bodies` (default `"multi_line"`) which controls whether to require function bodies to be wrapped in curly braces, with the options `"always"`, `"multi_line"` (only require curly braces when a function body spans over multiple lines), `"not_inline"` (only require curly braces when a function body starts on a new line) and `"never"` (#1807, #2240, @salim-b).
* `make_linter_from_xpath()` errors up front when `lint_message` is missing (instead of delaying this error until the linter is used, #2541, @MichaelChirico).
* `paste_linter()` is extended to recommend using `paste()` instead of `paste0()` for simply aggregating a character vector with `collapse=`, i.e., when `sep=` is irrelevant (#1108, @MichaelChirico).
* `expect_no_lint()` was added as new function to cover the typical use case of expecting no lint message, akin to the recent {testthat} functions like `expect_no_warning()` (#2580, @F-Noelle).

### New linters

Expand All @@ -72,6 +81,15 @@
* `one_call_pipe_linter()` for discouraging one-step pipelines like `x |> as.character()` (#2330 and part of #884, @MichaelChirico).
* `object_overwrite_linter()` for discouraging re-use of upstream package exports as local variables (#2344, #2346 and part of #884, @MichaelChirico and @AshesITR).

### Lint accuracy fixes: removing false positives

* `object_name_linter()` and `object_length_linter()` ignore {rlang} name injection like `x |> mutate("{new_name}" := foo(col))` (#1926, @MichaelChirico). No checking is applied in such cases. {data.table} in-place assignments like `DT[, "sPoNGeBob" := "friend"]` are still eligible for lints.

## Notes

* All user-facing messages are now prepared using the `{cli}` package (#2418, @IndrajeetPatil). All messages have been reviewed and updated to be more informative and consistent.
* {lintr} now depends on R version 4.0.0. It already does so implicitly due to recursive upstream dependencies requiring this version; we've simply made that dependency explicit and up-front (#2569, @MichaelChirico).

# lintr 3.1.2

## New and improved features
Expand Down
4 changes: 1 addition & 3 deletions R/absolute_path_linter.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
#' * contain at least two path elements, with one having at least two characters and
#' * contain only alphanumeric chars (including UTF-8), spaces, and win32-allowed punctuation
#'
#' @examplesIf getRversion() >= "4.0"
#' # Following examples use raw character constant syntax introduced in R 4.0.
#'
#' @examples
#' # will produce lints
#' lint(
#' text = 'R"--[/blah/file.txt]--"',
Expand Down
9 changes: 5 additions & 4 deletions R/addins.R
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
# nocov start
addin_lint <- function() {
if (!requireNamespace("rstudioapi", quietly = TRUE)) {
stop("'rstudioapi' is required for add-ins.", call. = FALSE)
cli_abort("{.pkg rstudioapi} is required for add-ins.")
}
filename <- rstudioapi::getSourceEditorContext()
if (filename$path == "") {
return("Current source has no path. Please save before continue")
cli_warn("Current source has no path. Please save before continuing.")
return(flatten_lints(list()))
}

lint(filename$path)
}

addin_lint_package <- function() {
if (!requireNamespace("rstudioapi", quietly = TRUE)) {
stop("'rstudioapi' is required for add-ins.", call. = FALSE)
cli_abort("{.pkg rstudioapi} is required for add-ins.")
}
project <- rstudioapi::getActiveProject()
if (is.null(project)) {
message("No project found, passing current directory")
cli_inform("No project found, passing current directory.")
project_path <- getwd()
} else {
project_path <- project
Expand Down
Loading

0 comments on commit 9fe4c56

Please sign in to comment.