nitpick.plugins.pre_commit module

Checker for the .pre-commit-config.yaml file.

class nitpick.plugins.pre_commit.PreCommitHook(repo: str, hook_id: str, yaml: nitpick.formats.YAMLFormat)[source]

Bases: object

A pre-commit hook.

Method generated by attrs for class PreCommitHook.

classmethod get_all_hooks_from(str_or_yaml: Union[str, ruamel.yaml.comments.CommentedSeq, ruamel.yaml.comments.CommentedMap])[source]

Get all hooks from a YAML string. Split the string in hooks and copy the repo info for each.

property key_value_pair

Key/value pair to be used as a dict item.

property single_hook

Return only a single hook instead of a list.

property unique_key

Unique key of this hook, to be used in a dict.

class nitpick.plugins.pre_commit.PreCommitPlugin(config: Dict[str, Any], file_name: str = None)[source]

Bases: nitpick.plugins.base.NitpickPlugin

Checker for the .pre-commit-config.yaml file.

Example: the default pre-commit hooks.

actual_hooks: OrderedDict[str, PreCommitHook] = {}
actual_hooks_by_index: List[str] = []
actual_hooks_by_key: Dict[str, int] = {}
actual_yaml: YAMLFormat = None
check_exists() → Iterator[Tuple[int, int, str, Type]]

Check if the file should exist.

check_hooks() → Iterator[Tuple[int, int, str, Type]][source]

Check the repositories configured in pre-commit.

check_repo_block(expected_repo_block: collections.OrderedDict) → Iterator[Tuple[int, int, str, Type]][source]

Check a repo with a YAML string configuration.

check_repo_old_format(index: int, repo_data: collections.OrderedDict) → Iterator[Tuple[int, int, str, Type]][source]

Check repos using the old deprecated format with hooks and repo keys.

check_rules() → Iterator[Tuple[int, int, str, Type]][source]

Check the rules for the pre-commit hooks.

dynamic_name_classes = {}
error_base_number = 330
error_prefix = ''
file_name = '.pre-commit-config.yaml'
fixed_name_classes = {}
flake8_error(number: int, message: str, suggestion: str = None, add_to_base_number=True) → Tuple[int, int, str, Type]

Return a flake8 error as a tuple.

static format_hook(expected_dict)str[source]

Format the hook so it’s easy to copy and paste it to the .yaml file: ID goes first, indent with spaces.

classmethod get_compiled_jmespath_file_names()

Return a compiled JMESPath expression for file names, using the class name as part of the key.

identify_tags = {}
classmethod load_fixed_dynamic_classes()None

Separate classes with fixed file names from classes with dynamic files names.

suggest_initial_contents()str[source]

Suggest the initial content for this missing file.

validation_schema = None
warn_missing_different(comparison: nitpick.formats.Comparison, prefix_message: str = '')

Warn about missing and different keys.

nitpick.plugins.pre_commit.handle_config_file(config: Dict[str, Any], file_name: str, tags: Set[str]) → Optional[nitpick.plugins.base.NitpickPlugin][source]

Handle pre-commit config file.

nitpick.plugins.pre_commit.plugin_class() → Type[nitpick.plugins.base.NitpickPlugin][source]

You should return your plugin class here.