├── .circleci ├── config.yml └── test-deploy.yml ├── .github ├── CODEOWNERS ├── ISSUE_TEMPLATE │ ├── BUG.md │ ├── config.yml │ └── feature_request.md └── PULL_REQUEST_TEMPLATE │ └── PULL_REQUEST.md ├── .gitignore ├── .yamllint ├── LICENSE ├── README.md └── src ├── @orb.yml ├── commands ├── check.yml └── install.yml ├── examples ├── add_shellcheck_to_workflow.yml └── custom_shellcheck_job.yml ├── jobs └── check.yml ├── scripts ├── check.sh └── install.sh └── tests ├── check-test.bats ├── ignore_test ├── goodScript.sh ├── ignore_path_1 │ └── ignore1.sh └── ignore_path_2 │ └── ignore2.sh └── test_data ├── failingShellCheck.sh └── fakeScript.fake /.circleci/config.yml: -------------------------------------------------------------------------------- 1 | version: 2.1 2 | setup: true 3 | orbs: 4 | orb-tools: circleci/orb-tools@11.1 5 | shellcheck: circleci/shellcheck@3.1 6 | 7 | filters: &filters 8 | tags: 9 | only: /.*/ 10 | 11 | workflows: 12 | lint-pack: 13 | jobs: 14 | - orb-tools/lint: 15 | filters: *filters 16 | - orb-tools/pack: 17 | filters: *filters 18 | - orb-tools/review: 19 | filters: *filters 20 | - shellcheck/check: 21 | exclude: SC2148,SC2038,SC2086,SC2002,SC2016 22 | ignore-dirs: | 23 | ./.git 24 | ./src/tests 25 | filters: *filters 26 | - orb-tools/publish: 27 | orb-name: circleci/shellcheck 28 | vcs-type: << pipeline.project.type >> 29 | requires: 30 | [orb-tools/lint, orb-tools/review, orb-tools/pack, shellcheck/check] 31 | # Use a context to hold your publishing token. 32 | context: orb-publisher 33 | filters: *filters 34 | # Triggers the next workflow in the Orb Development Kit. 35 | - orb-tools/continue: 36 | pipeline-number: << pipeline.number >> 37 | vcs-type: << pipeline.project.type >> 38 | requires: [orb-tools/publish] 39 | filters: *filters 40 | -------------------------------------------------------------------------------- /.circleci/test-deploy.yml: -------------------------------------------------------------------------------- 1 | version: 2.1 2 | orbs: 3 | shellcheck: circleci/shellcheck@dev:<> 4 | orb-tools: circleci/orb-tools@11.1 5 | filters: &filters 6 | tags: 7 | only: /.*/ 8 | jobs: 9 | integration-test_full: 10 | parameters: 11 | env: 12 | type: executor 13 | default: debian 14 | executor: <> 15 | steps: 16 | - checkout 17 | - shellcheck/install 18 | - run: 19 | name: Verify Shellcheck install 20 | command: shellcheck -V 21 | - shellcheck/check: 22 | exclude: SC2148,SC2038,SC2086 23 | dir: ./src/scripts 24 | workflows: 25 | test-deploy: 26 | jobs: 27 | # Make sure to include "filters: *filters" in every test job you want to run as part of your deployment. 28 | - integration-test_full: 29 | matrix: 30 | parameters: 31 | env: 32 | - debian 33 | - mac 34 | - alpine 35 | - arm 36 | filters: *filters 37 | - orb-tools/pack: 38 | filters: *filters 39 | - orb-tools/publish: 40 | orb-name: circleci/shellcheck 41 | vcs-type: << pipeline.project.type >> 42 | pub-type: production 43 | requires: 44 | - orb-tools/pack 45 | - integration-test_full 46 | context: orb-publisher 47 | github-token: GHI_TOKEN 48 | filters: 49 | branches: 50 | ignore: /.*/ 51 | tags: 52 | only: /^v[0-9]+\.[0-9]+\.[0-9]+$/ 53 | executors: 54 | debian: 55 | docker: 56 | - image: cimg/base:edge 57 | alpine: 58 | docker: 59 | - image: alpine 60 | mac: 61 | macos: 62 | xcode: "13.4.1" 63 | shell: bash --login -eox pipefail 64 | arm: 65 | machine: 66 | image: ubuntu-2204:current 67 | resource_class: arm.medium 68 | -------------------------------------------------------------------------------- /.github/CODEOWNERS: -------------------------------------------------------------------------------- 1 | # Ping these folks when changes are made to this repository 2 | - @CircleCI-Public/orb-publishers 3 | 4 | # We can also add orb-specifc codeowners at some point if desirable 5 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/BUG.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: "\U0001F41E Bug report" 3 | about: Report any bugs encountered while using this orb. 4 | title: '' 5 | labels: bug 6 | assignees: '' 7 | 8 | --- 9 | 10 | ## Orb version: 11 | 12 | 19 | 20 | ## What happened: 21 | 22 | 26 | 27 | ## Expected behavior: 28 | 29 | 30 | 31 | ## Additional Information: 32 | 33 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/config.yml: -------------------------------------------------------------------------------- 1 | blank_issues_enabled: false 2 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: "\U0001F680 Feature Request" 3 | about: Propose changes to the orb. 4 | title: '' 5 | labels: feature_request 6 | assignees: '' 7 | --- 8 | 9 | ## Describe Request: 10 | 11 | ## Examples: 12 | 13 | ## Supporting Documentation Links: 14 | 15 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE/PULL_REQUEST.md: -------------------------------------------------------------------------------- 1 | 2 | **SEMVER Update Type:** 3 | - [ ] Major 4 | - [ ] Minor 5 | - [ ] Patch 6 | 7 | ## Description: 8 | 9 | 13 | 14 | ## Motivation: 15 | 16 | 19 | 20 | **Closes Issues:** 21 | - ISSUE URL 22 | 23 | ## Checklist: 24 | 25 | 30 | 31 | - [ ] All new jobs, commands, executors, parameters have descriptions. 32 | - [ ] Usage Example version numbers have been updated. 33 | - [ ] Changelog has been updated. -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | orb.yml 3 | tmp -------------------------------------------------------------------------------- /.yamllint: -------------------------------------------------------------------------------- 1 | extends: relaxed 2 | 3 | rules: 4 | line-length: 5 | max: 200 6 | allow-non-breakable-inline-mappings: true 7 | 8 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 CircleCI Public 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Shellcheck Orb [![CircleCI status](https://circleci.com/gh/CircleCI-Public/shellcheck-orb.svg "CircleCI status")](https://circleci.com/gh/CircleCI-Public/shellcheck-orb) [![CircleCI Orb Version](https://badges.circleci.com/orbs/circleci/shellcheck.svg)](https://circleci.com/orbs/registry/orb/circleci/shellcheck) [![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/CircleCI-Public/shellcheck-orb/master/LICENSE) [![CircleCI Community](https://img.shields.io/badge/community-CircleCI%20Discuss-343434.svg)](https://discuss.circleci.com/c/ecosystem/orbs) 2 | 3 | An orb for linting and verifying shell scripts. 4 | 5 | ## Usage 6 | 7 | _For full usage guidelines, see the [orb registry listing](http://circleci.com/orbs/registry/orb/circleci/shellcheck)._ 8 | 9 | ## Contributing 10 | 11 | We welcome [issues](https://github.com/CircleCI-Public/shellcheck-orb/issues) to and [pull requests](https://github.com/CircleCI-Public/shellcheck-orb/pulls) against this repository! 12 | 13 | For further questions/comments about this or other orbs, visit [CircleCI's orbs discussion forum](https://discuss.circleci.com/c/orbs). 14 | -------------------------------------------------------------------------------- /src/@orb.yml: -------------------------------------------------------------------------------- 1 | version: 2.1 2 | 3 | description: | 4 | Automatically find bugs and errors in your shell scripts with ShellCheck on every commit. Add this static analysis tool to any CI/CD workflow and ShellCheck your scripts across your repository. 5 | 6 | display: 7 | source_url: https://github.com/circleci-public/shellcheck-orb 8 | home_url: https://shellcheck.net 9 | -------------------------------------------------------------------------------- /src/commands/check.yml: -------------------------------------------------------------------------------- 1 | description: > 2 | Scan files in directory matching pattern. 3 | 4 | parameters: 5 | exclude: 6 | description: > 7 | A comma separated list of SC codes to explicitly ignore. Example: "SC1000,SC1001" 8 | type: string 9 | default: "" 10 | external_sources: 11 | description: > 12 | Follow source statements even when the file is not specified as input. 13 | type: boolean 14 | default: false 15 | dir: 16 | description: > 17 | Specify the root path containing the shell scripts. The directory will be recursively searched. 18 | type: string 19 | default: "." 20 | ignore-dirs: 21 | description: | 22 | Specify directories to be ignored during shellcheck. Separate paths by with new line. 23 | Do not add slash (/) at the end of the directory. 24 | type: string 25 | default: './.git' 26 | severity: 27 | description: > 28 | Specify minimum severity of errors to consider. Valid values in order of severity are error, warning, info and style. 29 | enum: ["error", "warning", "info", "style"] 30 | type: enum 31 | default: "style" 32 | format: 33 | description: > 34 | Specify the output format of shellcheck. Valid values include: "tty", "gcc", "checkstyle", "diff", "json1", "json", "quiet" 35 | enum: ["tty", "gcc", "checkstyle", "diff", "json1", "json", "quiet"] 36 | default: "tty" 37 | type: enum 38 | output: 39 | type: string 40 | default: shellcheck.log 41 | description: | 42 | The filename of the shellcheck output, which is automatically saved 43 | as a job artifact 44 | shell: 45 | type: string 46 | default: "" 47 | description: Shell language to check against. 48 | pattern: 49 | type: string 50 | default: "" 51 | description: The file pattern to search for. By default will search for "*.sh" 52 | 53 | steps: 54 | - run: 55 | name: Run Shellcheck 56 | environment: 57 | SC_PARAM_EXCLUDE: <> 58 | SC_PARAM_EXTERNAL_SOURCES: <> 59 | SC_PARAM_DIR: <> 60 | SC_PARAM_SEVERITY: <> 61 | SC_PARAM_FORMAT: <> 62 | SC_PARAM_OUTPUT: <> 63 | SC_PARAM_SHELL: <> 64 | SC_PARAM_PATTERN: <> 65 | SC_PARAM_IGNORE_DIRS: <> 66 | command: << include(scripts/check.sh) >> 67 | 68 | - store_artifacts: 69 | path: <> 70 | destination: shellcheck 71 | -------------------------------------------------------------------------------- /src/commands/install.yml: -------------------------------------------------------------------------------- 1 | description: > 2 | Install Shellcheck. 3 | 4 | parameters: 5 | version: 6 | description: | 7 | Select the tagged release version of Shellcheck to install. 8 | Mac with ARM arquitecture is only supported since version 0.10.0 9 | default: "0.10.0" 10 | type: string 11 | 12 | steps: 13 | - run: 14 | name: Install Shellcheck 15 | environment: 16 | SC_INSTALL_VERSION: <> 17 | command: << include(scripts/install.sh) >> 18 | -------------------------------------------------------------------------------- /src/examples/add_shellcheck_to_workflow.yml: -------------------------------------------------------------------------------- 1 | description: | 2 | Easily integrate shellcheck into an existing workflow. Add the "check" job and provide any optional parameters desired. 3 | 4 | usage: 5 | version: 2.1 6 | 7 | orbs: 8 | shellcheck: circleci/shellcheck@3.1.2 # This version refers to the orb version, not the ShellCheck version. Check latest released version 9 | 10 | workflows: 11 | my_workflow: 12 | jobs: 13 | - shellcheck/check: 14 | dir: ./myScripts 15 | exclude: "SC2148" 16 | -------------------------------------------------------------------------------- /src/examples/custom_shellcheck_job.yml: -------------------------------------------------------------------------------- 1 | description: | 2 | Install the Shellcheck CLI into your CI environment. 3 | 4 | usage: 5 | version: 2.1 6 | 7 | orbs: 8 | shellcheck: circleci/shellcheck@3.1.2 # This version refers to the orb version, not the ShellCheck version. Check latest released version 9 | 10 | jobs: 11 | my_job: 12 | docker: 13 | - image: cimg/base:stable 14 | steps: 15 | - checkout 16 | - shellcheck/install 17 | - run: 18 | name: Run Shellcheck command 19 | command: shellcheck 20 | 21 | workflows: 22 | my_workflow: 23 | jobs: 24 | - my_job 25 | -------------------------------------------------------------------------------- /src/jobs/check.yml: -------------------------------------------------------------------------------- 1 | description: | 2 | Run shellcheck over any shell scripts in the repository. 3 | Add this job to any workflow to automatically check any shell scripts 4 | in your repository using the official Koalaman Shellcheck Docker image. 5 | 6 | docker: 7 | - image: <>:<> 8 | 9 | resource_class: << parameters.resource_class >> 10 | 11 | parameters: 12 | exclude: 13 | description: > 14 | A comma separated list of SC codes to explicitly ignore. Example: "SC1000,SC1001" 15 | type: string 16 | default: "" 17 | external_sources: 18 | description: > 19 | Follow source statements even when the file is not specified as input. 20 | type: boolean 21 | default: false 22 | dir: 23 | description: > 24 | Specify the root path containing the shell scripts. The directory will be recursively searched. 25 | type: string 26 | default: "." 27 | ignore-dirs: 28 | description: | 29 | Specify directories to be ignored during shellcheck. Separate paths by with new line. 30 | Do not add slash (/) at the end of the directory. 31 | type: string 32 | default: './.git' 33 | severity: 34 | description: > 35 | Specify minimum severity of errors to consider. Valid values in order of severity are error, warning, info and style. 36 | enum: ["error", "warning", "info", "style"] 37 | type: enum 38 | default: "style" 39 | format: 40 | description: > 41 | Specify the output format of shellcheck. Valid values include: "tty", "gcc", "checkstyle", "diff", "json1", "json", "quiet" 42 | enum: ["tty", "gcc", "checkstyle", "diff", "json1", "json", "quiet"] 43 | default: "tty" 44 | type: enum 45 | output: 46 | type: string 47 | default: shellcheck.log 48 | description: | 49 | The filename of the shellcheck output, which is automatically saved 50 | as a job artifact 51 | image-name: 52 | type: string 53 | default: "cimg/base" 54 | description: | 55 | Shellcheck is included in the CircleCI authored `cimg/base` docker image (Feb 2022 onward), installed via the official Ubuntu packages. 56 | By default, "cimg/base" is used as the image, but you may specify a different base image with this parameter. 57 | https://circleci.com/developer/images/image/cimg/base 58 | image-tag: 59 | type: string 60 | default: "current" 61 | description: | 62 | Shellcheck is included in the CircleCI authored `cimg/base` docker image (Feb 2022 onward), installed via the official Ubuntu packages. 63 | By default the most current stable release of this image will be used, but you may statically set the image tag with this parameter. 64 | https://circleci.com/developer/images/image/cimg/base 65 | resource_class: 66 | description: Configure the executor resource class 67 | type: enum 68 | enum: ["small", "medium", "medium+", "large", "xlarge", "2xlarge", "2xlarge+", "arm.medium", "arm.large", "arm.xlarge", "arm.2xlarge"] 69 | default: "small" 70 | shell: 71 | type: string 72 | default: "" 73 | description: Shell language to check against. 74 | pattern: 75 | type: string 76 | default: "" 77 | description: The file pattern to search for. By default will search for "*.sh" 78 | circleci_ip_ranges: 79 | description: Enables jobs to go through a set of well-defined IP address ranges. 80 | type: boolean 81 | default: false 82 | 83 | circleci_ip_ranges: << parameters.circleci_ip_ranges >> 84 | 85 | steps: 86 | - checkout 87 | - check: 88 | exclude: <> 89 | external_sources: <> 90 | dir: <> 91 | ignore-dirs: <> 92 | severity: <> 93 | format: <> 94 | output: <> 95 | shell: <> 96 | pattern: <> 97 | -------------------------------------------------------------------------------- /src/scripts/check.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | Run_ShellCheck() { 3 | input="$1" 4 | set -- 5 | 6 | if [ -n "$SC_PARAM_EXCLUDE" ]; then 7 | set -- "$@" "--exclude=$SC_PARAM_EXCLUDE" 8 | fi 9 | 10 | if [ "$SC_PARAM_EXTERNAL_SOURCES" == "1" ]; then 11 | set -- "$@" "--external-sources" 12 | fi 13 | 14 | if [ -n "$SC_PARAM_SHELL" ]; then 15 | set -- "$@" "--shell=$SC_PARAM_SHELL" 16 | fi 17 | 18 | shellcheck "$@" --severity="$SC_PARAM_SEVERITY" --format="$SC_PARAM_FORMAT" "$input" >> "$SC_PARAM_OUTPUT" 19 | } 20 | 21 | Check_For_ShellCheck() { 22 | if ! command -v shellcheck &> /dev/null 23 | then 24 | echo "Shellcheck not installed" 25 | exit 1 26 | fi 27 | } 28 | 29 | ShellCheck_Files() { 30 | IFS=$'\n' 31 | for file in ${SC_PARAM_IGNORE_DIRS}; do 32 | trimmed=$(echo "${file}" | awk '{$1=$1};1') 33 | 34 | if [ -e "${trimmed}" ]; then 35 | set -- "$@" "!" "-path" "${trimmed}/*.sh" 36 | fi 37 | done 38 | 39 | SC_PARAM_PATTERN="${SC_PARAM_PATTERN:-"*.sh"}" 40 | SC_INPUT_FILES=/tmp/sc-input-files 41 | find "$SC_PARAM_DIR" ! -name "$(printf "*\n*")" -name "$SC_PARAM_PATTERN" -type f "$@" | tee "${SC_INPUT_FILES}" 42 | set +e 43 | while IFS= read -r script 44 | do 45 | Run_ShellCheck "$script" 46 | done < "${SC_INPUT_FILES}" 47 | set -eo pipefail 48 | } 49 | 50 | Catch_SC_Errors() { 51 | if [ -s "$SC_PARAM_OUTPUT" ]; then 52 | printf '\e[1;31mShellCheck Errors Found\e[0m\n' 53 | cat "$SC_PARAM_OUTPUT" 54 | exit 1 55 | else 56 | printf '\e[1;32mNo ShellCheck Errors Found\e[0m\n' 57 | fi 58 | } 59 | 60 | SC_Main() { 61 | Check_For_ShellCheck 62 | ShellCheck_Files 63 | Catch_SC_Errors 64 | rm /tmp/sc-input-files 65 | } 66 | 67 | # Will not run if sourced for bats. 68 | # View src/tests for more information. 69 | TEST_ENV="bats-core" 70 | if [ "${0#*"$TEST_ENV"}" == "$0" ]; then 71 | SC_Main 72 | fi 73 | -------------------------------------------------------------------------------- /src/scripts/install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | if [[ $EUID == 0 ]]; then export SUDO=""; else # Check if we're root 3 | export SUDO="sudo" 4 | fi 5 | 6 | install_mac() { 7 | curl -LJO "https://github.com/koalaman/shellcheck/releases/download/v${SC_INSTALL_VERSION}/shellcheck-v${SC_INSTALL_VERSION}.darwin.aarch64.tar.xz" 8 | tar -xvf "shellcheck-v$SC_INSTALL_VERSION.darwin.aarch64.tar.xz" 9 | cd "shellcheck-v$SC_INSTALL_VERSION/" || false 10 | $SUDO cp shellcheck /usr/local/bin 11 | } 12 | install_linux() { 13 | wget -qO- "https://github.com/koalaman/shellcheck/releases/download/v${SC_INSTALL_VERSION}/shellcheck-v${SC_INSTALL_VERSION}.linux.x86_64.tar.xz" | tar -xJf - 14 | cd "shellcheck-v$SC_INSTALL_VERSION/" || false 15 | $SUDO cp shellcheck /usr/local/bin 16 | } 17 | install_arm64() { 18 | wget -qO- "https://github.com/koalaman/shellcheck/releases/download/v${SC_INSTALL_VERSION}/shellcheck-v${SC_INSTALL_VERSION}.linux.armv6hf.tar.xz" | tar -xJf - 19 | cd "shellcheck-v$SC_INSTALL_VERSION/" || false 20 | $SUDO cp shellcheck /usr/local/bin 21 | } 22 | install_alpine() { 23 | apk add shellcheck 24 | } 25 | install_arch() { 26 | wget -qO- "https://github.com/koalaman/shellcheck/releases/download/v${SC_INSTALL_VERSION}/shellcheck-v${SC_INSTALL_VERSION}.linux.aarch64.tar.xz" | tar -xJf - 27 | cd "shellcheck-v$SC_INSTALL_VERSION/" || false 28 | $SUDO cp shellcheck /usr/local/bin 29 | } 30 | 31 | # Platform check 32 | if uname -a | grep -q "Darwin"; then 33 | install_mac 34 | elif uname -a | grep -q "x86_64 GNU/Linux"; then 35 | install_linux 36 | elif uname -a | grep -q "aarch64 GNU/Linux"; then 37 | install_arm64 38 | elif uname -a | grep -q "x86_64 Msys"; then 39 | install_windows 40 | elif grep -q "Alpine" /etc/issue; then 41 | install_alpine 42 | elif grep -q Arch /etc/issue; then 43 | install_arch 44 | else 45 | echo "This platform appears to be unsupported." 46 | uname -a 47 | exit 1 48 | fi 49 | -------------------------------------------------------------------------------- /src/tests/check-test.bats: -------------------------------------------------------------------------------- 1 | setup() { 2 | source ./src/scripts/check.sh 3 | export SC_PARAM_OUTPUT="/tmp/shellcheck.log" 4 | export SC_PARAM_SHELL="bash" 5 | Check_For_ShellCheck 6 | } 7 | 8 | teardown() { 9 | # Clean shellcheck log for sake of other tests 10 | rm -rf /tmp/shellcheck.log 11 | } 12 | 13 | # Esure Shellcheck is able to find the two included shell scripts 14 | @test "1: Shellcheck test - Find both scripts" { 15 | export SC_PARAM_DIR="src/scripts" 16 | export SC_PARAM_SEVERITY="style" 17 | export SC_PARAM_EXCLUDE="SC2148,SC2038,SC2059" 18 | ShellCheck_Files 19 | # Test that 2 scripts were found 20 | [ $(wc -l /tmp/sc-input-files | awk '{print $1}') == 2 ] 21 | } 22 | 23 | # Esure Shellcheck is able to find files with custom patterns 24 | @test "2: Shellcheck test - Find one custom pattern script" { 25 | export SC_PARAM_DIR="src/tests/test_data" 26 | export SC_PARAM_SEVERITY="style" 27 | export SC_PARAM_EXCLUDE="SC2148,SC2038,SC2059" 28 | export SC_PARAM_FORMAT="tty" 29 | SC_PARAM_PATTERN="*.fake" 30 | ShellCheck_Files 31 | # Test that 1 fake script was found 32 | [ $(wc -l /tmp/sc-input-files | awk '{print $1}') == 1 ] 33 | } 34 | 35 | # Esure Shellcheck command provides a failure if errors are found 36 | @test "3: Shellcheck test - Fail on error" { 37 | export SC_PARAM_DIR="src/tests/test_data" 38 | export SC_PARAM_SEVERITY="style" 39 | export SC_PARAM_FORMAT="tty" 40 | ShellCheck_Files 41 | run Catch_SC_Errors 42 | [ "$status" == 1 ] 43 | } 44 | 45 | # Esure errors can be excluded 46 | @test "4: Shellcheck test - Suppress errors" { 47 | export SC_PARAM_DIR="src/tests/test_data" 48 | export SC_PARAM_SEVERITY="style" 49 | export SC_PARAM_EXCLUDE="SC2006,SC2116,SC2034" 50 | export SC_PARAM_FORMAT="tty" 51 | ShellCheck_Files 52 | run Catch_SC_Errors 53 | [ "$status" == 0 ] 54 | } 55 | 56 | # Esure errors can be excluded 57 | @test "5: Shellcheck test - Ignore directory list" { 58 | export SC_PARAM_DIR="src/tests/test_data" 59 | export SC_PARAM_IGNORE_DIRS="src/tests/ignore_test/ignore_path_1 60 | src/tests/ignore_test/ignore_path_2" 61 | export SC_PARAM_SEVERITY="style" 62 | export SC_PARAM_EXCLUDE="SC2006,SC2116,SC2034" 63 | export SC_PARAM_FORMAT="tty" 64 | ShellCheck_Files 65 | 66 | # Test that 1 script was found in test_data 67 | [ $(wc -l /tmp/sc-input-files | awk '{print $1}') == 1 ] 68 | } -------------------------------------------------------------------------------- /src/tests/ignore_test/goodScript.sh: -------------------------------------------------------------------------------- 1 | echo "hello world!" -------------------------------------------------------------------------------- /src/tests/ignore_test/ignore_path_1/ignore1.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | echo "This script contains shellchecking errors and should not be checked" 4 | # Error SC2006 5 | testme=`echo hello` -------------------------------------------------------------------------------- /src/tests/ignore_test/ignore_path_2/ignore2.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | echo "This script contains shellchecking errors and should not be checked" 4 | # Error SC2006 5 | testme=`echo hello` -------------------------------------------------------------------------------- /src/tests/test_data/failingShellCheck.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | echo "This script contains shellchecking errors" 4 | # Error SC2006 5 | testme=`echo hello` -------------------------------------------------------------------------------- /src/tests/test_data/fakeScript.fake: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | echo "This is a sample script with a custom extension" --------------------------------------------------------------------------------