Skip to content

Commit

Permalink
feat: enforce configs for any INI file (#304)
Browse files Browse the repository at this point in the history
* docs: ideas for INI and TOML (keys and sections, present/absent)
  • Loading branch information
andreoliwa authored Mar 2, 2021
1 parent 266c599 commit 80c840b
Show file tree
Hide file tree
Showing 24 changed files with 287 additions and 147 deletions.
2 changes: 2 additions & 0 deletions CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ Nitpick_ could always use more documentation, whether as part of the
official docs, in docstrings, or even on the web in blog posts,
articles, and such.

.. _development:

Development
===========

Expand Down
8 changes: 4 additions & 4 deletions docs/cli.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Nitpick_ has a CLI to apply changes to files automatically.

1. It doesn't work for all the plugins yet. Currently, it works for:

- :ref:`setupcfgplugin`
- :ref:`iniplugin`
- :ref:`pyprojecttomlplugin`

2. It tries to preserve the comments and the formatting of the original file.
Expand All @@ -31,7 +31,7 @@ Main options
------------


.. code-block:: shell
.. code-block::
Usage: nitpick [OPTIONS] COMMAND [ARGS]...
Expand All @@ -57,7 +57,7 @@ At the end of execution, this command displays:
- the number of violations that have to be changed manually.


.. code-block:: shell
.. code-block::
Usage: nitpick run [OPTIONS] [FILES]...
Expand All @@ -77,7 +77,7 @@ At the end of execution, this command displays:
-----------------------------


.. code-block:: shell
.. code-block::
Usage: nitpick ls [OPTIONS] [FILES]...
Expand Down
3 changes: 2 additions & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,9 +224,10 @@
# http://www.sphinx-doc.org/en/master/usage/extensions/intersphinx.html

# Example configuration for intersphinx: refer to the Python standard library.
# The inventory should be present for each of these URLs in the "objects.inv" file
intersphinx_mapping = {
"python": ("https://docs.python.org/3", None),
"marshmallow": ("https://marshmallow.readthedocs.io/en/stable", None),
"marshmallow": ("https://marshmallow.readthedocs.io/en/latest", None),
"ruamel.yaml": ("https://yaml.readthedocs.io/en/latest", None),
"jmespath": ("https://jmespath.readthedocs.io/en/latest", None),
}
Expand Down
38 changes: 19 additions & 19 deletions docs/defaults.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ All TOML_ configs below are taken from the `default style file`_.
Absent files
------------

Content of `styles/absent-files.toml <https://raw.githubusercontent.com/andreoliwa/nitpick/develop/styles/absent-files.toml>`_:
Contents of `styles/absent-files.toml <https://raw.githubusercontent.com/andreoliwa/nitpick/develop/styles/absent-files.toml>`_:

.. code-block:: toml
Expand All @@ -33,7 +33,7 @@ Content of `styles/absent-files.toml <https://raw.githubusercontent.com/andreoli
black_
------

Content of `styles/black.toml <https://raw.githubusercontent.com/andreoliwa/nitpick/develop/styles/black.toml>`_:
Contents of `styles/black.toml <https://raw.githubusercontent.com/andreoliwa/nitpick/develop/styles/black.toml>`_:

.. code-block:: toml
Expand Down Expand Up @@ -67,7 +67,7 @@ Content of `styles/black.toml <https://raw.githubusercontent.com/andreoliwa/nitp
flake8_
-------

Content of `styles/flake8.toml <https://raw.githubusercontent.com/andreoliwa/nitpick/develop/styles/flake8.toml>`_:
Contents of `styles/flake8.toml <https://raw.githubusercontent.com/andreoliwa/nitpick/develop/styles/flake8.toml>`_:

.. code-block:: toml
Expand Down Expand Up @@ -111,7 +111,7 @@ Content of `styles/flake8.toml <https://raw.githubusercontent.com/andreoliwa/nit
IPython_
--------

Content of `styles/ipython.toml <https://raw.githubusercontent.com/andreoliwa/nitpick/develop/styles/ipython.toml>`_:
Contents of `styles/ipython.toml <https://raw.githubusercontent.com/andreoliwa/nitpick/develop/styles/ipython.toml>`_:

.. code-block:: toml
Expand All @@ -124,7 +124,7 @@ Content of `styles/ipython.toml <https://raw.githubusercontent.com/andreoliwa/ni
isort_
------

Content of `styles/isort.toml <https://raw.githubusercontent.com/andreoliwa/nitpick/develop/styles/isort.toml>`_:
Contents of `styles/isort.toml <https://raw.githubusercontent.com/andreoliwa/nitpick/develop/styles/isort.toml>`_:

.. code-block:: toml
Expand Down Expand Up @@ -154,7 +154,7 @@ Content of `styles/isort.toml <https://raw.githubusercontent.com/andreoliwa/nitp
mypy_
-----

Content of `styles/mypy.toml <https://raw.githubusercontent.com/andreoliwa/nitpick/develop/styles/mypy.toml>`_:
Contents of `styles/mypy.toml <https://raw.githubusercontent.com/andreoliwa/nitpick/develop/styles/mypy.toml>`_:

.. code-block:: toml
Expand Down Expand Up @@ -188,7 +188,7 @@ Content of `styles/mypy.toml <https://raw.githubusercontent.com/andreoliwa/nitpi
package.json_
-------------

Content of `styles/package-json.toml <https://raw.githubusercontent.com/andreoliwa/nitpick/develop/styles/package-json.toml>`_:
Contents of `styles/package-json.toml <https://raw.githubusercontent.com/andreoliwa/nitpick/develop/styles/package-json.toml>`_:

.. code-block:: toml
Expand All @@ -209,7 +209,7 @@ Content of `styles/package-json.toml <https://raw.githubusercontent.com/andreoli
Poetry_
-------

Content of `styles/poetry.toml <https://raw.githubusercontent.com/andreoliwa/nitpick/develop/styles/poetry.toml>`_:
Contents of `styles/poetry.toml <https://raw.githubusercontent.com/andreoliwa/nitpick/develop/styles/poetry.toml>`_:

.. code-block:: toml
Expand All @@ -221,7 +221,7 @@ Content of `styles/poetry.toml <https://raw.githubusercontent.com/andreoliwa/nit
Bash_
-----

Content of `styles/pre-commit/bash.toml <https://raw.githubusercontent.com/andreoliwa/nitpick/develop/styles/pre-commit/bash.toml>`_:
Contents of `styles/pre-commit/bash.toml <https://raw.githubusercontent.com/andreoliwa/nitpick/develop/styles/pre-commit/bash.toml>`_:

.. code-block:: toml
Expand All @@ -238,7 +238,7 @@ Content of `styles/pre-commit/bash.toml <https://raw.githubusercontent.com/andre
commitlint_
-----------

Content of `styles/pre-commit/commitlint.toml <https://raw.githubusercontent.com/andreoliwa/nitpick/develop/styles/pre-commit/commitlint.toml>`_:
Contents of `styles/pre-commit/commitlint.toml <https://raw.githubusercontent.com/andreoliwa/nitpick/develop/styles/pre-commit/commitlint.toml>`_:

.. code-block:: toml
Expand All @@ -257,7 +257,7 @@ Content of `styles/pre-commit/commitlint.toml <https://raw.githubusercontent.com
pre-commit_ (hooks)
-------------------

Content of `styles/pre-commit/general.toml <https://raw.githubusercontent.com/andreoliwa/nitpick/develop/styles/pre-commit/general.toml>`_:
Contents of `styles/pre-commit/general.toml <https://raw.githubusercontent.com/andreoliwa/nitpick/develop/styles/pre-commit/general.toml>`_:

.. code-block:: toml
Expand All @@ -280,7 +280,7 @@ Content of `styles/pre-commit/general.toml <https://raw.githubusercontent.com/an
pre-commit_ (main)
------------------

Content of `styles/pre-commit/main.toml <https://raw.githubusercontent.com/andreoliwa/nitpick/develop/styles/pre-commit/main.toml>`_:
Contents of `styles/pre-commit/main.toml <https://raw.githubusercontent.com/andreoliwa/nitpick/develop/styles/pre-commit/main.toml>`_:

.. code-block:: toml
Expand All @@ -295,14 +295,14 @@ Content of `styles/pre-commit/main.toml <https://raw.githubusercontent.com/andre
pre-commit_ (Python hooks)
--------------------------

Content of `styles/pre-commit/python.toml <https://raw.githubusercontent.com/andreoliwa/nitpick/develop/styles/pre-commit/python.toml>`_:
Contents of `styles/pre-commit/python.toml <https://raw.githubusercontent.com/andreoliwa/nitpick/develop/styles/pre-commit/python.toml>`_:

.. code-block:: toml
[[".pre-commit-config.yaml".repos]]
yaml = """
- repo: https://github.com/pre-commit/pygrep-hooks
rev: v1.7.1
rev: v1.8.0
hooks:
- id: python-check-blanket-noqa
- id: python-check-mock-methods
Expand All @@ -316,7 +316,7 @@ Content of `styles/pre-commit/python.toml <https://raw.githubusercontent.com/and
Pylint_
-------

Content of `styles/pylint.toml <https://raw.githubusercontent.com/andreoliwa/nitpick/develop/styles/pylint.toml>`_:
Contents of `styles/pylint.toml <https://raw.githubusercontent.com/andreoliwa/nitpick/develop/styles/pylint.toml>`_:

.. code-block:: toml
Expand All @@ -328,7 +328,7 @@ Content of `styles/pylint.toml <https://raw.githubusercontent.com/andreoliwa/nit
Python 3.6
----------

Content of `styles/python36.toml <https://raw.githubusercontent.com/andreoliwa/nitpick/develop/styles/python36.toml>`_:
Contents of `styles/python36.toml <https://raw.githubusercontent.com/andreoliwa/nitpick/develop/styles/python36.toml>`_:

.. code-block:: toml
Expand All @@ -340,7 +340,7 @@ Content of `styles/python36.toml <https://raw.githubusercontent.com/andreoliwa/n
Python 3.7
----------

Content of `styles/python37.toml <https://raw.githubusercontent.com/andreoliwa/nitpick/develop/styles/python37.toml>`_:
Contents of `styles/python37.toml <https://raw.githubusercontent.com/andreoliwa/nitpick/develop/styles/python37.toml>`_:

.. code-block:: toml
Expand All @@ -352,7 +352,7 @@ Content of `styles/python37.toml <https://raw.githubusercontent.com/andreoliwa/n
Python 3.8
----------

Content of `styles/python38.toml <https://raw.githubusercontent.com/andreoliwa/nitpick/develop/styles/python38.toml>`_:
Contents of `styles/python38.toml <https://raw.githubusercontent.com/andreoliwa/nitpick/develop/styles/python38.toml>`_:

.. code-block:: toml
Expand All @@ -364,7 +364,7 @@ Content of `styles/python38.toml <https://raw.githubusercontent.com/andreoliwa/n
Python 3.9
----------

Content of `styles/python39.toml <https://raw.githubusercontent.com/andreoliwa/nitpick/develop/styles/python39.toml>`_:
Contents of `styles/python39.toml <https://raw.githubusercontent.com/andreoliwa/nitpick/develop/styles/python39.toml>`_:

.. code-block:: toml
Expand Down
4 changes: 2 additions & 2 deletions docs/generate_rst.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def generate_defaults(filename: str):
{header}
{dashes}
Content of `{toml_file} <{base_url}/develop/{toml_file}>`_:
Contents of `{toml_file} <{base_url}/develop/{toml_file}>`_:
.. code-block:: toml
Expand Down Expand Up @@ -173,7 +173,7 @@ def generate_cli(filename: str) -> None:
{dashes}
{long}
.. code-block:: shell
.. code-block::
{help}
"""
Expand Down
40 changes: 40 additions & 0 deletions docs/ideas/ini.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Keys should be present
["setup.cfg".flake8]
ignore__present = "str"
max-line-length__present = "int"
exclude__present = "str"
max-complexity__present = "int"
inline-quotes__present = "str"

# Keys should be absent
["setup.cfg".some-section]
ignore__present = true
max-line-length__present = true
exclude__present = true
max-complexity__present = true
inline-quotes__present = true

# Section should be absent
["setup.cfg".darglint]
__present = false
blabla = "{{ nit.section_absent() }}"

# Section should be absent
["setup.cfg"."tox:tox"]
__present = false
["setup.cfg"."gh-actions"]
__present = false

# Section should be present
["tox.ini"."tox"]
__present = true
["tox.ini".gh-actions]
__present = true

# Keys should be present using Jinja
["setup.cfg".flake82]
ignore = "{{ nit.present(str, validators=[comma_separated_str]) }}"
max-line-length = "{{ nit.present(int, validators=[range(80, 120)]) }}"
exclude = "{{ nit.present(str, validators=[comma_separated_str]) }}"
max-complexity = "{{ nit.present(int) }}"
inline-quotes = "{{ nit.present(str, choices=['double', 'single']) }}"
File renamed without changes.
36 changes: 36 additions & 0 deletions docs/ideas/toml.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Keys are absent
["pyproject.toml".tool.poetry.dev-dependencies]
pep257__present = false
pycodestyle__present = false
pur__present = false
pep257 = "{{ nit.absent() }}" # Jinja
pycodestyle = "{{ nit.absent() }}" # Jinja
pur = "{{ nit.absent() }}" # Jinja

# Keys are absent
["pyproject.toml".tool.poetry.dependencies]
pep257__present = false
pycodestyle__present = false
pur__present = false
pep257 = "{{ nit.absent() }}" # Jinja
pycodestyle = "{{ nit.absent() }}" # Jinja
pur = "{{ nit.absent() }}" # Jinja

# TODO: pre-processing with Jinja to generate multiple sections with the same config? ["pyproject.toml".tool.poetry.{{ ['dependencies', 'dev-dependencies'] }}]

# Keys are present, with the expected types
["pyproject.toml".build-system]
requires__present = "List[str]"
build-backend__present = "str"
requires = "{{ nit.present(List[str]) }}" # Jinja
build-backend = "{{ nit.present(str) }}" # Jinja

# Integer key exists
["pyproject.toml".tool.black]
line-length__present = "int"
line-length = "{{ nit.present(int) }}" # Jinja

# Section exists with anything inside
["pyproject.toml".tool.black2]
__present = true
blabla = "{{ nit.section_present() }}" # Jinja
Empty file added docs/ideas/yaml.toml
Empty file.
30 changes: 18 additions & 12 deletions docs/plugins.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,17 @@ Below are the currently included plugins.

.. auto-generated-from-here
.. _setupcfgplugin:

setup.cfg
---------

Enforce config on `setup.cfg <https://docs.python.org/3/distutils/configfile.html>`_.

Example: :ref:`flake8 configuration <default-flake8>`.

.. _pyprojecttomlplugin:

pyproject.toml
--------------

Enforce config on `pyproject.toml <https://github.com/python-poetry/poetry/blob/master/docs/docs/pyproject.md>`_.
Enforce config on `pyproject.toml (PEP 518) <https://www.python.org/dev/peps/pep-0518/#file-format>`_.

See also `PEP 518 <https://www.python.org/dev/peps/pep-0518/>`_.
See also `the [tool.poetry] section of the pyproject.toml file
<https://github.com/python-poetry/poetry/blob/master/docs/docs/pyproject.md>`_.

Example: :ref:`the Python 3.7 default <default-python-3-7>`.
Example: :ref:`the Python 3.8 default <default-python-3-8>`.
There are many other examples in :ref:`defaults`.

.. _precommitplugin:
Expand All @@ -43,6 +35,20 @@ Enforce configuration for `.pre-commit-config.yaml <https://pre-commit.com/#pre-

Example: :ref:`the default pre-commit hooks <default-pre-commit-hooks>`.

.. _iniplugin:

INI files
---------

Enforce config on INI files.

Examples of ``.ini`` files handled by this plugin:

- `setup.cfg <setup-cfg>`_
- `.editorconfig <EditorConfig>`_

Example of Nitpick styles enforcing values on INI files: :ref:`flake8 configuration <default-flake8>`.

.. _jsonplugin:

JSON files
Expand Down
7 changes: 7 additions & 0 deletions docs/source/nitpick.plugins.ini.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
nitpick.plugins.ini module
==========================

.. automodule:: nitpick.plugins.ini
:members:
:undoc-members:
:show-inheritance:
2 changes: 1 addition & 1 deletion docs/source/nitpick.plugins.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ Submodules

nitpick.plugins.base
nitpick.plugins.info
nitpick.plugins.ini
nitpick.plugins.json
nitpick.plugins.pre_commit
nitpick.plugins.pyproject_toml
nitpick.plugins.setup_cfg
nitpick.plugins.text
7 changes: 0 additions & 7 deletions docs/source/nitpick.plugins.setup_cfg.rst

This file was deleted.

Loading

0 comments on commit 80c840b

Please sign in to comment.