diff --git a/.github/workflows/lint-changed-files.yaml b/.github/workflows/lint-changed-files.yaml new file mode 100644 index 0000000000..d57b6ed4fd --- /dev/null +++ b/.github/workflows/lint-changed-files.yaml @@ -0,0 +1,53 @@ +on: + pull_request: + branches: + - main + - master + +name: lint-changed-files + +jobs: + lint-changed-files: + runs-on: macOS-latest + env: + GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + steps: + - uses: actions/checkout@v2 + + - uses: r-lib/actions/setup-r@v1 + + - name: Query dependencies + run: | + install.packages('remotes') + saveRDS(remotes::dev_package_deps(dependencies = TRUE), ".github/depends.Rds", version = 2) + writeLines(sprintf("R-%i.%i", getRversion()$major, getRversion()$minor), ".github/R-version") + shell: Rscript {0} + + - name: Cache R packages + uses: actions/cache@v2 + with: + path: ${{ env.R_LIBS_USER }} + key: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-${{ hashFiles('.github/depends.Rds') }} + restore-keys: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1- + + - name: Install dependencies + run: | + install.packages(c("remotes")) + remotes::install_deps(dependencies = TRUE) + remotes::install_cran("gh") + remotes::install_github("jimhester/lintr") + remotes::install_cran("purrr") + shell: Rscript {0} + + - name: Add lintr options + run: cat('\noptions(lintr.linter_file = ".lintr_new")\n', file = "~/.Rprofile", append = TRUE) + shell: Rscript {0} + + - name: Extract and lint files changed by this PR + run: | + files <- gh::gh("GET https://api.github.com/repos/jimhester/lintr/pulls/${{ github.event.pull_request.number }}/files") + changed_files <- purrr::map_chr(files, "filename") + all_files <- list.files(recursive = TRUE) + exclusions_list <- as.list(setdiff(all_files, changed_files)) + lintr::lint_package(exclusions = exclusions_list) + shell: Rscript {0} diff --git a/.lintr_new b/.lintr_new new file mode 100644 index 0000000000..a8be72455b --- /dev/null +++ b/.lintr_new @@ -0,0 +1,10 @@ +linters: with_defaults( + line_length_linter = line_length_linter(120) + ) +exclusions: list( + "tests/testthat/dummy_packages", + "tests/testthat/knitr_formats", + "tests/testthat/knitr_malformed", + "inst", + "vignettes" + ) diff --git a/NEWS.md b/NEWS.md index 836ef2c305..f047df08f4 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,6 @@ # lintr (development version) +* Added a secondary, more restrictive lint workflow - `lint-changed-files` - for newly written / modified code (#641, @dragosmg) * Switched CI from Travis to GitHub Actions, using the full tidyverse recommended R CMD check. Code coverage and linting are implemented using separate GitHub Actions workflows (#572, @dragosmg) * `save_cache` will now recursively create the cache directory; this avoids errors that could arise if any parent directories do not exist (#60, @dankessler). * `extract_r_source` handles Rmd containing unevaluated code blocks with named