Skip to content

Commit

Permalink
chore: get core 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 940da4a commit 2d1dc3b
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 40 deletions.
7 changes: 2 additions & 5 deletions internal/core/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func (c *Config) addWordList(r io.Reader, accept bool) error {
scanner := bufio.NewScanner(r)
for scanner.Scan() {
word := strings.TrimSpace(scanner.Text())
if len(word) == 0 || strings.HasPrefix(word, "# ") {
if len(word) == 0 || strings.HasPrefix(word, "# ") { //nolint:gocritic
continue
} else if accept {
if _, ok := c.AcceptedTokens[word]; !ok {
Expand All @@ -130,10 +130,7 @@ func (c *Config) addWordList(r io.Reader, accept bool) error {
}
}
}
if err := scanner.Err(); err != nil {
return err
}
return nil
return scanner.Err()
}

func (c *Config) String() string {
Expand Down
8 changes: 2 additions & 6 deletions internal/core/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func annotate(file []byte, target string, finder errorCondition) (lineError, err
for scanner.Scan() {
markup := scanner.Text()
plain := StripANSI(markup)
if idx-context.line > 2 && context.line != 0 {
if idx-context.line > 2 && context.line != 0 { //nolint:gocritic
break
} else if finder(idx, plain, target) && context.line == 0 {
context.line = idx
Expand Down Expand Up @@ -64,7 +64,7 @@ func annotate(file []byte, target string, finder errorCondition) (lineError, err

// NewError creates a colored error from the given information.
//
// The standard format is
// # The standard format is
//
// ```
// <code> [<context>] <title>
Expand Down Expand Up @@ -102,10 +102,6 @@ func NewE201(msg, value, path string, finder errorCondition) error {
return NewE100("NewE201", errors.New(msg))
}

if err != nil {
return NewE100("NewE201/Highlight", err)
}

ctx, err := annotate(f, value, finder)
if err != nil {
return NewE100("NewE201/annotate", err)
Expand Down
8 changes: 4 additions & 4 deletions internal/core/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ func (f *File) ComputeMetrics() (map[string]interface{}, error) {
if strings.HasPrefix(k, "table") {
continue
}
k = strings.Replace(k, ".", "_", -1)
k = strings.ReplaceAll(k, ".", "_")
params[k] = float64(v)
}

Expand Down Expand Up @@ -259,8 +259,8 @@ func (f *File) AddAlert(a Alert, blk nlp.Block, lines, pad int, lookup bool) {

if _, found := f.history[entry]; !found {
// Check rule-assigned limits for reporting:
count, found := f.limits[a.Check]
if (!found || a.Limit == 0) || count < a.Limit {
count, occur := f.limits[a.Check]
if (!occur || a.Limit == 0) || count < a.Limit {
f.Alerts = append(f.Alerts, a)

f.history[entry] = 1
Expand All @@ -275,7 +275,7 @@ func (f *File) AddAlert(a Alert, blk nlp.Block, lines, pad int, lookup bool) {

// UpdateComments sets a new status based on comment.
func (f *File) UpdateComments(comment string) {
if comment == "vale off" {
if comment == "vale off" { //nolint:gocritic
f.Comments["off"] = true
} else if comment == "vale on" {
f.Comments["off"] = false
Expand Down
44 changes: 22 additions & 22 deletions internal/core/ini.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,45 +39,45 @@ var syntaxOpts = map[string]func(string, *ini.Section, *Config) error{

return nil
},
"IgnorePatterns": func(label string, sec *ini.Section, cfg *Config) error {
"IgnorePatterns": func(label string, sec *ini.Section, cfg *Config) error { //nolint:unparam
cfg.BlockIgnores[label] = sec.Key("IgnorePatterns").Strings(",")
return nil
},
"BlockIgnores": func(label string, sec *ini.Section, cfg *Config) error {
"BlockIgnores": func(label string, sec *ini.Section, cfg *Config) error { //nolint:unparam
cfg.BlockIgnores[label] = mergeValues(sec.Key("BlockIgnores").StringsWithShadows(","))
return nil
},
"TokenIgnores": func(label string, sec *ini.Section, cfg *Config) error {
"TokenIgnores": func(label string, sec *ini.Section, cfg *Config) error { //nolint:unparam
cfg.TokenIgnores[label] = mergeValues(sec.Key("TokenIgnores").StringsWithShadows(","))
return nil
},
"Transform": func(label string, sec *ini.Section, cfg *Config) error {
"Transform": func(label string, sec *ini.Section, cfg *Config) error { //nolint:unparam
candidate := sec.Key("Transform").String()
cfg.Stylesheets[label] = determinePath(cfg.Flags.Path, candidate)
return nil

},
"Lang": func(label string, sec *ini.Section, cfg *Config) error {
"Lang": func(label string, sec *ini.Section, cfg *Config) error { //nolint:unparam
cfg.FormatToLang[label] = sec.Key("Lang").String()
return nil
},
}

var globalOpts = map[string]func(*ini.Section, *Config, []string){
"BasedOnStyles": func(sec *ini.Section, cfg *Config, args []string) {
"BasedOnStyles": func(sec *ini.Section, cfg *Config, _ []string) {
cfg.GBaseStyles = mergeValues(sec.Key("BasedOnStyles").StringsWithShadows(","))
cfg.Styles = append(cfg.Styles, cfg.GBaseStyles...)
},
"IgnorePatterns": func(sec *ini.Section, cfg *Config, args []string) {
"IgnorePatterns": func(sec *ini.Section, cfg *Config, _ []string) {
cfg.BlockIgnores["*"] = sec.Key("IgnorePatterns").Strings(",")
},
"BlockIgnores": func(sec *ini.Section, cfg *Config, args []string) {
"BlockIgnores": func(sec *ini.Section, cfg *Config, _ []string) {
cfg.BlockIgnores["*"] = mergeValues(sec.Key("BlockIgnores").StringsWithShadows(","))
},
"TokenIgnores": func(sec *ini.Section, cfg *Config, args []string) {
"TokenIgnores": func(sec *ini.Section, cfg *Config, _ []string) {
cfg.TokenIgnores["*"] = mergeValues(sec.Key("TokenIgnores").StringsWithShadows(","))
},
"Lang": func(sec *ini.Section, cfg *Config, args []string) {
"Lang": func(sec *ini.Section, cfg *Config, _ []string) {
cfg.FormatToLang["*"] = sec.Key("Lang").String()
},
}
Expand Down Expand Up @@ -106,9 +106,9 @@ var coreOpts = map[string]func(*ini.Section, *Config, []string) error{
}
return nil
},
"MinAlertLevel": func(sec *ini.Section, cfg *Config, args []string) error {
"MinAlertLevel": func(sec *ini.Section, cfg *Config, _ []string) error {
if !StringInSlice(cfg.Flags.AlertLevel, AlertLevels) {
level := sec.Key("MinAlertLevel").String() //.In("suggestion", AlertLevels)
level := sec.Key("MinAlertLevel").String() // .In("suggestion", AlertLevels)
if index, found := LevelToInt[level]; found {
cfg.MinAlertLevel = index
} else {
Expand All @@ -120,27 +120,27 @@ var coreOpts = map[string]func(*ini.Section, *Config, []string) error{
}
return nil
},
"IgnoredScopes": func(sec *ini.Section, cfg *Config, args []string) error {
"IgnoredScopes": func(sec *ini.Section, cfg *Config, _ []string) error { //nolint:unparam
cfg.IgnoredScopes = mergeValues(sec.Key("IgnoredScopes").StringsWithShadows(","))
return nil
},
"WordTemplate": func(sec *ini.Section, cfg *Config, args []string) error {
"WordTemplate": func(sec *ini.Section, cfg *Config, _ []string) error { //nolint:unparam
cfg.WordTemplate = sec.Key("WordTemplate").String()
return nil
},
"DictionaryPath": func(sec *ini.Section, cfg *Config, args []string) error {
"DictionaryPath": func(sec *ini.Section, cfg *Config, _ []string) error { //nolint:unparam
cfg.DictionaryPath = sec.Key("DictionaryPath").String()
return nil
},
"SkippedScopes": func(sec *ini.Section, cfg *Config, args []string) error {
"SkippedScopes": func(sec *ini.Section, cfg *Config, _ []string) error { //nolint:unparam
cfg.SkippedScopes = mergeValues(sec.Key("SkippedScopes").StringsWithShadows(","))
return nil
},
"IgnoredClasses": func(sec *ini.Section, cfg *Config, args []string) error {
"IgnoredClasses": func(sec *ini.Section, cfg *Config, _ []string) error { //nolint:unparam
cfg.IgnoredClasses = mergeValues(sec.Key("IgnoredClasses").StringsWithShadows(","))
return nil
},
"Vocab": func(sec *ini.Section, cfg *Config, args []string) error {
"Vocab": func(sec *ini.Section, cfg *Config, _ []string) error {
cfg.Vocab = mergeValues(sec.Key("Vocab").StringsWithShadows(","))
for _, v := range cfg.Vocab {
if err := loadVocab(v, cfg); err != nil {
Expand All @@ -149,7 +149,7 @@ var coreOpts = map[string]func(*ini.Section, *Config, []string) error{
}
return nil
},
"NLPEndpoint": func(sec *ini.Section, cfg *Config, args []string) error {
"NLPEndpoint": func(sec *ini.Section, cfg *Config, _ []string) error { //nolint:unparam
cfg.NLPEndpoint = sec.Key("NLPEndpoint").MustString("")
return nil
},
Expand Down Expand Up @@ -179,7 +179,7 @@ func loadINI(cfg *Config, dry bool) error {
}

fromEnv, hasEnv := os.LookupEnv("VALE_CONFIG_PATH")
if cfg.Flags.Sources != "" {
if cfg.Flags.Sources != "" { //nolint:gocritic
// We have multiple sources -- e.g., local config + remote package(s).
//
// See fixtures/config.feature#451 for an explanation of how this has
Expand Down Expand Up @@ -300,7 +300,7 @@ func processConfig(uCfg *ini.File, cfg *Config, paths []string, dry bool) error
if err := f(core, cfg, paths); err != nil && !dry {
return err
}
} else if _, found := syntaxOpts[k]; found {
} else if _, found = syntaxOpts[k]; found {
msg := fmt.Sprintf("'%s' is a syntax-specific option", k)
return NewE201FromTarget(msg, k, cfg.RootINI)
}
Expand All @@ -320,7 +320,7 @@ func processConfig(uCfg *ini.File, cfg *Config, paths []string, dry bool) error
for _, k := range global.KeyStrings() {
if f, found := globalOpts[k]; found {
f(global, cfg, paths)
} else if _, found := syntaxOpts[k]; found {
} else if _, found = syntaxOpts[k]; found {
msg := fmt.Sprintf("'%s' is a syntax-specific option", k)
return NewE201FromTarget(msg, k, cfg.RootINI)
} else {
Expand Down
2 changes: 1 addition & 1 deletion internal/core/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func ReadPipeline(provider string, flags *CLIFlags, dry bool) (*Config, error) {
config, err := NewConfig(flags)
if err != nil {
return config, err
} else if err := validateFlags(config); err != nil {
} else if err = validateFlags(config); err != nil {
return config, err
}

Expand Down
4 changes: 2 additions & 2 deletions internal/core/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func StripANSI(s string) string {
// WhitespaceToSpace converts newlines and multiple spaces (e.g., " ") into a
// single space.
func WhitespaceToSpace(msg string) string {
msg = strings.Replace(msg, "\n", " ", -1)
msg = strings.ReplaceAll(msg, "\n", " ")
msg = spaces.ReplaceAllString(msg, " ")
return msg
}
Expand Down Expand Up @@ -205,7 +205,7 @@ func AllStringsInSlice(strings []string, slice []string) bool {
}

// SplitLines splits on CRLF, CR not followed by LF, and LF.
func SplitLines(data []byte, atEOF bool) (adv int, token []byte, err error) {
func SplitLines(data []byte, atEOF bool) (adv int, token []byte, err error) { //nolint:nonamedreturns
if atEOF && len(data) == 0 {
return 0, nil, nil
}
Expand Down

0 comments on commit 2d1dc3b

Please sign in to comment.