From e4b08ec8421c41212d15c4506d129a27ec69b43f Mon Sep 17 00:00:00 2001 From: Marco Ferrari Date: Wed, 8 Dec 2021 21:28:30 +0100 Subject: [PATCH] Lint the whole code base with JSCPD (#2180) * Lint the whole code base with JSCPD if VALIDATE_ALL_CODEBASE is true * Use VALIDATE_JSCPD_ALL_CODEBASE Co-authored-by: Lukas Gravley --- README.md | 1 + lib/functions/buildFileList.sh | 19 +++++++++++++------ lib/linter.sh | 4 ++++ 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 9ac990cc..f565713f 100644 --- a/README.md +++ b/README.md @@ -323,6 +323,7 @@ But if you wish to select or exclude specific linters, we give you full control | **TYPESCRIPT_ES_CONFIG_FILE** | `.eslintrc.yml` | Filename for [ESLint configuration](https://eslint.org/docs/user-guide/configuring#configuration-file-formats) (ex: `.eslintrc.yml`, `.eslintrc.json`) | | **USE_FIND_ALGORITHM** | `false` | By default, we use `git diff` to find all files in the workspace and what has been updated, this would enable the Linux `find` method instead to find all files to lint | | **VALIDATE_ALL_CODEBASE** | `true` | Will parse the entire repository and find all files to validate across all types. **NOTE:** When set to `false`, only **new** or **edited** files will be parsed for validation. | +| **VALIDATE_JSCPD_ALL_CODEBASE** | `false` | If set to `true`, will lint the whole codebase with JSCPD, in addition to linting files with JSCPD one by one. If set to `false`, JSCPD will only lint files one by one. | | **VALIDATE_ANSIBLE** | `true` | Flag to enable or disable the linting process of the Ansible language. | | **VALIDATE_ARM** | `true` | Flag to enable or disable the linting process of the ARM language. | | **VALIDATE_BASH** | `true` | Flag to enable or disable the linting process of the Bash language. | diff --git a/lib/functions/buildFileList.sh b/lib/functions/buildFileList.sh index 46620adc..9ff8ad87 100755 --- a/lib/functions/buildFileList.sh +++ b/lib/functions/buildFileList.sh @@ -54,19 +54,21 @@ function BuildFileList() { # Pull in vars # ################ VALIDATE_ALL_CODEBASE="${1}" - debug "Validate all code base: ${VALIDATE_ALL_CODEBASE}..." + debug "VALIDATE_ALL_CODEBASE: ${VALIDATE_ALL_CODEBASE}" TEST_CASE_RUN="${2}" - debug "TEST_CASE_RUN: ${TEST_CASE_RUN}..." + debug "TEST_CASE_RUN: ${TEST_CASE_RUN}" ANSIBLE_DIRECTORY="${3}" - debug "ANSIBLE_DIRECTORY: ${ANSIBLE_DIRECTORY}..." + debug "ANSIBLE_DIRECTORY: ${ANSIBLE_DIRECTORY}" - debug "IGNORE_GITIGNORED_FILES: ${IGNORE_GITIGNORED_FILES}..." + debug "IGNORE_GITIGNORED_FILES: ${IGNORE_GITIGNORED_FILES}" - debug "IGNORE_GENERATED_FILES: ${IGNORE_GENERATED_FILES}..." + debug "IGNORE_GENERATED_FILES: ${IGNORE_GENERATED_FILES}" - debug "USE_FIND_ALGORITHM: ${USE_FIND_ALGORITHM}..." + debug "USE_FIND_ALGORITHM: ${USE_FIND_ALGORITHM}" + + debug "VALIDATE_JSCPD_ALL_CODEBASE: ${VALIDATE_JSCPD_ALL_CODEBASE}" if [ "${VALIDATE_ALL_CODEBASE}" == "false" ] && [ "${TEST_CASE_RUN}" != "true" ]; then # Need to build a list of all files changed @@ -854,6 +856,11 @@ function BuildFileList() { debug "" done + if [ "${VALIDATE_JSCPD_ALL_CODEBASE}" == "true" ]; then + debug "Adding the root of the workspaces to the list of files and directories to lint with JSCPD..." + FILE_ARRAY_JSCPD+=("${GITHUB_WORKSPACE}") + fi + ################ # Footer print # ################ diff --git a/lib/linter.sh b/lib/linter.sh index c66d8657..ca0a0e5f 100755 --- a/lib/linter.sh +++ b/lib/linter.sh @@ -953,6 +953,10 @@ debug "---------------------------------------------" ################################# CheckSSLCert +# Check if we need to lint the whole codebase with JSCPD +VALIDATE_JSCPD_ALL_CODEBASE="${VALIDATE_JSCPD_ALL_CODEBASE:-"false"}" +export VALIDATE_JSCPD_ALL_CODEBASE + ########################################### # Build the list of files for each linter # ###########################################