User Guide
💿 Installation
npm install --save-dev eslint eslint-plugin-ymlRequirements
- ESLint v9.38.0 and above
- Node.js v20.19.0 or higher (in the 20.x line), v22.13.0 or higher (in the 22.x line), or v24.0.0 and above
📖 Usage
Configuration
Use eslint.config.js file to configure rules. See also: https://eslint.org/docs/latest/use/configure/configuration-files-new.
Example eslint.config.js:
import eslintPluginYml from 'eslint-plugin-yml';
export default [
// add more generic rule sets here, such as:
// js.configs.recommended,
...eslintPluginYml.configs.recommended,
{
rules: {
// override/add rules settings here, such as:
// 'yml/rule-name': 'error'
}
}
];This plugin provides configs:
*.configs.base... Configuration to enable correct YAML parsing.*.configs.recommended... Above, plus rules to prevent errors or unintended behavior.*.configs.standard... Above, plus rules to enforce the common stylistic conventions.*.configs.prettier... Turn off rules that may conflict with Prettier.
See the rule list to get the rules that this plugin provides.
Note: The *.configs['flat/*'] configs are still available for backward compatibility, but it is recommended to use the new config names without the flat/ prefix.
Parser Configuration
If you have specified a parser, you need to configure a parser for .yaml.
For example, if you are using the "@babel/eslint-parser", configure it as follows:
import eslintPluginYml from 'eslint-plugin-yml';
import babelParser from '@babel/eslint-parser';
export default [
...eslintPluginYml.configs.standard,
{
files: ['**/*.js'],
languageOptions: {
parser: babelParser,
},
},
// YAML files are already configured by the plugin
];Parser Options
The following parser options for yaml-eslint-parser are available by specifying them in parserOptions in the ESLint configuration file.
import eslintPluginYml from 'eslint-plugin-yml';
export default [
...eslintPluginYml.configs.recommended,
{
files: ['**/*.yaml', '**/*.yml'],
languageOptions: {
parserOptions: {
defaultYAMLVersion: '1.2',
},
},
},
];See also https://github.com/ota-meshi/yaml-eslint-parser#readme.
Running ESLint from the command line
With ESLint v9 and flat config, ESLint automatically lints all files matched by your config. You typically don't need the --ext option anymore.
Examples:
eslint .
eslint "src/**/*.{js,yaml,yml}"Languages
This plugin provides the following language identifiers for use in ESLint configurations:
yml/yaml... YAML files
For example, to apply settings specifically to YAML files, you can use the language field in your ESLint configuration:
import eslintPluginYml from 'eslint-plugin-yml';
export default [
{
files: ["*.yaml", "*.yml", "**/*.yaml", "**/*.yml"],
plugins: {
yml: eslintPluginYml,
},
language: "yml/yaml",
}
]The configuration above is included in the shareable configs provided by this plugin, so using configs is generally recommended.
See also https://eslint.org/docs/latest/use/configure/plugins#specify-a-language
💻 Editor Integrations
Visual Studio Code
Use the dbaeumer.vscode-eslint extension that Microsoft provides officially.
You have to configure the eslint.validate option of the extension to check .yaml files, because the extension targets only *.js or *.jsx files by default.
Example .vscode/settings.json:
{
"eslint.validate": [
"javascript",
"javascriptreact",
"yaml",
"github-actions-workflow" // for GitHub Actions workflow files
]
}JetBrains WebStorm IDEs
In any of the JetBrains IDEs you can configure the linting scope. Following the steps in their help document, you can add YAML files to the scope like so:
- Open the Settings/Preferences dialog, go to Languages and Frameworks | JavaScript | Code Quality Tools | ESLint, and select Automatic ESLint configuration or Manual ESLint configuration.
- In the Run for files field, update the pattern that defines the set of files to be linted to include YAML files as well:
{**/*,*}.{js,ts,jsx,tsx,html,vue,yaml,yml}
^^^^ ^^^❓ FAQ
- TODO