The style file
Example of a style:
["pyproject.toml".tool.black] line-length = 120 ["pyproject.toml".tool.poetry.dev-dependencies] pylint = "*" ["setup.cfg".flake8] ignore = "D107,D202,D203,D401" max-line-length = 120 inline-quotes = "double" ["setup.cfg".isort] line_length = 120 multi_line_output = 3 include_trailing_comma = true force_grid_wrap = 0 combine_as_imports = true
This example style will assert that:
Configure your own style
You can also check the style library, and use the styles to build your own.
Default search order for a style
Style file syntax
A style file contains basically the configuration options you want to enforce in all your projects.
They are just the config to the tool, prefixed with the name of the config file.
E.g.: To configure the black formatter with a line length of 120, you use this in your
[tool.black] line-length = 120
To enforce that all your projects use this same line length, add this to your nitpick-style.toml file:
["pyproject.toml".tool.black] line-length = 120
It’s the same exact section/key, just prefixed with the config file name (
The same works for
To configure mypy to ignore missing imports in your project, this is needed on
[mypy] ignore_missing_imports = true
To enforce all your projects to ignore missing imports, add this to your nitpick-style.toml file:
["setup.cfg".mypy] ignore_missing_imports = true
Comparing elements on lists
At the moment, this feature only works on :ref:`the YAML plugin <yamlplugin>`_.
On YAML files, a list (called a “sequence” in the YAML spec) can contain different elements:
Scalar values like int, float and string;
Dictionaries or objects with key/value pairs (called “mappings” in the YAML spec)
Other lists (sequences).
The default behaviour for all lists: when applying a style, Nitpick searches if the element already exists in the list; if not found, the element is appended at the end of list.
With scalar values, Nitpick compares the elements by their exact value. Strings are compared in a case-sensitive manner, and spaces are considered.
Dicts are compared by a “hash” of their key/value pairs.
On lists containing dicts, it is possible to define a custom “list key” used to search for an element, overriding the default compare mechanism above.
If an element is found by its key, the other key/values are compared and Nitpick applies the difference. If the key doesn’t exist, the new dict is appended at the end of the list.
Some files have a predefined configuration:
.pre-commit-config.yaml, repos are searched by their hook IDs.
On GitHub Workflow YAML files, steps are searched by their names.
You can define your own list keys for your YAML files (or override the predefined configs above) by using
__list_keys on your style:
["path/from/root/to/your/config.yaml".__list_keys] "<list expression>" = "<search key expression>"
a dotted path to a list, e.g.
a pattern containing wildcards (
*). For example,
stepswill use the same
<search key expression>.
<search key expression>:
a key from the dict inside the list, e.g.
a parent key and its child key separated by a dot, e.g.
For now, only two-level nesting is possible: parent and child keys.
Below are the breaking changes in the style before the API is stable. If your style was working in a previous version and now it’s not, check below.
missing_message key was removed
missing_message was removed. Use
[nitpick.files."pyproject.toml"] missing_message = "Install poetry and run 'poetry init' to create it"
[nitpick.files.present] "pyproject.toml" = "Install poetry and run 'poetry init' to create it"