Styles¶
The style file¶
A “Nitpick code style” is a TOML file with the settings that should be present in config files from other tools.
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¶
After creating your own TOML file with your style, add it to your pyproject.toml
file. See Configuration for details.
You can also check some pre-configured examples, and copy/paste/change configuration from them.
Default search order for a style¶
A file or URL configured in the
pyproject.toml
file,[tool.nitpick]
section,style
key, as described in Configuration.Any nitpick-style.toml file found in the current directory (the one in which flake8 runs from) or above.
If no style is found, then the default style file from GitHub is used.
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 pyproject.toml
:
[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 ("pyproject.toml".
)
The same works for setup.cfg
.
To configure mypy to ignore missing imports in your project, this is needed on setup.cfg
:
[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
Breaking style changes¶
Warning
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.present]
now.
Before:
[nitpick.files."pyproject.toml"]
missing_message = "Install poetry and run 'poetry init' to create it"
Now:
[nitpick.files.present]
"pyproject.toml" = "Install poetry and run 'poetry init' to create it"