-
Notifications
You must be signed in to change notification settings - Fork 1
Configuration
The scriptlint CLI is configured by either
- CLI command flags or
- a config object that stems from
- a
scriptlint
property inpackage.json
- a
.scriptlintrc
file in JSON or YAML format - a
.scriptlintrc.json
file - a
.scriptlintrc.yaml
,.scriptlintrc.yml
, or.scriptlintrc.js
file - a
scriptlint.config.js
file exporting a JS object
- a
With a combination of both the CLI command flags take precedence!
{
"strict": false,
"fix": false,
"config": false,
"json": false,
"rules": {},
"ignoreScripts": [],
"customRules": []
}
This defines what set of rules will be used. Non-strict means minimum rules, "strict": true
uses all of the default rules available. See here for in depth explanation for each rule.
Turn a rule on/off like this:
{
"strict": true,
"rules": {
"uses-allowed-namespace": false
}
}
Output the issues in a json format
[
{
"message": "Use of unix double ampersand (&&) in script 'test' is not allowed, consider using npm-run-all/run-s (no-unix-double-ampersand)",
"type": "warning",
"affected": "test"
}
]
Print the config as json for debugging purposes.
🚨 This alters the contents of your package.json
, only use it in a version controlled environment!
Attempt to fix all found issues. Not every rule has a autofix function ready, but some do.
{
"strict": true,
"ignoreScripts": ["my-funny-scriptname"]
}
Scripts in this list will be exempt from linting.
You can add custom rule implementations in your config. customRules
is an array of objects like this:
{
// your custom rule's name
name: string,
// is the rule looking at an individual script or the whole scripts object
isObjectRule: boolean,
// the error message if the validation fails for this rule, uses template tags {{name}} (and {{names}} for object rules)
message: string,
// the validation function for the rule
// for object rules it returns the failing scripts on fail
// if isObjectRule === true: (scripts: Object) => true | Array<string>
// for script rules it returns true or false
// if isObjectRule === false: (key: string, script: string, scripts: Object) => boolean
validate: function
// if the problem is autofixable, provide a fix function here
// for object rules it returns a fixed scripts object
// for script rules it returns an array with [key: string, value: string]
fix: function
}
As a speaking example here's a custom config (.scriptlintrc.js
) to override the camelCase
rule and replace it with a kebab-case
one:
module.exports = {
rules: {
"correct-casing": false,
"correct-kebab-casing": true
},
customRules: [
{
name: "correct-kebab-casing",
isObjectRule: false,
message: "`{{name}}`: Script name must be kebab case",
validate: name => /^[\d:a-z\-]+$/.test(name)
}
]
};
- Motivation
- The scriptlint "standard" tl;dr
-
The scriptlint "standard"
- Rules enforceable via the scriptlint CLI
- Best practices
- The scriptlint CLI
- Contributing to scriptlint