From 242d88b75737a69ecbceffdb5f90d6c3713d9436 Mon Sep 17 00:00:00 2001 From: Matthias Bernt Date: Fri, 15 Dec 2023 18:09:29 +0100 Subject: [PATCH] styler --- .github/styler.R | 13 +++++++++++++ .github/workflows/pr.yaml | 36 ++++++++---------------------------- 2 files changed, 21 insertions(+), 28 deletions(-) create mode 100644 .github/styler.R diff --git a/.github/styler.R b/.github/styler.R new file mode 100644 index 00000000000..c15db997fe3 --- /dev/null +++ b/.github/styler.R @@ -0,0 +1,13 @@ +library("argparse") +library("styler") + +parser <- ArgumentParser(description = "Call styler") +parser$add_argument("dir", + metavar = "DIR", type = "character", + help = "File to parse" +) +parser$add_argument("--dry", + choices = c("off", "on", "fail"), default = "on" +) +args <- parser$parse_args() +result <- style_dir(args$dir, dry = args$dry) diff --git a/.github/workflows/pr.yaml b/.github/workflows/pr.yaml index 85cee20cfab..50a38fb78a3 100644 --- a/.github/workflows/pr.yaml +++ b/.github/workflows/pr.yaml @@ -202,38 +202,18 @@ jobs: with: path: ${{ env.R_LIBS_USER }} key: r_cache_${{ matrix.os }}_${{ matrix.r-version }} - - name: Install non-R lintr dependencies - run: sudo apt-get install libcurl4-openssl-dev - - name: Install lintr - run: | - install.packages('remotes') - remotes::install_cran("lintr") - shell: Rscript {0} + - name: Install packages + uses: r-lib/actions/setup-r-dependencies@v2 + with: + packages: | + any::argparse + any::styler - name: Save repositories to file run: echo '${{ needs.setup.outputs.repository-list }}' > repository_list.txt - name: lintr run: | - library(lintr) - linters <- linters_with_defaults(line_length_linter = NULL, cyclocomp_linter = NULL, object_usage_linter = NULL, object_name_linter = NULL) - con <- file("repository_list.txt", "r") - status <- 0 - while (TRUE) { - repo <- readLines(con, n = 1) - if (length(repo) == 0) { - break - } - lnt <- lint_dir(repo, relative_path=T, linters=linters) - if (length(lnt) > 0) { - status <- 1 - for (l in lnt) { - rel_path <- paste(repo, l$filename, sep="/") - write(paste(paste(rel_path, l$line_number, l$column_number, sep=":"), l$message, paste("(", l$line, ")")), stderr()) - write(paste(paste(rel_path, l$line_number, l$column_number, sep=":"), l$message, paste("(", l$line, ")")), "rlint_report.txt", append=TRUE) - } - } - } - quit(status = status) - shell: Rscript {0} + echo '${{ needs.setup.outputs.repository-list }}' | xargs -d '\n' .github/styler.R --dry off + git diff --exit-code | tee rlint_report.txt - uses: actions/upload-artifact@v3 if: ${{ failure() }} with: