nitpick.plugins.yaml module
YAML files.
- class nitpick.plugins.yaml.YamlPlugin(info: FileInfo, expected_config: JsonDict, autofix=False)[source]
Bases:
NitpickPlugin
Enforce configurations and autofix YAML files.
Example: .pre-commit-config.yaml.
Style example: the default pre-commit hooks.
Warning
The plugin tries to preserve comments in the YAML file by using the
ruamel.yaml
package. It works for most cases. If your comment was removed, place them in a different place of the fil and try again. If it still doesn’t work, please report a bug.Known issue: lists like
args
andadditional_dependencies
might be joined in a single line, and comments between items will be removed. Move your comments outside these lists, and they should be preserved.Note
No validation of
.pre-commit-config.yaml
will be done anymore in this generic YAML plugin. Nitpick will not validate hooks and missing keys as it did before; it’s not the purpose of this package.- expected_config: JsonDict
- file_path: Path
- filename = ''
- identify_tags: ClassVar = {'yaml'}
Which
identify
tags thisnitpick.plugins.base.NitpickPlugin
child recognises.
- property nitpick_file_dict: Dict[str, Any]
Nitpick configuration for this file as a TOML dict, taken from the style file.
- post_init()
Hook for plugin initialization after the instance was created.
The name mimics
__post_init__()
on dataclasses, without the magic double underscores: Post-init processing
- predefined_special_config() SpecialConfig [source]
Predefined special config, with list keys for .pre-commit-config.yaml and GitHub Workflow files.
- report(violation: ViolationEnum, yaml_object: YamlObject, change: YamlDoc | None, replacement: YamlDoc | None = None)[source]
Report a violation while optionally modifying the YAML document.
- skip_empty_suggestion = False
- validation_schema: Schema | None = None
Nested validation field for this file, to be applied in runtime when the validation schema is rebuilt. Useful when you have a strict configuration for a file type (e.g.
nitpick.plugins.json.JsonPlugin
).
- nitpick.plugins.yaml.can_handle(info: FileInfo) type[NitpickPlugin] | None [source]
Handle YAML files.
- nitpick.plugins.yaml.plugin_class() type[nitpick.plugins.base.NitpickPlugin] [source]
Handle YAML files.