These plugins use the processor to parse and return the results independently, without providing the ESLint engine with AST and source code text.
Plugins don't provide AST, so you can't use directive comments (e.g. # eslint-disable).
Plugins don't provide source code text, so you can't use it with plugins and rules that use text (e.g. eslint-plugin-prettier, eol-last).
eslint-plugin-yml works by providing AST and source code text to ESLint.
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.
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.
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:
The --fix option on the command line automatically fixes problems reported by rules which have a wrench :wrench: below.
The rules with the following star :star: are included in the config.