nitpick.plugins.base module

Base class for file checkers.

class nitpick.plugins.base.NitpickPlugin(info: FileInfo, expected_config: Dict[str, Any], autofix=False)[source]

Bases: object

Base class for Nitpick plugins.

Parameters
  • data – File information (project, path, tags).

  • expected_config – Expected configuration for the file

  • autofix – Flag to modify files, if the plugin supports it (default: True).

abstract enforce_rules() Iterator[Fuss][source]

Enforce rules for this file. It must be overridden by inherited classes if needed.

entry_point() Iterator[Fuss][source]

Entry point of the Nitpick plugin.

filename = ''
fixable: bool = False

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

identify_tags: set[str] = {}

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

abstract property initial_contents: str

Suggested initial content when the file doesn’t exist.

property nitpick_file_dict: Dict[str, Any]

Nitpick configuration for this file as a TOML dict, taken from the style file.

post_init()[source]

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]

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

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 = 0
write_file(file_exists: bool) Fuss | None[source]

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) str[source]

Helper to write initial contents based on a format.