From 6372885cd0b5c9269ecfe033f7e3af5b7e6622d3 Mon Sep 17 00:00:00 2001 From: assignUser Date: Mon, 17 Aug 2020 16:27:31 +0000 Subject: [PATCH] relative exclusions work, adressed comments --- docs/disabling-linters.md | 4 ++-- lib/buildFileList.sh | 2 +- lib/linter.sh | 8 ++++---- lib/worker.sh | 10 ++++++++-- 4 files changed, 15 insertions(+), 9 deletions(-) diff --git a/docs/disabling-linters.md b/docs/disabling-linters.md index 9da136ea..d96385c8 100644 --- a/docs/disabling-linters.md +++ b/docs/disabling-linters.md @@ -905,7 +905,7 @@ var = "terrible code down here..." - `.github/linters/.lintr` - You can pass multiple rules and overwrite default rules -- File should be located at: `.github/linters/.lintr` +- You can use either one `.lintr` file in the root of your repository and/or additonal `.lintr` files in subdirectories. When linting a file lintr will look for config files from the file location upwards and will use the closest one. - **Note:** The defaults adhere to the [tidyverse styleguide](https://style.tidyverse.org/) ### lintr disable single line @@ -924,7 +924,7 @@ var = "terrible code down here..." ``` ### lintr disable entire file -Add files to exclude into the config file as a list of filenames to exclude from linting. You can use a named item to exclude only certain lines from a file. +Add files to exclude into the config file as a list of filenames to exclude from linting. You can use a named item to exclude only certain lines from a file. Use paths relative to the location of the `.lintr` file. ```r exclusions: list("inst/doc/creating_linters.R" = 1, "inst/example/bad.R", "tests/testthat/exclusions-test") diff --git a/lib/buildFileList.sh b/lib/buildFileList.sh index d44f6348..760c0eec 100755 --- a/lib/buildFileList.sh +++ b/lib/buildFileList.sh @@ -358,7 +358,7 @@ function BuildFileList() { #################### # Get the R files # #################### - elif [ "${FILE_TYPE}" == "r" ]; then + elif [ "${FILE_TYPE}" == "r" ] || [ "${FILE_TYPE}" == "rmd" ]; then ################################ # Append the file to the array # ################################ diff --git a/lib/linter.sh b/lib/linter.sh index 99cf7e8d..e3cbad39 100755 --- a/lib/linter.sh +++ b/lib/linter.sh @@ -132,8 +132,8 @@ YAML_LINTER_RULES="${DEFAULT_RULES_LOCATION}/${YAML_FILE_NAME}" # Path to the ya ####################################### LINTER_ARRAY=('ansible-lint' 'arm-ttk' 'asl-validator' 'cfn-lint' 'checkstyle' 'clj-kondo' 'coffeelint' 'dart' 'dockerfilelint' 'dotenv-linter' 'editorconfig-checker' 'eslint' 'flake8' 'golangci-lint' - 'hadolint' 'htmlhint' 'jsonlint' 'ktlint' 'lua' 'markdownlint' 'npm-groovy-lint' 'perl' 'protolint' - 'pwsh' 'pylint' 'lintr' 'raku' 'rubocop' 'shellcheck' 'spectral' 'standard' 'stylelint' 'sql-lint' + 'hadolint' 'htmlhint' 'jsonlint' 'ktlint' 'lintr' 'lua' 'markdownlint' 'npm-groovy-lint' 'perl' 'protolint' + 'pwsh' 'pylint' 'raku' 'rubocop' 'shellcheck' 'spectral' 'standard' 'stylelint' 'sql-lint' 'terrascan' 'tflint' 'xmllint' 'yamllint') ############################# @@ -299,7 +299,7 @@ FILE_ARRAY_POWERSHELL=() # Array of files to check FILE_ARRAY_PROTOBUF=() # Array of files to check FILE_ARRAY_PYTHON_PYLINT=() # Array of files to check FILE_ARRAY_PYTHON_FLAKE8=() # Array of files to check -FILE_ARRAY_R=() # Array of files to check +FILE_ARRAY_R=() # Array of files to check FILE_ARRAY_RAKU=() # Array of files to check FILE_ARRAY_RUBY=() # Array of files to check FILE_ARRAY_STATES=() # Array of files to check @@ -1708,7 +1708,7 @@ if [ "${VALIDATE_R}" == "true" ]; then # Lint the R files # ###################### # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" - LintCodebase "R" "lintr" "lintr::lint('$File')" ".*\.\(r\|R\|Rmd\|rmd\)\$" "${FILE_ARRAY_R[@]}" + LintCodebase "R" "lintr" "lintr::lint(File)" ".*\.\(r\|R\|Rmd\|rmd\)\$" "${FILE_ARRAY_R[@]}" fi ################ diff --git a/lib/worker.sh b/lib/worker.sh index c3434462..31d2f98d 100755 --- a/lib/worker.sh +++ b/lib/worker.sh @@ -213,10 +213,16 @@ function LintCodebase() { ####################################### # Lint the file with the updated path # ####################################### + if [ ! -f "${DIR_NAME}/.lintr" ]; then + r_dir="${GITHUB_WORKSPACE}" + else + r_dir="${DIR_NAME}" + fi LINT_CMD=$( - cd "${DIR_NAME}" || exit + 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 ) + #LINTER_COMMAND="lintr::lint('${FILE}')" else ################################ # Lint the file with the rules # @@ -632,7 +638,7 @@ function RunTestCases() { TestCodebase "PYTHON_PYLINT" "pylint" "pylint --rcfile ${PYTHON_PYLINT_LINTER_RULES}" ".*\.\(py\)\$" "python" TestCodebase "PYTHON_FLAKE8" "flake8" "flake8 --config ${PYTHON_FLAKE8_LINTER_RULES}" ".*\.\(py\)\$" "python" # TestCodebase "Language" "Linter" "Linter-command" "Regex to find files" "Test Folder" - TestCodebase "R" "lintr" "raku -c" ".*\.\(r\|R\|Rmd\|rmd\)\$" "r" + TestCodebase "R" "lintr" "lintr::lint()" ".*\.\(r\|R\|Rmd\|rmd\)\$" "r" TestCodebase "RAKU" "raku" "raku -c" ".*\.\(raku\|rakumod\|rakutest\|pm6\|pl6\|p6\)\$" "raku" TestCodebase "RUBY" "rubocop" "rubocop -c ${RUBY_LINTER_RULES}" ".*\.\(rb\)\$" "ruby" TestCodebase "STATES" "asl-validator" "asl-validator --json-path" ".*\.\(json\)\$" "states"