Skip to content

Use as a JavaScript module

Moritz Jacobs edited this page Feb 25, 2020 · 1 revision

Using scriptlint as a module dependency

You can install scriptlint as a dependency and call it as a function like this:

const scriptlint = require("scriptlint");

const scriptlintIssues = scriptlint({
	strict: true,
	packageFile: "/Users/foobar/project-dir"
});

OR you pass in a script object directly …

const scriptlint = require("scriptlint");

const scriptlintIssues = scriptlint({
	fix: true,
	strict: true,
	packageScripts: {
            foo: "bar",
            test: "jest"
        }
});

BUT NOT BOTH!

The function returns an object with found issues and the (potentially fixed if fix: true) scripts object in question:

{
  "issues": [
    {
      "message": "must contain a \"start\" script (mandatory-start)",
      "type": "warning",
      "affected": false
    },
    {
      "message": "must contain a \"dev\" script (mandatory-dev)",
      "type": "warning",
      "affected": false
    }
  ],
  "scripts": {
    "other:foo": "bar",
    "test": "jest"
  }
}

Note: local user config (in .scriptlintrc or similar) is ignored in the module, you have to configure the module directly!


scriptlint status
npm version badge
dependency badge
Issue badge
CI badge

Clone this wiki locally