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.

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 and additional_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.

dirty: bool
enforce_rules() Iterator[Fuss][source]

Enforce rules for missing data in the YAML file.

entry_point() Iterator[Fuss]

Entry point of the Nitpick plugin.

expected_config: JsonDict
file_path: Path
filename = ''
fixable: bool = True

Can this plugin modify its files directly? Are the files fixable?

identify_tags: ClassVar = {'yaml'}

Which identify tags this nitpick.plugins.base.NitpickPlugin child recognises.

property initial_contents: str

Suggest the initial content for this missing file.

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).

violation_base_code: int = 360
write_file(file_exists: bool) Fuss | None

Hook to write the new file when autofix mode is on.

Should be used by inherited classes.

write_initial_contents(doc_class: type[nitpick.blender.BaseDoc], expected_dict: dict | None = None) str

Helper to write initial contents based on a format.

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.