From 0b756c57e8a95eb0aee22b05d53b464c5113dfa7 Mon Sep 17 00:00:00 2001 From: Max Held Date: Fri, 26 Feb 2021 15:49:08 +0100 Subject: [PATCH] only error on rstats lintr errors, not all lints (#1233) * only error on lintr errors * ensure that dockerfile includes purrr * update tap snapshot * add actual lint error * add snapshot for actual error Co-authored-by: Gabriel Diaz Co-authored-by: Lukas Gravley --- .automation/test/r/r_bad_1.r | 3 +++ .automation/test/r/reports/expected-R.tap | 2 +- Dockerfile | 2 +- lib/functions/worker.sh | 2 +- 4 files changed, 6 insertions(+), 3 deletions(-) diff --git a/.automation/test/r/r_bad_1.r b/.automation/test/r/r_bad_1.r index 480eacd1..93ba18ed 100644 --- a/.automation/test/r/r_bad_1.r +++ b/.automation/test/r/r_bad_1.r @@ -39,5 +39,8 @@ message('single_quotes') # trailing_whitespace y <- 2 +(1:10) +# unexpected end of input +{ + # trailing_blank_lines diff --git a/.automation/test/r/reports/expected-R.tap b/.automation/test/r/reports/expected-R.tap index 8794ed31..f2c4581a 100644 --- a/.automation/test/r/reports/expected-R.tap +++ b/.automation/test/r/reports/expected-R.tap @@ -2,6 +2,6 @@ TAP version 13 1..2 not ok 1 - r_bad_1.r --- - message: Warning message \nIn options(stringsAsFactors = TRUE) \n 'options(stringsAsFactors = TRUE)' is deprecated and will be disabled\n/tmp/lint/.automation/test/r/r_bad_1.r 8 3 style Use <-, not =, for assignment.\nf = function (x,y = 1){}\n ^\n/tmp/lint/.automation/test/r/r_bad_1.r 8 14 style Remove spaces before the left parenthesis in a function call.\nf = function (x,y = 1){}\n ^\n/tmp/lint/.automation/test/r/r_bad_1.r 8 17 style Commas should always have a space after.\nf = function (x,y = 1){}\n ^\n/tmp/lint/.automation/test/r/r_bad_1.r 8 22 style There should be a space between right parenthesis and an opening curly brace.\nf = function (x,y = 1){}\n ^~\n/tmp/lint/.automation/test/r/r_bad_1.r 8 23 style Opening curly braces should never go on their own line and should always be followed by a new line.\nf = function (x,y = 1){}\n ^\n/tmp/lint/.automation/test/r/r_bad_1.r 8 24 style Closing curly-braces should always be on their own line, unless it's followed by an else.\nf = function (x,y = 1){}\n ^\n/tmp/lint/.automation/test/r/r_bad_1.r 11 3 style Commented code should be removed.\n# some <- commented("out code")\n ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n/tmp/lint/.automation/test/r/r_bad_1.r 21 1 style functions should have cyclomatic complexity of less than 15, this has 22.\nsomeComplicatedFunctionWithALongCameCaseName <- function(x)\n^\n/tmp/lint/.automation/test/r/r_bad_1.r 21 1 style Variable and function names should not be longer than 30 characters.\nsomeComplicatedFunctionWithALongCameCaseName <- function(x)\n^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n/tmp/lint/.automation/test/r/r_bad_1.r 21 1 style Variable and function name style should be snake_case.\nsomeComplicatedFunctionWithALongCameCaseName <- function(x)\n^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n/tmp/lint/.automation/test/r/r_bad_1.r 22 1 style Opening curly braces should never go on their own line and should always be followed by a new line.\n{\n^\n/tmp/lint/.automation/test/r/r_bad_1.r 24 1 style Lines should not be more than 80 characters.\n if (1 > 2 && 2 > 3 && 3 > 4 && 4 > 5 && 5*10 > 6 && x == NA) {TRUE} else {FALSE}\n^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n/tmp/lint/.automation/test/r/r_bad_1.r 24 44 style Put spaces around all infix operators.\n if (1 > 2 && 2 > 3 && 3 > 4 && 4 > 5 && 5*10 > 6 && x == NA) {TRUE} else {FALSE}\n ~^~\n/tmp/lint/.automation/test/r/r_bad_1.r 24 57 warning Use is.na rather than == NA.\n if (1 > 2 && 2 > 3 && 3 > 4 && 4 > 5 && 5*10 > 6 && x == NA) {TRUE} else {FALSE}\n ^~~~~\n/tmp/lint/.automation/test/r/r_bad_1.r 24 64 style Opening curly braces should never go on their own line and should always be followed by a new line.\n if (1 > 2 && 2 > 3 && 3 > 4 && 4 > 5 && 5*10 > 6 && x == NA) {TRUE} else {FALSE}\n ^\n/tmp/lint/.automation/test/r/r_bad_1.r 24 69 style Closing curly-braces should always be on their own line, unless it's followed by an else.\n if (1 > 2 && 2 > 3 && 3 > 4 && 4 > 5 && 5*10 > 6 && x == NA) {TRUE} else {FALSE}\n ^\n/tmp/lint/.automation/test/r/r_bad_1.r 24 76 style Opening curly braces should never go on their own line and should always be followed by a new line.\n if (1 > 2 && 2 > 3 && 3 > 4 && 4 > 5 && 5*10 > 6 && x == NA) {TRUE} else {FALSE}\n ^\n/tmp/lint/.automation/test/r/r_bad_1.r 24 82 style Closing curly-braces should always be on their own line, unless it's followed by an else.\n if (1 > 2 && 2 > 3 && 3 > 4 && 4 > 5 && 5*10 > 6 && x == NA) {TRUE} else {FALSE}\n ^\n/tmp/lint/.automation/test/r/r_bad_1.r 31 3 style Do not place spaces around code in parentheses or square brackets.\nx[ 2]\n ^\n/tmp/lint/.automation/test/r/r_bad_1.r 32 1 warning Avoid 1 length(...) expressions, use seq_len.\n1 length(x) %>% lapply(function(x) x*2) %>%\n^\n/tmp/lint/.automation/test/r/r_bad_1.r 32 37 style Put spaces around all infix operators.\n1 length(x) %>% lapply(function(x) x*2) %>%\n ~^~\n/tmp/lint/.automation/test/r/r_bad_1.r 32 43 style `%>%` should always have a space before it and a new line after it, unless the full pipeline fits on one line.\n1 length(x) %>% lapply(function(x) x*2) %>%\n ~~^\n/tmp/lint/.automation/test/r/r_bad_1.r 36 9 style Only use double-quotes.\nmessage('single_quotes')\n ^~~~~~~~~~~~~~~\n/tmp/lint/.automation/test/r/r_bad_1.r 40 8 style Put spaces around all infix operators.\ny <- 2 +(1 10)\n ^~\n/tmp/lint/.automation/test/r/r_bad_1.r 40 9 style Place a space before left parenthesis, except in a function call.\ny <- 2 +(1 10)\n ^\n/tmp/lint/.automation/test/r/r_bad_1.r 43 1 style Trailing blank lines are superfluous.\n\n^\n + message: /tmp/lint/.automation/test/r/r_bad_1.r 8 3 style Use <-, not =, for assignment.\nf = function (x,y = 1){}\n ^\n/tmp/lint/.automation/test/r/r_bad_1.r 8 14 style Remove spaces before the left parenthesis in a function call.\nf = function (x,y = 1){}\n ^\n/tmp/lint/.automation/test/r/r_bad_1.r 8 17 style Commas should always have a space after.\nf = function (x,y = 1){}\n ^\n/tmp/lint/.automation/test/r/r_bad_1.r 8 22 style There should be a space between right parenthesis and an opening curly brace.\nf = function (x,y = 1){}\n ^~\n/tmp/lint/.automation/test/r/r_bad_1.r 8 23 style Opening curly braces should never go on their own line and should always be followed by a new line.\nf = function (x,y = 1){}\n ^\n/tmp/lint/.automation/test/r/r_bad_1.r 8 24 style Closing curly-braces should always be on their own line, unless it's followed by an else.\nf = function (x,y = 1){}\n ^\n/tmp/lint/.automation/test/r/r_bad_1.r 11 3 style Commented code should be removed.\n# some <- commented("out code")\n ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n/tmp/lint/.automation/test/r/r_bad_1.r 21 1 style functions should have cyclomatic complexity of less than 15, this has 22.\nsomeComplicatedFunctionWithALongCameCaseName <- function(x)\n^\n/tmp/lint/.automation/test/r/r_bad_1.r 21 1 style Variable and function names should not be longer than 30 characters.\nsomeComplicatedFunctionWithALongCameCaseName <- function(x)\n^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n/tmp/lint/.automation/test/r/r_bad_1.r 21 1 style Variable and function name style should be snake_case.\nsomeComplicatedFunctionWithALongCameCaseName <- function(x)\n^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n/tmp/lint/.automation/test/r/r_bad_1.r 22 1 style Opening curly braces should never go on their own line and should always be followed by a new line.\n{\n^\n/tmp/lint/.automation/test/r/r_bad_1.r 24 1 style Lines should not be more than 80 characters.\n if (1 > 2 && 2 > 3 && 3 > 4 && 4 > 5 && 5*10 > 6 && x == NA) {TRUE} else {FALSE}\n^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n/tmp/lint/.automation/test/r/r_bad_1.r 24 44 style Put spaces around all infix operators.\n if (1 > 2 && 2 > 3 && 3 > 4 && 4 > 5 && 5*10 > 6 && x == NA) {TRUE} else {FALSE}\n ~^~\n/tmp/lint/.automation/test/r/r_bad_1.r 24 57 warning Use is.na rather than == NA.\n if (1 > 2 && 2 > 3 && 3 > 4 && 4 > 5 && 5*10 > 6 && x == NA) {TRUE} else {FALSE}\n ^~~~~\n/tmp/lint/.automation/test/r/r_bad_1.r 24 64 style Opening curly braces should never go on their own line and should always be followed by a new line.\n if (1 > 2 && 2 > 3 && 3 > 4 && 4 > 5 && 5*10 > 6 && x == NA) {TRUE} else {FALSE}\n ^\n/tmp/lint/.automation/test/r/r_bad_1.r 24 69 style Closing curly-braces should always be on their own line, unless it's followed by an else.\n if (1 > 2 && 2 > 3 && 3 > 4 && 4 > 5 && 5*10 > 6 && x == NA) {TRUE} else {FALSE}\n ^\n/tmp/lint/.automation/test/r/r_bad_1.r 24 76 style Opening curly braces should never go on their own line and should always be followed by a new line.\n if (1 > 2 && 2 > 3 && 3 > 4 && 4 > 5 && 5*10 > 6 && x == NA) {TRUE} else {FALSE}\n ^\n/tmp/lint/.automation/test/r/r_bad_1.r 24 82 style Closing curly-braces should always be on their own line, unless it's followed by an else.\n if (1 > 2 && 2 > 3 && 3 > 4 && 4 > 5 && 5*10 > 6 && x == NA) {TRUE} else {FALSE}\n ^\n/tmp/lint/.automation/test/r/r_bad_1.r 31 3 style Do not place spaces around code in parentheses or square brackets.\nx[ 2]\n ^\n/tmp/lint/.automation/test/r/r_bad_1.r 32 1 warning Avoid 1 length(...) expressions, use seq_len.\n1 length(x) %>% lapply(function(x) x*2) %>%\n^\n/tmp/lint/.automation/test/r/r_bad_1.r 32 37 style Put spaces around all infix operators.\n1 length(x) %>% lapply(function(x) x*2) %>%\n ~^~\n/tmp/lint/.automation/test/r/r_bad_1.r 32 43 style `%>%` should always have a space before it and a new line after it, unless the full pipeline fits on one line.\n1 length(x) %>% lapply(function(x) x*2) %>%\n ~~^\n/tmp/lint/.automation/test/r/r_bad_1.r 36 9 style Only use double-quotes.\nmessage('single_quotes')\n ^~~~~~~~~~~~~~~\n/tmp/lint/.automation/test/r/r_bad_1.r 40 8 style Put spaces around all infix operators.\ny <- 2 +(1 10)\n ^~\n/tmp/lint/.automation/test/r/r_bad_1.r 40 9 style Place a space before left parenthesis, except in a function call.\ny <- 2 +(1 10)\n ^\n/tmp/lint/.automation/test/r/r_bad_1.r 43 1 style Opening curly braces should never go on their own line and should always be followed by a new line.\n{\n^\n/tmp/lint/.automation/test/r/r_bad_1.r 46 0 error unexpected end of input\n\n\n/tmp/lint/.automation/test/r/r_bad_1.r 46 1 style Trailing blank lines are superfluous.\n\n^\n ... ok 2 - r_good_1.r diff --git a/Dockerfile b/Dockerfile index b1d79dc5..4f3977ae 100644 --- a/Dockerfile +++ b/Dockerfile @@ -18,7 +18,7 @@ FROM alpine/terragrunt:0.14.5 as terragrunt FROM mvdan/shfmt:v3.2.2 as shfmt FROM accurics/terrascan:2d1374b as terrascan FROM hadolint/hadolint:latest-alpine as dockerfile-lint -FROM ghcr.io/assignuser/lintr-lib:0.1.2 as lintr-lib +FROM ghcr.io/assignuser/lintr-lib:0.2.0 as lintr-lib FROM ghcr.io/assignuser/chktex-alpine:0.1.1 as chktex FROM garethr/kubeval:0.15.0 as kubeval diff --git a/lib/functions/worker.sh b/lib/functions/worker.sh index f217abb6..813e1cf0 100755 --- a/lib/functions/worker.sh +++ b/lib/functions/worker.sh @@ -218,7 +218,7 @@ function LintCodebase() { fi LINT_CMD=$( cd "$r_dir" || exit - R --slave -e "errors <- lintr::lint('$FILE');print(errors);quit(save = 'no', status = if (length(errors) > 0) 1 else 0)" 2>&1 + R --slave -e "lints <- lintr::lint('$FILE');print(lints);errors <- purrr::keep(lints, ~ .\$type == 'error');quit(save = 'no', status = if (length(errors) > 0) 1 else 0)" 2>&1 ) ######################################################### # Corner case for C# as it writes to tty and not stdout #