Lint YAML files
npm install eslint-plugin-yamlLint YAML files
You'll first need to install ESLint:
Next, install eslint-plugin-yaml:
``shell`
npm install eslint-plugin-yaml --save-dev
Add the following to eslint.config.cjs:
`js
const pluginYaml = require("eslint-plugin-yaml").default
module.exports = [pluginYaml.configs.recommended]
`
or to eslint.config.mjs:
`js
import pluginYaml from "eslint-plugin-yaml"
export default [pluginYaml.configs.recommended]
`
Add the following to the overrides section of .eslintrc for yaml files:
`json`
"overrides" : [
{
"files": ["/.yaml", "/.yml"],
"plugins": ["yaml"],
"extends": ["plugin:yaml/legacy"]
}
]
and run it for all the files:
`shell`
eslint .
or:
`shell`
eslint example.yaml
See spec folder for an example of eslint config file.
or add yaml to the plugins section of your .eslintrc configuration file. You can omit the eslint-plugin- prefix:
`json`
{
"plugins": ["yaml"],
"extends": ["plugin:yaml/legacy"]
}
You can run ESLint on individual YAML files or you can use the --ext flag to add YAML files to the list.
`shell``
eslint . --ext .yaml --ext .js
eslint example.yaml