Files
atlantis/server/utils/spellcheck.go
Ed Laur 9b61288540 feat: Add check for misspelled executable name command (#3059)
* feat: Add check for misspelled executable name command

* Update server/utils/spellcheck_test.go

Co-authored-by: Ken Kaizu <k.kaizu38@gmail.com>

---------

Co-authored-by: nitrocode <7775707+nitrocode@users.noreply.github.com>
Co-authored-by: Ken Kaizu <k.kaizu38@gmail.com>
2023-02-22 00:45:14 +00:00

18 lines
483 B
Go

package utils
import (
"github.com/agext/levenshtein"
)
// IsSimilarWord calculates "The Levenshtein Distance" between two strings which
// represents the minimum total cost of edits that would convert the first string
// into the second. If the distance is less than 3, the word is considered misspelled.
func IsSimilarWord(given string, suggestion string) bool {
dist := levenshtein.Distance(given, suggestion, nil)
if dist > 0 && dist < 3 {
return true
}
return false
}