diff --git a/internal/core/config.go b/internal/core/config.go index 5d029303..21f9fb47 100644 --- a/internal/core/config.go +++ b/internal/core/config.go @@ -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 { @@ -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 { diff --git a/internal/core/error.go b/internal/core/error.go index 3753a004..2822c927 100644 --- a/internal/core/error.go +++ b/internal/core/error.go @@ -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 @@ -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 // // ``` // [] @@ -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) diff --git a/internal/core/file.go b/internal/core/file.go index 6bde218a..87d34483 100755 --- a/internal/core/file.go +++ b/internal/core/file.go @@ -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) } @@ -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 @@ -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 diff --git a/internal/core/ini.go b/internal/core/ini.go index b640ff34..16eac5de 100644 --- a/internal/core/ini.go +++ b/internal/core/ini.go @@ -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() }, } @@ -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 { @@ -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 { @@ -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 }, @@ -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 @@ -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) } @@ -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 { diff --git a/internal/core/source.go b/internal/core/source.go index 716ab547..309cc851 100644 --- a/internal/core/source.go +++ b/internal/core/source.go @@ -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 } diff --git a/internal/core/util.go b/internal/core/util.go index d1a26c89..5d1c9356 100755 --- a/internal/core/util.go +++ b/internal/core/util.go @@ -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 } @@ -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 }