1.0.2 • Published 6 years ago

jest-runner-shellcheck v1.0.2

Weekly downloads
2,148
License
MIT
Repository
github
Last release
6 years ago

Build Status npm version

Usage

This library is a jest-runner for the shellcheck library.

Install

Install jest(it needs Jest 21+) and jest-runner-shellcheck

yarn add --dev jest jest-runner-shellcheck

# or with NPM

npm install --save-dev jest jest-runner-shellcheck

Add it to your Jest config

Standalone

In your package.json

{
  "jest": {
    "runner": "jest-runner-shellcheck",
    "displayName": "lint:shell",
    "moduleFileExtensions": ["sh", "bash"],
    "testMatch": ["<rootDir>/src/**/*.sh"]
  }
}

Or in jest.config.js

module.exports = {
  runner: "jest-runner-shellcheck",
  displayName: "shell lint",
  moduleFileExtensions: ["sh", "bash"],
  testMatch: ["<rootDir>/src/**/*.sh"]
};

Please update testMatch to match your project folder structure

Alongside other runners

It is recommended to use the projects configuration option to run multiple Jest runners simultaneously.

If you are using Jest <22.0.5, you can use multiple Jest configuration files and supply the paths to those files in the projects option. For example:

// jest-test.config.js
module.exports = {
  // your Jest test options
  displayName: "test"
};

// jest-grapqhl-schema-linter.config.js
module.exports = {
  // your jest-runner-shellcheck options
  runner: "jest-runner-shellcheck",
  displayName: "shell lint",
  moduleFileExtensions: ["sh", "bash"],
  testMatch: ["<rootDir>/src/**/*.sh"]
};

In your package.json:

{
  "jest": {
    "projects": [
      "<rootDir>/jest-test.config.js",
      "<rootDir>/jest-shellcheck.config.js"
    ]
  }
}

Or in jest.config.js:

module.exports = {
  projects: [
    "<rootDir>/jest-test.config.js",
    "<rootDir>/jest-shellcheck.config.js"
  ]
};

If you are using Jest >=22.0.5, you can supply an array of project configuration objects instead. In your package.json:

{
  "jest": {
    "projects": [
      {
        "displayName": "test"
      },
      {
        "runner": "jest-runner-shellcheck",
        "displayName": "lint:shell",
        "moduleFileExtensions": ["sh", "bash"],
        "testMatch": ["<rootDir>/src/**/*.sh"]
      }
    ]
  }
}

Or in jest.config.js:

module.exports = {
  projects: [
    {
      displayName: "test"
    },
    {
      runner: "jest-runner-shellcheck",
      displayName: "shell lint",
      moduleFileExtensions: ["sh", "bash"],
      testMatch: ["<rootDir>/src/**/*.sh"]
    }
  ]
};

Run Jest

yarn test

Options

This project uses cosmiconfig, so you can provide config via:

  • a jest-runner-shellcheck property in your package.json
  • a jest-runner-shellcheck.config.js JS file
  • a .jest-runner-shellcheckrc JSON file

In package.json

{
  "jest-runner-shellcheck": {
    "cliOptions": {
      // Options here
    }
  }
}

or in jest-runner-shellcheck.config.js

module.exports = {
  cliOptions: {
    // Options here
  }
};

cliOptions

The listed options are the ones provided by the shellcheck CLI.

optiondefaultvaluesexample
checkSourcedfalsefalse|true"checkSourced": true
colornullauto|always|never"color": "auto"
excludenull"exclude": "CODE1,CODE2.."
formatcheckstylecheckstyle|gcc|json|tty"format": "json"
shellshsh|bash|dash|ksh"shell": "bash"
externalSourcesfalsefalse|true"externalSources": "true"