Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(yaml): autofix .pre-commit-config.yaml (note: style changed!) #434

Merged
merged 33 commits into from
Jan 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
7a93d94
feat: append elements on a lisy
andreoliwa Jan 2, 2022
059935b
refactor: format_class to doc_class
andreoliwa Jan 2, 2022
1d5f219
feat: only display the element that is missing
andreoliwa Jan 2, 2022
19b9fdf
test: a few more green tests
andreoliwa Jan 2, 2022
8c244c8
docs: trying to preserve comments
andreoliwa Jan 2, 2022
046ba3d
test: fix all of them 🎉🔥
andreoliwa Jan 2, 2022
fe3f045
refactor: mutable mapping
andreoliwa Jan 2, 2022
e0cc97c
refactor: JsonDict everywhere
andreoliwa Jan 2, 2022
6fa0249
refactor: JsonDict replaces JsonYaml
andreoliwa Jan 2, 2022
240f3a9
test: deprecation warning for "repos.yaml" key
andreoliwa Jan 2, 2022
e344dc7
style: remove deprecated repos.yaml key from all styles
andreoliwa Jan 2, 2022
506b407
docs: ideas for presence/absence of keys
andreoliwa Jan 2, 2022
d79cdf0
feat(yaml): custom unique keys for fields
andreoliwa Jan 3, 2022
29c54a4
docs: more comments
andreoliwa Jan 3, 2022
00171b8
docs: more small fixes
andreoliwa Jan 3, 2022
f25badb
docs: ReadTheDocs still didn't upgrade to Python 3.9
andreoliwa Jan 3, 2022
24c2710
Merge branch 'develop' into autofix-pre-commit-config
andreoliwa Jan 3, 2022
23020dd
test: overriding the default unique key with nothing
andreoliwa Jan 3, 2022
ac5673e
Merge remote-tracking branch 'origin/autofix-pre-commit-config' into …
andreoliwa Jan 3, 2022
6d1b495
test: overriding unique keys
andreoliwa Jan 4, 2022
494bf51
Merge branch 'develop' into autofix-pre-commit-config
andreoliwa Jan 4, 2022
9de6003
test: when the key already exists, don't show diff (complex case)
andreoliwa Jan 5, 2022
13cb0b9
docs: maybe a way to compare elements
andreoliwa Jan 5, 2022
7bd27b0
feat: compare elements individually
andreoliwa Jan 7, 2022
a5a3da6
refactor: slightly reduce complexity (not ideal yet)
andreoliwa Jan 7, 2022
3947382
docs: remember to test more cases
andreoliwa Jan 7, 2022
1bce0b1
docs: more cases... this will never end
andreoliwa Jan 7, 2022
357ce8e
test: nested dict with different key/value pairs
andreoliwa Jan 7, 2022
e88a7f1
test: hook with different dependencies
andreoliwa Jan 7, 2022
f0b6204
docs: remove comments that will be handled in another PR
andreoliwa Jan 7, 2022
42df9a4
docs: improve YAML plugin docstring
andreoliwa Jan 7, 2022
a835796
docs: fix .rst warnings/notes
andreoliwa Jan 7, 2022
6c228d7
chore: remove dead code
andreoliwa Jan 7, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 14 additions & 16 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,20 @@ repos:
rev: v2.31.0
hooks:
- id: pyupgrade
- repo: https://github.com/myint/autoflake
rev: v1.4
hooks:
- id: autoflake
args:
[
--in-place,
--remove-all-unused-imports,
--remove-unused-variables,
--remove-duplicate-keys,
--ignore-init-module-imports,
--exclude,
compat.py,
]
- repo: https://github.com/psf/black
rev: 21.12b0
hooks:
Expand Down Expand Up @@ -66,22 +80,6 @@ repos:
hooks:
- id: prettier
stages: [commit]
- repo: https://github.com/myint/autoflake
rev: v1.4
hooks:
- id: autoflake
name: autoflake
language: python
args:
[
--in-place,
--remove-all-unused-imports,
--remove-unused-variables,
--remove-duplicate-keys,
--ignore-init-module-imports,
--exclude,
compat.py,
]
- repo: https://github.com/PyCQA/flake8
rev: 4.0.1
hooks:
Expand Down
4 changes: 3 additions & 1 deletion CONTRIBUTING.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.. include:: targets.rst

============
Contributing
============
Expand All @@ -11,7 +13,7 @@ Bug reports or feature requests
===============================

* First, search the `GitHub issue tracker <https://github.com/andreoliwa/nitpick/issues>`_ to see if your bug/feature is already there.
* If nothing is found, just `add a new issue and follow the instructions there <https://github.com/andreoliwa/nitpick/issues/new/choose>`_.
* If nothing is found, just `add a new issue and follow the instructions <new issue>`_.

Documentation improvements
==========================
Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ Implemented
- ✅
* - `.pre-commit-config.yaml <https://nitpick.rtfd.io/en/latest/plugins.html#pre-commit-config-yaml>`_
- ✅
- `#282 <https://github.com/andreoliwa/nitpick/issues/282>`_ 🚧
-
* - `.pylintrc <https://nitpick.rtfd.io/en/latest/plugins.html#ini-files>`_
- ✅
- ✅
Expand Down
218 changes: 131 additions & 87 deletions docs/examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,11 @@ Contents of `resources/any/commitizen.toml <https://github.com/andreoliwa/nitpic
.. code-block:: toml

[[".pre-commit-config.yaml".repos]]
yaml = """
- repo: https://github.com/commitizen-tools/commitizen
hooks:
- id: commitizen
stages: [commit-msg]
"""
repo = "https://github.com/commitizen-tools/commitizen"

[[".pre-commit-config.yaml".repos.hooks]]
id = "commitizen"
stages = ["commit-msg"]

.. _example-commitlint:

Expand All @@ -75,13 +74,12 @@ Contents of `resources/any/commitlint.toml <https://github.com/andreoliwa/nitpic
"""

[[".pre-commit-config.yaml".repos]]
yaml = """
- repo: https://github.com/alessandrojcm/commitlint-pre-commit-hook
hooks:
- id: commitlint
stages: [commit-msg]
additional_dependencies: ['@commitlint/config-conventional']
"""
repo = "https://github.com/alessandrojcm/commitlint-pre-commit-hook"

[[".pre-commit-config.yaml".repos.hooks]]
additional_dependencies = ["@commitlint/config-conventional"]
id = "commitlint"
stages = ["commit-msg"]

.. _example-editorconfig:

Expand Down Expand Up @@ -154,12 +152,13 @@ Contents of `resources/any/hooks.toml <https://github.com/andreoliwa/nitpick/blo
".pre-commit-config.yaml" = "Create the file with the contents below, then run 'pre-commit install'"

[[".pre-commit-config.yaml".repos]]
yaml = """
- repo: https://github.com/pre-commit/pre-commit-hooks
hooks:
- id: end-of-file-fixer
- id: trailing-whitespace
"""
repo = "https://github.com/pre-commit/pre-commit-hooks"

[[".pre-commit-config.yaml".repos.hooks]]
id = "end-of-file-fixer"

[[".pre-commit-config.yaml".repos.hooks]]
id = "trailing-whitespace"

.. _example-markdownlint:

Expand All @@ -174,6 +173,22 @@ Contents of `resources/any/markdownlint.toml <https://github.com/andreoliwa/nitp
# https://github.com/markdownlint/markdownlint
enabled = false

.. _example-prettier:

Prettier_
---------

Contents of `resources/any/prettier.toml <https://github.com/andreoliwa/nitpick/blob/v0.29.0/resources/any/prettier.toml>`_:

.. code-block:: toml

[[".pre-commit-config.yaml".repos]]
repo = "https://github.com/pre-commit/mirrors-prettier"

[[".pre-commit-config.yaml".repos.hooks]]
id = "prettier"
stages = ["commit"]

.. _example-package-json:

package.json_
Expand Down Expand Up @@ -203,6 +218,22 @@ Contents of `resources/python/absent.toml <https://github.com/andreoliwa/nitpick
".venv" = ""
".pyup.yml" = "Configure safety instead: https://github.com/pyupio/safety#using-safety-with-a-ci-service"

.. _example-autoflake:

autoflake_
----------

Contents of `resources/python/autoflake.toml <https://github.com/andreoliwa/nitpick/blob/v0.29.0/resources/python/autoflake.toml>`_:

.. code-block:: toml

[[".pre-commit-config.yaml".repos]]
repo = "https://github.com/myint/autoflake"

[[".pre-commit-config.yaml".repos.hooks]]
id = "autoflake"
args = ["--in-place", "--remove-all-unused-imports", "--remove-unused-variables", "--remove-duplicate-keys", "--ignore-init-module-imports"]

.. _example-bandit:

bandit_
Expand All @@ -212,6 +243,14 @@ Contents of `resources/python/bandit.toml <https://github.com/andreoliwa/nitpick

.. code-block:: toml

[[".pre-commit-config.yaml".repos]]
repo = "https://github.com/PyCQA/bandit"

[[".pre-commit-config.yaml".repos.hooks]]
id = "bandit"
args = ["--ini", "setup.cfg"]
exclude = "tests/"

[".codeclimate.yml".plugins.bandit] # https://docs.codeclimate.com/docs/bandit
# https://github.com/PyCQA/bandit
enabled = true
Expand All @@ -229,24 +268,18 @@ Contents of `resources/python/black.toml <https://github.com/andreoliwa/nitpick/
line-length = 120

[[".pre-commit-config.yaml".repos]]
yaml = """
- repo: https://github.com/psf/black
hooks:
- id: black
args: [--safe, --quiet]
- repo: https://github.com/asottile/blacken-docs
hooks:
- id: blacken-docs
additional_dependencies: [black==21.5b2]
"""
# TODO The toml library has issues loading arrays with multiline strings:
# https://github.com/uiri/toml/issues/123
# https://github.com/uiri/toml/issues/230
# If they are fixed one day, remove this 'yaml' key and use only a 'repos' list with a single element:
#[".pre-commit-config.yaml"]
#repos = ["""
#<YAML goes here>
#"""]
repo = "https://github.com/psf/black"

[[".pre-commit-config.yaml".repos.hooks]]
id = "black"
args = ["--safe", "--quiet"]

[[".pre-commit-config.yaml".repos]]
repo = "https://github.com/asottile/blacken-docs"

[[".pre-commit-config.yaml".repos.hooks]]
id = "blacken-docs"
additional_dependencies = ["black==21.5b2"]

.. _example-flake8:

Expand All @@ -270,26 +303,11 @@ Contents of `resources/python/flake8.toml <https://github.com/andreoliwa/nitpick
# This way, the developer has the choice of overriding this style, instead of having lots of plugins installed
# without being asked.
[[".pre-commit-config.yaml".repos]]
yaml = """
- repo: https://github.com/PyCQA/flake8
hooks:
- id: flake8
additional_dependencies:
[
flake8-blind-except,
flake8-bugbear,
flake8-comprehensions,
flake8-debugger,
flake8-docstrings,
flake8-isort,
flake8-polyfill,
flake8-pytest,
flake8-quotes,
flake8-typing-imports,
yesqa,
]
"""
# TODO suggest nitpick for external repos
repo = "https://github.com/PyCQA/flake8"

[[".pre-commit-config.yaml".repos.hooks]]
id = "flake8"
additional_dependencies = ["flake8-blind-except", "flake8-bugbear", "flake8-comprehensions", "flake8-debugger", "flake8-docstrings", "flake8-isort", "flake8-polyfill", "flake8-pytest", "flake8-quotes", "flake8-typing-imports", "yesqa"]

[".codeclimate.yml".plugins.pep8] # https://docs.codeclimate.com/docs/pep8 PEP8 already being checked by flake8 plugins on pre-commit
enabled = false
Expand Down Expand Up @@ -345,21 +363,34 @@ Contents of `resources/python/hooks.toml <https://github.com/andreoliwa/nitpick/
.. code-block:: toml

[[".pre-commit-config.yaml".repos]]
yaml = """
- repo: https://github.com/pre-commit/pygrep-hooks
hooks:
- id: python-check-blanket-noqa
- id: python-check-mock-methods
- id: python-no-eval
- id: python-no-log-warn
- id: rst-backticks
- repo: https://github.com/pre-commit/pre-commit-hooks
hooks:
- id: debug-statements
- repo: https://github.com/asottile/pyupgrade
hooks:
- id: pyupgrade
"""
repo = "https://github.com/pre-commit/pygrep-hooks"

[[".pre-commit-config.yaml".repos.hooks]]
id = "python-check-blanket-noqa"

[[".pre-commit-config.yaml".repos.hooks]]
id = "python-check-mock-methods"

[[".pre-commit-config.yaml".repos.hooks]]
id = "python-no-eval"

[[".pre-commit-config.yaml".repos.hooks]]
id = "python-no-log-warn"

[[".pre-commit-config.yaml".repos.hooks]]
id = "rst-backticks"

[[".pre-commit-config.yaml".repos]]
repo = "https://github.com/pre-commit/pre-commit-hooks"

[[".pre-commit-config.yaml".repos.hooks]]
id = "debug-statements"

[[".pre-commit-config.yaml".repos]]
repo = "https://github.com/asottile/pyupgrade"

[[".pre-commit-config.yaml".repos.hooks]]
id = "pyupgrade"

.. _example-ipython:

Expand Down Expand Up @@ -397,11 +428,10 @@ Contents of `resources/python/isort.toml <https://github.com/andreoliwa/nitpick/
combine_as_imports = true

[[".pre-commit-config.yaml".repos]]
yaml = """
- repo: https://github.com/PyCQA/isort
hooks:
- id: isort
"""
repo = "https://github.com/PyCQA/isort"

[[".pre-commit-config.yaml".repos.hooks]]
id = "isort"

.. _example-mypy:

Expand Down Expand Up @@ -431,11 +461,11 @@ Contents of `resources/python/mypy.toml <https://github.com/andreoliwa/nitpick/b
warn_unused_ignores = false

[[".pre-commit-config.yaml".repos]]
yaml = """
- repo: https://github.com/pre-commit/mirrors-mypy
hooks:
- id: mypy
"""
repo = "https://github.com/pre-commit/mirrors-mypy"

[[".pre-commit-config.yaml".repos.hooks]]
id = "mypy"
args = ["--show-error-codes"]

.. _example-poetry:

Expand Down Expand Up @@ -464,6 +494,18 @@ Contents of `resources/python/pylint.toml <https://github.com/andreoliwa/nitpick
["pyproject.toml".tool.poetry.extras]
lint = ["pylint"]

# pylint needs to be installed in the same venv as the project, to be more useful
# https://github.com/pre-commit/mirrors-pylint#using-pylint-with-pre-commit
[[".pre-commit-config.yaml".repos]]
repo = "local"

[[".pre-commit-config.yaml".repos.hooks]]
id = "pylint"
name = "pylint"
language = "system"
exclude = "tests/"
types = ["python"]

[".pylintrc".MASTER]
# Use multiple processes to speed up Pylint.
jobs = 1
Expand Down Expand Up @@ -689,11 +731,13 @@ Contents of `resources/shell/bashate.toml <https://github.com/andreoliwa/nitpick
.. code-block:: toml

[[".pre-commit-config.yaml".repos]]
yaml = """
- repo: https://github.com/openstack/bashate
hooks:
- id: bashate
"""
repo = "https://github.com/openstack/bashate"

[[".pre-commit-config.yaml".repos.hooks]]
id = "bashate"

# https://docs.openstack.org/bashate/latest/man/bashate.html#options
args = ["-i", "E006"]

.. _example-shellcheck:

Expand Down
4 changes: 3 additions & 1 deletion docs/generate_rst.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@
"python/sonar-python.toml": "sonar-python_",
"shell/shellcheck.toml": "shellcheck_",
"python/github-workflow.toml": "GitHub Workflow (Python)",
"python/autoflake.toml": "autoflake_",
"any/prettier.toml": "Prettier_",
}
)
CLI_MAPPING = [
Expand Down Expand Up @@ -167,7 +169,7 @@ def row(self) -> Tuple[str, str, str]:
f"Any YAML file (except {PRE_COMMIT_CONFIG_YAML})", f"{READ_THE_DOCS_URL}plugins.html#yaml-files", True, True
),
FileType(EDITOR_CONFIG, f"{READ_THE_DOCS_URL}examples.html#example-editorconfig", True, True),
FileType(PRE_COMMIT_CONFIG_YAML, f"{READ_THE_DOCS_URL}plugins.html#pre-commit-config-yaml", True, 282),
FileType(PRE_COMMIT_CONFIG_YAML, f"{READ_THE_DOCS_URL}plugins.html#pre-commit-config-yaml", True, True),
FileType(PYLINTRC, f"{READ_THE_DOCS_URL}plugins.html#ini-files", True, True),
FileType(PACKAGE_JSON, f"{READ_THE_DOCS_URL}examples.html#example-package-json", True, True),
FileType(PYPROJECT_TOML, f"{READ_THE_DOCS_URL}plugins.html#toml-files", True, True),
Expand Down
Loading