feat: adds suggestions to QuoteSpacing#3724
Open
hippietrail wants to merge 6 commits into
Open
Conversation
elijah-potter
requested changes
Jul 1, 2026
Comment on lines
+39
to
+53
| // Count quotes before this one to determine if it's opening (even) or closing (odd) | ||
| let quote_index = source[..quote_span.start] | ||
| .iter() | ||
| .filter(|&&c| c == '"') | ||
| .count(); | ||
|
|
||
| let mut suggestions = vec![ | ||
| super::Suggestion::ReplaceWith(vec![' ', '"']), | ||
| super::Suggestion::ReplaceWith(vec!['"', ' ']), | ||
| ]; | ||
|
|
||
| // Every odd-numbered quote is likely a close quote, ie space likely should be after it. | ||
| if quote_index % 2 == 1 { | ||
| suggestions.swap(0, 1); | ||
| } |
Collaborator
There was a problem hiding this comment.
You should not need to do this. Quote tokens include this information already using a pretty reliable algorithm.
Comment on lines
+102
to
+108
| fn fix_by_inserting_space_after() { | ||
| assert_suggestion_result( | ||
| "It's not a complete sentence since it lacks a verb but it would be valid as a title or answer to a question since \"dog runs\"are things which exist", | ||
| QuoteSpacing::default(), | ||
| "It's not a complete sentence since it lacks a verb but it would be valid as a title or answer to a question since \"dog runs\" are things which exist", | ||
| ); | ||
| } |
Collaborator
There was a problem hiding this comment.
Nice! I will want to fuzz it as well. This is a pretty high-profile rule.
…ote-spacing-suggestions
Adds a new `assert_first_suggestion_result` to test whether ordering the suggestions is working.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issues
N/A
Description
I noticed in an old GitHub comment of mine that I'd made a typo missing a space next to a quote and Harper was flagging it.
But it didn't suggest a fix.
This PR suggests both fixes, a space before the quote and a space after the quote.
I used an AI agent when I realized my naïve attempt was the wrong way to count
"tokens to decide whether to suggest inserting the space before or after should be the first choice.I also used more AI than I prefer to help refactor the assertion functions to be able to add a new one to test that the suggestion you want to be the first one actually is the first one.
I've gone through every line of the code the AI made and I'm pretty sure there's nothing I don't understand.
How Has This Been Tested?
AI Disclosure
If Your PR Implements or Enhances a Linter
Checklist