Skip to content

Commit

Permalink
Start using pre-commit to maintain this project
Browse files Browse the repository at this point in the history
  • Loading branch information
s0undt3ch committed Feb 2, 2024
1 parent 025792b commit 3a73b96
Show file tree
Hide file tree
Showing 13 changed files with 762 additions and 531 deletions.
55 changes: 55 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
---
default_language_version:
python: python3

exclude: ^(doc/_static/.*|doc/_themes/.*)$
repos:

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: check-merge-conflict # Check for files that contain merge conflict strings.
- id: trailing-whitespace # Trims trailing whitespace.
args:
- --markdown-linebreak-ext=md
- id: mixed-line-ending # Replaces or checks mixed line ending.
args:
- --fix=lf
- id: end-of-file-fixer # Makes sure files end in a newline and only a newline.
- id: check-ast # Simply check whether files parse as valid python.
- id: check-case-conflict # Check for files with names that would conflict on a
# case-insensitive filesystem like MacOS HFS+ or Windows FAT.
- id: check-json # Attempts to load all json files to verify syntax.
- id: check-symlinks # Checks for symlinks which do not point to anything.
- id: debug-statements # Check for debugger imports and py37+ breakpoint() calls in python source.
- id: fix-byte-order-marker # removes UTF-8 byte order marker
- id: forbid-submodules # forbids any submodules in the repository.
- id: fix-encoding-pragma # Remove `# -*- coding: utf-8 -*-` from the top of python files.
args:
- --remove

# ----- Code Formatting and Analysis ---------------------------------------------------------->
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: "v0.2.0"
hooks:
- id: ruff
args:
- --fix
exclude: (.pre-commit-hooks/.*|docs/.*)\.py

- repo: https://github.com/psf/black
rev: 24.1.1
hooks:
- id: black
args: [-l 100]
exclude: src/saf/version.py

- repo: https://github.com/asottile/blacken-docs
rev: 1.16.0
hooks:
- id: blacken-docs
args: [--skip-errors]
files: ^(docs/.*\.rst|.*\.py)$
additional_dependencies:
- black==24.1.1
# <---- Code Formatting and Analysis -----------------------------------------------------------
1 change: 0 additions & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -199,4 +199,3 @@ Apache License
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
# salt-pylint
# salt-pylint
128 changes: 128 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,131 @@ build-backend = "setuptools.build_meta"
[tool.setuptools_scm]
write_to = "saltpylint/version.py"
write_to_template = "# pylint: skip-file\n\n__version__ = \"{version}\"\n"

[tool.ruff]
line-length = 120
show-fixes = true
output-format = "grouped"
target-version = "py38"
respect-gitignore = true
src = [
"saltpylint",
"tests",
"tools",
"examples",
]
extend-exclude = [
".nox/**",
]
extend-include = [
"setup.py",
"noxfile.py",
]
builtins = [
"__opts__",
"__salt__",
# "__context__",
# "__grains__",
# "__pillar__",
"__salt_system_encoding__",
]

[tool.ruff.lint]
select = ["ALL"]
ignore = [
# D* pydocstyle
"D200", # Reformat to one line
"D212", # Remove whitespace after opening quotes
"COM", # flake8-commas - Black takes care of this
"ERA", # eradicate
"SIM108", # Use ternary operator `A = X if Y else Z` instead of `if`-`else`-block
"PERF203", # `try`-`except` within a loop incurs performance overhead"
"PERF401", # Use a list comprehension to create a transformed list
"PERF402", # Use `list` or `list.copy` to create a copy of a list
"ANN", # Type annotations
]
ignore-init-module-imports = true

[tool.ruff.lint.per-file-ignores]
"**/*.py" = [
"D100", # Missing docstring in public module
"D101", # Missing docstring in public class
"D102", # Missing docstring in public method
"D103", # Missing docstring in public function
"D104", # Missing docstring in public package
"D107", # Missing docstring in `__init__`
"D205", # 1 blank line required between summary line and description
"D415", # First line should end with a period, question mark, or exclamation point
"PTH", # use pathlib.Path
"ARG001", # Unused function argument: *
"ARG002", # Unused method argument: *
]
"setup.py" = [
"D",
]
"noxfile.py" = [
"D",
"ANN",
"SLF001",
"C901",
"PLR0912",
"DTZ005",
"FBT002",
"PLR0913", # Too many arguments to function call"
"PLR0915", # Too many statements
]
"saltpylint/blacklist.py" = [
"BLE001", # Do not catch blind exception: `Exception`
]
"saltpylint/thirdparty.py" = [
"BLE001", # Do not catch blind exception: `Exception`
]
"tools/**/*.py" = [
"ANN201", # Missing return type annotation for public function"
"D104", # Missing docstring in public package
"FBT001", # Boolean positional arg in function definition
"FBT002", # Boolean default value in function definition
]
"tests/**/*.py" = [
"ANN", # Ignore missing type annotations in tests
"ARG001", # Unused function argument
"DTZ003", # The use of `datetime.datetime.utcnow()` is not allowed, use `datetime.datetime.now(tz=)` instead
"PLR2004", # Magic value used in comparison, consider replacing 3 with a constant variable
"PT001", # use @pytest.fixture() over @pytest.fixture
"PT023", # use @pytest.mark.<blah>() over @pytest.mark.<blah>
"RET504", # Unnecessary variable assignment before `return` statement"
"S101", # Ignore the use of 'assert ...' in tests
"S603", # `subprocess` call: check for execution of untrusted input
"SIM117", # Use a single `with` statement with multiple contexts instead of nested `with` statements
"TCH002", # Move third-party import into a type-checking block
"TCH003", # Move standard library import `pathlib` into a type-checking block
]

[tool.ruff.lint.flake8-quotes]
docstring-quotes = "double"

[tool.ruff.lint.pydocstyle]
# Use Google-style docstrings.
convention = "google"

[tool.ruff.lint.isort]
combine-as-imports = false
force-single-line = true
known-first-party = ["src"]
forced-separate = ["tests"]

[tool.ruff.lint.pep8-naming]
ignore-names = [
"__virtual__",
]
[tool.ruff.lint.pyupgrade]
# Preserve types, even if a file imports `from __future__ import annotations`.
keep-runtime-typing = true

[tool.ruff.lint.mccabe]
max-complexity = 45

[tool.ruff.lint.pylint]
max-branches = 45
max-returns = 10
max-statements = 100
1 change: 0 additions & 1 deletion saltpylint/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
# -*- coding: utf-8 -*-
Loading

0 comments on commit 3a73b96

Please sign in to comment.