Skip to content

Commit

Permalink
ci: spell-check the code as part of linting (#1388)
Browse files Browse the repository at this point in the history
Add a `codespell` run as part of the `tox -e lint` environment, to pick
up any spelling errors that might be missed in review. It's also added
to the pre-commit checks, for anyone using those.

The PR also makes 4 corrections, which codespell found. Two are
debatable (whether or not to hyphenate) but two are definite errors.

This adds a new (lint-time) dependency of codespell - it's also used in
the default charmcraft profile, I've used it before, and it has a [good
Snyk score](https://snyk.io/advisor/python/codespell) so it seems ok to
me. I have lightly skimmed the code, but not read it in depth.
  • Loading branch information
tonyandrewmeyer authored Sep 25, 2024
1 parent 64d9565 commit 6f90333
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 5 deletions.
9 changes: 8 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v4.5.0
hooks:
- id: check-added-large-files
- id: check-ast
Expand All @@ -24,3 +24,10 @@ repos:
args: [ --preview ]
- id: ruff-format
args: [ --preview ]
# Spellcheck the code.
- repo: https://github.com/codespell-project/codespell
rev: v2.2.4
hooks:
- id: codespell
additional_dependencies:
- tomli
2 changes: 1 addition & 1 deletion CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ In the interest of fostering an open and welcoming environment, we as
contributors and maintainers pledge to making participation in our project and
our community a harassment-free experience for everyone, regardless of age, body
size, disability, ethnicity, sex characteristics, gender identity and expression,
level of experience, education, socio-economic status, nationality, personal
level of experience, education, socioeconomic status, nationality, personal
appearance, race, religion, or sexual identity and orientation.

## Our Standards
Expand Down
2 changes: 1 addition & 1 deletion ops/_private/harness.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ def begin(self) -> None:
if self._charm is not None:
raise RuntimeError('cannot call the begin method on the harness more than once')

# The Framework adds attributes to class objects for events, etc. As such, we can't re-use
# The Framework adds attributes to class objects for events, etc. As such, we can't reuse
# the original class against multiple Frameworks. So create a locally defined class
# and register it.
# TODO: jam 2020-03-16 We are looking to changes this to Instance attributes instead of
Expand Down
4 changes: 2 additions & 2 deletions ops/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -3133,7 +3133,7 @@ def _format_action_result_dict(
parent_key: Optional[str] = None,
output: Optional[Dict[str, str]] = None,
) -> Dict[str, str]:
"""Turn a nested dictionary into a flattened dictionary, using '.' as a key seperator.
"""Turn a nested dictionary into a flattened dictionary, using '.' as a key separator.
This is used to allow nested dictionaries to be translated into the dotted format required by
the Juju `action-set` hook tool in order to set nested data on an action.
Expand Down Expand Up @@ -3973,7 +3973,7 @@ class CloudSpec:
"""A list of CA certificates."""

skip_tls_verify: bool = False
"""Whether to skip TLS verfication."""
"""Whether to skip TLS verification."""

is_controller_cloud: bool = False
"""If this is the cloud used by the controller, defaults to False."""
Expand Down
4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -224,3 +224,7 @@ reportUnnecessaryComparison = false
reportUnnecessaryTypeIgnoreComment = "error"
disableBytesTypePromotions = false
stubPath = ""

[tool.codespell]
skip = './docs/_build,.venv,venv,build'
quiet-level = 3
2 changes: 2 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,11 @@ commands =
description = Check code against coding style standards
deps =
ruff==0.4.5
codespell==2.3.0
commands =
ruff check --preview
ruff format --preview --check
codespell

[testenv:static]
description = Run static type checker
Expand Down

0 comments on commit 6f90333

Please sign in to comment.