3

I've set up lintr package with GitHub Actions:

on: push: branches: - master pull_request: branches: - 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@master - uses: actions/cache@v1 with: path: ~/Library/Application Support/renv key: ${{ runner.os }}-renv-${{ hashFiles('**/renv.lock') }} restore-keys: | ${{ runner.os }}-renv- - name: Install lintr run: install.packages("lintr") shell: Rscript {0} - name: Lint run: lintr::lint_dir(linters = lintr::with_defaults(assignment_linter = NULL, line_length_linter = NULL, spaces_left_parentheses_linter = NULL), pattern = '[.]R$|[.]Rmd') shell: Rscript {0} 

And formatting errors are shown as Annotations:

enter image description here

But, those annotations doesn't fails PR check which is actually what you want when you lint code.

enter image description here

I thought of setting an exit 1 on warnings. Is that the correct approach?

3
  • I'm not familiar with lintr but perhaps the issue here is that it's treating issues as warnings instead of errors. C# devs face a similar situation where the StyleCop linter uses some warnings and doesn't fail the build unless a configuration is changed. Perhaps lintr can be similarly configured to treat all warnings as errors and return an error code. Commented Jun 3, 2020 at 18:28
  • I'll give it a try! Commented Jun 4, 2020 at 15:24
  • @AlbersonMiranda, did you ever succeed in throwing an error here? I tried replicating the top comment's answer, but I still get annotations, not errors. It doesn't seem like error_on_lint changes anything in my action Commented Aug 25, 2021 at 17:59

1 Answer 1

3

Prior to the code that runs lint_dir , you could add options(error_on_lint=TRUE) :

run: "options(error_on_lint=TRUE); lintr::lint_dir(linters = lintr ..." 

It might be useful to put your lintr settings into a .lintr file in the directory that you run lintr against:

.lintr

linters: with_defaults( assignment_linter = NULL, line_length_linter = NULL, spaces_left_parentheses_linter = NULL ) error_on_lint: TRUE 

Then the lint_dir code in your GHA would look like:

run: lintr::lint_dir(pattern=....) 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.