Skip to content

Commit

Permalink
chore: get spell passing new ci config
Browse files Browse the repository at this point in the history
  • Loading branch information
jdkato committed Aug 28, 2023
1 parent 3eb5d4d commit 940da4a
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 246 deletions.
17 changes: 9 additions & 8 deletions internal/spell/aff.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ type dictConfig struct {
}

// expand expands a word/affix using dictionary/affix rules
// This also supports CompoundRule flags
//
// This also supports CompoundRule flags
func (a dictConfig) expand(wordAffix string, out []string) ([]string, error) {
out = out[:0]
idx := strings.Index(wordAffix, "/")
Expand All @@ -82,7 +83,7 @@ func (a dictConfig) expand(wordAffix string, out []string) ([]string, error) {
return out, nil
}
if idx == 0 || idx+1 == len(wordAffix) {
return nil, fmt.Errorf("Slash char found in first or last position")
return nil, fmt.Errorf("slash char found in first or last position")
}
// safe
word, keyString := wordAffix[:idx], wordAffix[idx+1:]
Expand All @@ -91,7 +92,7 @@ func (a dictConfig) expand(wordAffix string, out []string) ([]string, error) {
// "compound only". If so then nothing to add
compoundOnly := false
for _, key := range keyString {
if strings.IndexRune(a.CompoundOnly, key) != -1 {
if strings.ContainsRune(a.CompoundOnly, key) {
compoundOnly = true
continue
}
Expand Down Expand Up @@ -158,7 +159,7 @@ func isCrossProduct(val string) (bool, error) {
}

// newDictConfig reads an Hunspell AFF file
func newDictConfig(file io.Reader) (*dictConfig, error) {
func newDictConfig(file io.Reader) (*dictConfig, error) { //nolint:funlen
aff := dictConfig{
Flag: "ASCII",
AffixMap: make(map[rune]affix),
Expand Down Expand Up @@ -257,7 +258,7 @@ func newDictConfig(file io.Reader) (*dictConfig, error) {
flag := rune(parts[1][0])
a, ok := aff.AffixMap[flag]
if !ok {
return nil, fmt.Errorf("Got rules for flag %q but no definition", flag)
return nil, fmt.Errorf("got rules for flag %q but no definition", flag)
}

strip := ""
Expand All @@ -270,13 +271,13 @@ func newDictConfig(file io.Reader) (*dictConfig, error) {
pat := parts[4]
if pat != "." {
if a.Type == Prefix {
pat = "^" + pat
pat += "^"
} else {
pat = pat + "$"
pat += "$"
}
matcher, err = regexp.Compile(pat)
if err != nil {
return nil, fmt.Errorf("Unable to compile %s", pat)
return nil, fmt.Errorf("unable to compile %s", pat)
}
}

Expand Down
77 changes: 0 additions & 77 deletions internal/spell/case.go

This file was deleted.

31 changes: 13 additions & 18 deletions internal/spell/gospell.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ type wordMatch struct {
}

type goSpell struct {
config dictConfig
dict map[string]struct{}
dict map[string]struct{}

ireplacer *strings.Replacer
compounds []*regexp.Regexp
Expand All @@ -43,11 +42,6 @@ func (s *goSpell) inputConversion(raw []byte) string {
return s.ireplacer.Replace(sraw)
}

// split a text into Words
func (s *goSpell) split(text string) []string {
return s.splitter.split(text)
}

// addWordRaw adds a single word to the internal dictionary without modifications
// returns true if added
// return false is already exists
Expand Down Expand Up @@ -122,10 +116,10 @@ func (s *goSpell) suggest(word string) []wordMatch {
})

hits := matches[:5]
if word == strings.Title(word) {
if word == strings.Title(word) { //nolint:staticcheck
// Capitalized word, so capitalize the suggestions
for i := range hits {
hits[i].word = strings.Title(hits[i].word)
hits[i].word = strings.Title(hits[i].word) //nolint:staticcheck
}
}

Expand Down Expand Up @@ -208,7 +202,7 @@ func newGoSpellReader(aff, dic io.Reader) (*goSpell, error) {

words, err = affix.expand(line, words)
if err != nil {
return nil, fmt.Errorf("Unable to process %q: %s", line, err)
return nil, fmt.Errorf("unable to process %q: %s", line, err.Error())
}

if len(words) == 0 {
Expand All @@ -220,7 +214,7 @@ func newGoSpellReader(aff, dic io.Reader) (*goSpell, error) {
}
}

if err := scanner.Err(); err != nil {
if err = scanner.Err(); err != nil {
return nil, err
}

Expand All @@ -229,16 +223,17 @@ func newGoSpellReader(aff, dic io.Reader) (*goSpell, error) {
for _, key := range compoundRule {
switch key {
case '(', ')', '+', '?', '*':
pattern = pattern + string(key)
pattern += string(key)
default:
groups := affix.compoundMap[key]
pattern = pattern + "(" + strings.Join(groups, "|") + ")"
}
}
pattern = pattern + "$"
pat, err := regexp.Compile(pattern)
if err != nil {
return nil, err
pattern += "$"

pat, perr := regexp.Compile(pattern)
if perr != nil {
return nil, perr
}
gs.compounds = append(gs.compounds, pat)
}
Expand All @@ -253,12 +248,12 @@ func newGoSpellReader(aff, dic io.Reader) (*goSpell, error) {
func newGoSpell(affFile, dicFile string) (*goSpell, error) {
aff, err := os.Open(affFile)
if err != nil {
return nil, fmt.Errorf("Unable to open aff: %s", err)
return nil, fmt.Errorf("unable to open aff: %s", err.Error())
}
defer aff.Close()
dic, err := os.Open(dicFile)
if err != nil {
return nil, fmt.Errorf("Unable to open dic: %s", err)
return nil, fmt.Errorf("unable to open dic: %s", err.Error())
}
defer dic.Close()
h, err := newGoSpellReader(aff, dic)
Expand Down
98 changes: 0 additions & 98 deletions internal/spell/notwords.go

This file was deleted.

Loading

0 comments on commit 940da4a

Please sign in to comment.