nitpick.plugins.toml module

TOML files.

class nitpick.plugins.toml.TomlPlugin(info: FileInfo, expected_config: JsonDict, autofix=False)[source]

Bases: NitpickPlugin

Enforce configurations and autofix TOML files.

E.g.: pyproject.toml (PEP 518).

See also the [tool.poetry] section of the pyproject.toml file.

Style example: Python 3.8 version constraint. There are many other examples here.

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

Enforce rules for missing key/value pairs in the TOML 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: set[str] = {'toml'}

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

Create a predefined special configuration for this plugin. Each plugin can override this method.

report(violation: ViolationEnum, document: TOMLDocument | None, change: TomlDoc | None, replacement: TomlDoc | None = None)[source]

Report a violation while optionally modifying the TOML 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 = 310
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[BaseDoc], expected_dict: dict | None = None) str

Helper to write initial contents based on a format.

nitpick.plugins.toml.can_handle(info: FileInfo) type[NitpickPlugin] | None[source]

Handle TOML files.

nitpick.plugins.toml.plugin_class() type[NitpickPlugin][source]

Handle TOML files.