Skip to content

Commit

Permalink
Merge branch 'master' into ns-hooks-redux
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelChirico authored Nov 30, 2020
2 parents 3604f9c + b4e3f72 commit b9587dd
Show file tree
Hide file tree
Showing 12 changed files with 238 additions and 46 deletions.
1 change: 1 addition & 0 deletions .github/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.html
100 changes: 100 additions & 0 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
on:
push:
branches:
- main
- master
pull_request:
branches:
- main
- master

name: R-CMD-check

jobs:
R-CMD-check:
runs-on: ${{ matrix.config.os }}

name: ${{ matrix.config.os }} (${{ matrix.config.r }})

strategy:
fail-fast: false
matrix:
config:
- {os: macOS-latest, r: 'release'}
- {os: windows-latest, r: 'release'}
- {os: windows-latest, r: '3.6'}
- {os: ubuntu-16.04, r: 'devel', rspm: "https://packagemanager.rstudio.com/cran/__linux__/xenial/latest", http-user-agent: "R/4.0.0 (ubuntu-16.04) R (4.0.0 x86_64-pc-linux-gnu x86_64 linux-gnu) on GitHub Actions" }
- {os: ubuntu-16.04, r: 'release', rspm: "https://packagemanager.rstudio.com/cran/__linux__/xenial/latest"}
- {os: ubuntu-16.04, r: 'oldrel', rspm: "https://packagemanager.rstudio.com/cran/__linux__/xenial/latest"}
- {os: ubuntu-16.04, r: '3.5', rspm: "https://packagemanager.rstudio.com/cran/__linux__/xenial/latest"}
- {os: ubuntu-16.04, r: '3.4', rspm: "https://packagemanager.rstudio.com/cran/__linux__/xenial/latest"}
- {os: ubuntu-16.04, r: '3.3', rspm: "https://packagemanager.rstudio.com/cran/__linux__/xenial/latest"}

env:
R_REMOTES_NO_ERRORS_FROM_WARNINGS: true
RSPM: ${{ matrix.config.rspm }}
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}

steps:
- uses: actions/checkout@v2

- uses: r-lib/actions/setup-r@v1
with:
r-version: ${{ matrix.config.r }}
http-user-agent: ${{ matrix.config.http-user-agent }}

- uses: r-lib/actions/setup-pandoc@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
if: runner.os != 'Windows'
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 system dependencies
if: runner.os == 'Linux'
run: |
while read -r cmd
do
eval sudo $cmd
done < <(Rscript -e 'writeLines(remotes::system_requirements("ubuntu", "16.04"))')
- name: Install dependencies
run: |
remotes::install_deps(dependencies = TRUE)
remotes::install_cran("rcmdcheck")
shell: Rscript {0}

- name: Session info
run: |
options(width = 100)
pkgs <- installed.packages()[, "Package"]
sessioninfo::session_info(pkgs, include_base = TRUE)
shell: Rscript {0}

- name: Check
env:
_R_CHECK_CRAN_INCOMING_: false
run: rcmdcheck::rcmdcheck(args = c("--no-manual", "--as-cran"), error_on = "warning", check_dir = "check")
shell: Rscript {0}

- name: Show testthat output
if: always()
run: find check -name 'testthat.Rout*' -exec cat '{}' \; || true
shell: bash

- name: Upload check results
if: failure()
uses: actions/upload-artifact@main
with:
name: ${{ runner.os }}-r${{ matrix.config.r }}-results
path: check
47 changes: 47 additions & 0 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
on:
push:
branches:
- main
- master
- "**"
pull_request:
branches:
- main
- master

name: lint

jobs:
lint:
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_github("jimhester/lintr")
shell: Rscript {0}

- name: Lint
run: lintr::lint_package()
shell: Rscript {0}
49 changes: 49 additions & 0 deletions .github/workflows/test-coverage.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
on:
push:
branches:
- main
- master
- '**'
pull_request:
branches:
- main
- master

name: test-coverage

jobs:
test-coverage:
runs-on: macOS-latest
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v2

- uses: r-lib/actions/setup-r@v1

- uses: r-lib/actions/setup-pandoc@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("covr")
shell: Rscript {0}

- name: Test coverage
run: covr::codecov()
shell: Rscript {0}
1 change: 0 additions & 1 deletion .lintr
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
linters: with_defaults( # The following TODOs are part of an effort to have {lintr} lint-free (#584)
line_length_linter = line_length_linter(120),
infix_spaces_linter = NULL, # TODO enable (#594)
commented_code_linter = NULL, # TODO enable (#595)
cyclocomp_linter = cyclocomp_linter(29), # TODO reduce to 15
object_name_linter = NULL, # TODO enable (#597)
spaces_inside_linter = NULL, # TODO enable (#598)
Expand Down
25 changes: 0 additions & 25 deletions .travis.yml

This file was deleted.

1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# lintr (development version)

* 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
format specifiers (#472, @russHyde)
Expand Down
20 changes: 10 additions & 10 deletions R/get_source_expressions.R
Original file line number Diff line number Diff line change
Expand Up @@ -327,16 +327,16 @@ fix_column_numbers <- function(content) {
# getParseData() counts 1 tab as a variable number of spaces instead of one:
# https://github.com/wch/r-source/blame/e7401b68ab0e032fce3e376aaca9a5431619b2b4/src/main/gram.y#L512
# The number of spaces is so that the code is brought to the next 8-character indentation level e.g:
# "1\t;" -> "1 ;"
# "12\t;" -> "12 ;"
# "123\t;" -> "123 ;"
# "1234\t;" -> "1234 ;"
# "12345\t;" -> "12345 ;"
# "123456\t;" -> "123456 ;"
# "1234567\t;" -> "1234567 ;"
# "12345678\t;" -> "12345678 ;"
# "123456789\t;" -> "123456789 ;"
# "1234567890\t;" -> "1234567890 ;"
# "1\t;" --> "1 ;"
# "12\t;" --> "12 ;"
# "123\t;" --> "123 ;"
# "1234\t;" --> "1234 ;"
# "12345\t;" --> "12345 ;"
# "123456\t;" --> "123456 ;"
# "1234567\t;" --> "1234567 ;"
# "12345678\t;" --> "12345678 ;"
# "123456789\t;" --> "123456789 ;"
# "1234567890\t;" --> "1234567890 ;"
fix_tab_indentations <- function(source_file) {
pc <- getParseData(source_file)

Expand Down
28 changes: 22 additions & 6 deletions R/spaces_left_parentheses_linter.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@ spaces_left_parentheses_linter <- function(source_file) {

parsed <- source_file$parsed_content[id, ]

terminal_tokens_before <-
source_file$parsed_content$token[
source_file$parsed_content$line1 == parsed$line1 &
source_file$parsed_content$col1 < parsed$col1 &
source_file$parsed_content$terminal]
terminal_tokens_before <- with(
source_file$parsed_content,
token[line1 == parsed$line1 & col1 < parsed$col1 & terminal]
)
last_type <- tail(terminal_tokens_before, n = 1)

is_function <- length(last_type) %!=% 0L &&
Expand All @@ -24,7 +23,24 @@ spaces_left_parentheses_linter <- function(source_file) {
before_operator <- substr(line, parsed$col1 - 1L, parsed$col1 - 1L)

non_space_before <- re_matches(before_operator, rex(non_space))
not_exception <- !(before_operator %in% c("!", ":", "[", "("))
not_exception <- !(before_operator %in% c("!", ":", "[", "(", "^"))

# exception for unary - and unary +, #508
before_operator_idx <- with(
source_file$parsed_content,
col1 == parsed$col1 - 1L & col1 == col2
)
is_sibling_expr <- if (any(before_operator_idx)) {
with(
source_file$parsed_content,
token == "expr" & parent == parent[before_operator_idx]
)
} else {
rep(FALSE, nrow(source_file$parsed_content))
}
not_exception <- not_exception &&
!(before_operator %in% c("-", "+") &&
nrow(source_file$parsed_content[is_sibling_expr, ]) == 1L)

if (non_space_before && not_exception) {
Lint(
Expand Down
6 changes: 3 additions & 3 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,9 @@ escape_chars <- c(
"\\f" = "\f", # form feed
"\\v" = "\v" # vertical tab
# dynamically-added:
#"\\'" = "'", # ASCII apostrophe
#"\\\"" = "\"", # ASCII quotation mark
#"\\`" = "`" # ASCII grave accent (backtick)
#"\\'" --> "'", # ASCII apostrophe
#"\\\"" --> "\"", # ASCII quotation mark
#"\\`" --> "`" # ASCII grave accent (backtick)
)

unescape <- function(str, q="`") {
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# lintr
[![Travis-CI Build Status](https://travis-ci.org/jimhester/lintr.svg?branch=master)](https://travis-ci.org/jimhester/lintr)
[![R build status](https://github.com/jimhester/lintr/workflows/R-CMD-check/badge.svg)](https://github.com/jimhester/lintr/actions)
[![codecov.io](https://codecov.io/github/jimhester/lintr/coverage.svg?branch=master)](https://codecov.io/github/jimhester/lintr?branch=master)
[![CRAN_Status_Badge](https://www.r-pkg.org/badges/version/lintr)](https://cran.r-project.org/package=lintr) [![Join the chat at https://gitter.im/jimhester-lintr/Lobby](https://badges.gitter.im/jimhester-lintr/Lobby.svg)](https://gitter.im/jimhester-lintr/Lobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)

Expand Down
4 changes: 4 additions & 0 deletions tests/testthat/test-spaces_left_parentheses_linter.R
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,8 @@ test_that("returns the correct linting", {
expect_lint("if (!(foo && bar || baz)) { foo }",
NULL,
spaces_left_parentheses_linter)

expect_lint("x^(y + z)", NULL, spaces_left_parentheses_linter)

expect_lint("a <- -(b)", NULL, spaces_left_parentheses_linter)
})

0 comments on commit b9587dd

Please sign in to comment.