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

Fix typos detected by the typos tool #1330

Merged
merged 15 commits into from
Nov 30, 2024
Merged

Conversation

airwoodix
Copy link
Contributor

This is a proposal to add the typos tool to the lint session.

The patch adds the tool to the Nox lint session and fixes the reported issues. Some issues require overriding the tools decision. To limit these cases, db4c4ef does some minor renaming, which hopefully also improves the code's readability.

Since file names in releasenotes/notes/**/*.yaml are automatically generated, they may contain false positives. This scenario is dealt with by suppressing filename spell-checking for files under releasenotes/.

@coveralls
Copy link

coveralls commented Nov 24, 2024

Pull Request Test Coverage Report for Build 12090600366

Details

  • 36 of 36 (100.0%) changed or added relevant lines in 9 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 95.869%

Totals Coverage Status
Change from base Build 11991065969: 0.0%
Covered Lines: 18287
Relevant Lines: 19075

💛 - Coveralls

Copy link
Collaborator

@IvanIsCoding IvanIsCoding left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Firstly, thanks for getting this started. I'd focus for now on submitting the typo fixes and not trying to get the tool on CI. I will explain why.

Typos should be a warning not a CI failure. It adds friction for new contributors and unfortunately we already have:

  • cargo clippy (fails CI)
  • ruff (fails CI)
  • cargo fmt (fails CI)
  • black (fails CI)
  • type annotations (fails CI)
  • release notes (fails only if not in the folder, if missing the CI passes)
  • documentation (fails only if formatted incorrectly, if missing the CI passes)

Because the development is asynchronous, that can delay how fast others can contribute. Some things like ruff add a lot of value, they find real bugs from time to time. Code formatters like black and cargo fmt are not strictly necessary but they help the codebase be more consistent. The type annotation checks are to prevent backsliding to a level before #401 (but it still allows bugs like #1322).

Ideally, we should have a bot messasing us with the new typos found in the PR. Something similar to the Code Coverage bot: if someone sends a PR and I see the bot commenting the coverage is low, I can immediately take action and ask for more tests. If you equip the reviewers to find typos I'd say it is a good balance.

@@ -26,7 +26,7 @@ jobs:
- uses: actions/setup-python@v5
with:
python-version: "3.10"
- run: pip install -U ruff==0.6.8 black~=24.8
- run: pip install -U ruff==0.6.8 black~=24.8 typos~=1.27
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's remove this from CI for now and try to add it as a warning

@@ -77,7 +77,7 @@ it just as it would if there was a prebuilt binary available.
> [!NOTE]
> To build from source you will need to ensure you have pip >=19.0.0
installed, which supports PEP-517, or that you have manually installed
`setuptools-rust` prior to running `pip install rustworkx`. If you recieve an
`setuptools-rust` prior to running `pip install rustworkx`. If you receive an
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an example of high-value contribution because README.md typos are read by everyone and a bit embarrasing

@@ -266,7 +266,7 @@ New Features

- A new method, :meth:`~rustworkx.PyDiGraph.remove_node_retain_edges`, has been
added to the :class:`~rustworkx.PyDiGraph` class. This method can be used to
remove a node and add edges from its predecesors to its successors.
remove a node and add edges from its predecessors to its successors.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not even sure if we process this file anymore but it is a high-value find

noxfile.py Outdated
@@ -49,6 +50,8 @@ def lint(session):
session.run("ruff", "check", "rustworkx", "retworkx", "setup.py")
session.run("cargo", "fmt", "--all", "--", "--check", external=True)
session.run("python", "tools/find_stray_release_notes.py")
session.run("typos", "--exclude", "releasenotes")
session.run("typos", "--no-check-filenames", "releasenotes")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ironically, releasenotes/ is one of the places I'd like to check for typos the most

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

releasenotes/ is checked, but not the filenames, because they the hashes from reno produce many false positives.

It may be possible to exclude file name checking for all YAML files or even YAML files within releasenotes/ by adjusting typos.toml. The split command looked less magic to me.

@@ -371,7 +371,7 @@ fn expand_blossom<E>(
// base.
assert!(label_ends[blossom].is_some());
let entry_child = in_blossoms[endpoints[label_ends[blossom].unwrap() ^ 1]];
// Decied in which direction we will go around the blossom.
// Decide in which direction we will go around the blossom.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an example of a find with low-value,, I don't want to block people when they make a typo on a code comment. Except if that code comment is a docstring of course

@@ -175,7 +175,7 @@ def test_raises_negative_cycle_bellman_ford_paths(self):
with self.assertRaises(rustworkx.NegativeCycle):
rustworkx.bellman_ford_shortest_paths(graph, 0, weight_fn=float)

def test_raises_negative_cycle_bellman_ford_path_lenghts(self):
def test_raises_negative_cycle_bellman_ford_path_lengths(self):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made this typo, it is silly but this is one of the cases where the tool blocking CI would not add much value. The test is still correct.

typos.toml Outdated
@@ -0,0 +1,4 @@
[default]
extend-ignore-words-re = [
"[Ss]toer",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is convenient that the tool supports this, but this list is bound to expand. I assume it tries to correct Stoer to Store?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, store is the suggested correction.

These cases become dangerous when using typos -w (edit in-place). With just a linter report, the problem is quickly spotted.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. The only change I will make is moving this from its own file to pyproject.toml as it is better to have all configurations centralized in a single file

@IvanIsCoding
Copy link
Collaborator

With that being said, for the next release we should run the release PR (like in #1228) through the tool if we don't have a bot by then. Many code review comments were humans trying to find typos.

@airwoodix airwoodix force-pushed the fix-typos branch 2 times, most recently from c57ca29 to e7cb30a Compare November 29, 2024 19:17
@airwoodix
Copy link
Contributor Author

Thanks for the feedback!

I understand your concerns and removed the CI check as you suggested. Would it be ok to keep it in the Nox lint session?

airwoodix/gh-typos-comment contains a prototype of an automatic PR comment with the spell checking report (see example in airwoodix/gh-typos-comment#3 - the comment is removed if the spell checker doesn't find anything). I'm not extremely familiar with Github Actions, but it seems that the recommended way of doing this is to have dependent workflows. However, these only trigger if the workflow file is in the main branch, so an equivalent of pr_comment.yml would need to be contributed separately to get the trigger in this PR. Would you consider reviewing such a patch?

@airwoodix airwoodix marked this pull request as ready for review November 29, 2024 21:19
typos.toml Outdated
@@ -0,0 +1,4 @@
[default]
extend-ignore-words-re = [
"[Ss]toer",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. The only change I will make is moving this from its own file to pyproject.toml as it is better to have all configurations centralized in a single file

noxfile.py Outdated
@@ -49,6 +50,8 @@ def lint(session):
session.run("ruff", "check", "rustworkx", "retworkx", "setup.py")
session.run("cargo", "fmt", "--all", "--", "--check", external=True)
session.run("python", "tools/find_stray_release_notes.py")
session.run("typos", "--exclude", "releasenotes")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will keep this is nox -etypos for two reasons:

  • it doesn't need rustworkx to be compiled (just like Black)
  • It might make our life easier if we want to have the separate CI pass

@@ -27,9 +27,9 @@ jobs:
with:
python-version: "3.10"
- run: pip install -U ruff==0.6.8 black~=24.8
- uses: dtolnay/rust-toolchain@stable
- uses: dtolnay/rust-toolchain@1.82
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will revert to use stable, we always want to build on the latest version

@IvanIsCoding
Copy link
Collaborator

Thanks for the feedback!

I understand your concerns and removed the CI check as you suggested. Would it be ok to keep it in the Nox lint session?

airwoodix/gh-typos-comment contains a prototype of an automatic PR comment with the spell checking report (see example in airwoodix/gh-typos-comment#3 - the comment is removed if the spell checker doesn't find anything). I'm not extremely familiar with Github Actions, but it seems that the recommended way of doing this is to have dependent workflows. However, these only trigger if the workflow file is in the main branch, so an equivalent of pr_comment.yml would need to be contributed separately to get the trigger in this PR. Would you consider reviewing such a patch?

You are going above and beyond with this! I think the concept is perfect. This PR is almost ready to merge, I will just make some minor edits and submit today.

With regards to the bot, I like the concept. I will need to think about how to organize the GitHub Action but I would feel comfortable with it living on a separate file. It can be a completely different workflow, typos seems to be a cheap command to run if we don't need to compile rustworkx

@IvanIsCoding IvanIsCoding added this pull request to the merge queue Nov 30, 2024
Merged via the queue into Qiskit:main with commit 680789b Nov 30, 2024
31 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants