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

Automatic suggestion fixes #5023

Open
aminya opened this issue Nov 28, 2023 · 1 comment
Open

Automatic suggestion fixes #5023

aminya opened this issue Nov 28, 2023 · 1 comment

Comments

@aminya
Copy link
Contributor

aminya commented Nov 28, 2023

Is your feature request related to a problem? Please describe.

It would be great to have a fix command where Cspell automatically takes the first suggestion and replaces the errors with that.

Describe the solution you'd like
I have written this Bash script to do that, however, I hope this is integrated into Cspell.

This requires the correct configuration of words to prevent false positive changes, which is needed anyway if a project wants to use Cspell.

#!/bin/bash

# Run cspell and capture output
pnpm i -g cspell || npm i -g cspell
output=$(cspell lint --show-suggestions --no-progress)

# Loop through each line of output
while read -r line; do
    # if line is empty, skip
    if [ -z "$line" ]; then
        continue
    fi

    # Get the file, word, and first suggestion
    file=$(echo "$line" | awk -F ':' '{print $1}')
    word=$(echo "$line" | awk -F '[(|)]' '{print $2}')
    first_suggestion=$(echo "$line" | awk -F 'Suggestions: ' '{print $2}' | awk -F '[[]|[]]' '{print $2}' | awk -F ',' '{print $1}' | sed 's/\*//g')

    # Replace the word with the suggestion (full word)
    sed -i "s/\b$word\b/$first_suggestion/g" "$file"

    echo "Replaced $word with $first_suggestion in $file"
done <<<"$output"

Additional context

I use Cspell for my project to fix spelling errors. However, it takes time for new projects that haven't used Cspell before to fix the errors manually.

@Jason3S
Copy link
Collaborator

Jason3S commented Nov 30, 2023

@aminya,

Thank you for the suggestion. It is on the list of things to improve.

Please see: #4725 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants