actions icon indicating copy to clipboard operation
actions copied to clipboard

Lintr step should fail by defaullt if a violation is found

Open edmondop opened this issue 2 years ago • 12 comments

The current lintr workflows for example here https://github.com/r-lib/actions/blob/v2-branch/examples/lint.yaml doesn't fail if a violation is found, which is counterintuive and differs from what normally CI/CD workflows do.

I think we should fail by default, and let people "ignore" the failure with an option. Unfortunately the guide here https://github.com/r-lib/lintr#continuous-integration is not very clear, I would have expected this to be the default

edmondop avatar Mar 22 '22 18:03 edmondop

I think we should fail by default, and let people "ignore" the failure with an option

IMHO, this will be a bad idea.

There can often be a few false positives (e.g. function name should be snake_case lint for generic method) in lintr. So, if GHA defaults to failure for any violation found, unfortunately, this will just incentivize people to remove lintr GHA.

cc @MichaelChirico

IndrajeetPatil avatar Mar 23 '22 19:03 IndrajeetPatil

"Tests can be flaky, so don't run tests in CI"

edmondop avatar Mar 23 '22 19:03 edmondop

Linting is not unit testing. They are good suggestions for improving code quality, but they are not 100% correct.

IndrajeetPatil avatar Mar 23 '22 19:03 IndrajeetPatil

There is nothing wrong with having an option for it.

gaborcsardi avatar Mar 23 '22 19:03 gaborcsardi

There is nothing wrong with having an option for it.

Sure, no doubt about that.

But I am just pushing back against the suggested default, which is to mark build a failure if any lint is found.

A better default would be the current behaviour, and if someone wishes to, they can choose the option to mark the build failed in case any lints are found.

IndrajeetPatil avatar Mar 23 '22 19:03 IndrajeetPatil

I think the default should be failure. false positives should be reported and/or # nolint'd

MichaelChirico avatar Mar 23 '22 20:03 MichaelChirico

lintr itself has been bitten a few times recently from the lack of failure. it's easy to miss the warnings in a review, leading to extra review toil (1) handling follow-up PRs and (2) getting distracted in unrelated PRs by noticing the lint warnings there.

MichaelChirico avatar Mar 23 '22 20:03 MichaelChirico

💯 @MichaelChirico totally agree

edmondop avatar Mar 23 '22 20:03 edmondop

I am with @edmondo1984 and @MichaelChirico that failing should be the default :-)

richelbilderbeek avatar Apr 22 '22 09:04 richelbilderbeek

The LINTR_ERROR_ON_LINT environment variable provides the default for the lintr option error_on_lint, which should provide the option that folks want.

We have another project that has a CI check that is effectively:

export LINTR_ERROR_ON_LINT=true
Rscript -e 'lintr::lint_dir("R")'

You should be able to set this environment variable in your existing actions and see lintr rule violations fail CI.

aronatkins avatar Apr 25 '22 13:04 aronatkins

@aronatkins sounds great, thanks much!

Now the question is whether that should default to true or not? If yes, then we could set this env var in the example workflow. It seems like people in this thread would favor that.

Anyone wants to submit a PR?

gaborcsardi avatar Apr 25 '22 13:04 gaborcsardi

I just want to mention lintr::expect_lint_free

assignUser avatar May 13 '22 20:05 assignUser

This issue has been automatically locked. If you believe you have found a related problem, please file a new issue and include a link to this issue

github-actions[bot] avatar Nov 04 '22 13:11 github-actions[bot]