Skip to content

Commit

Permalink
golangci lint (#822)
Browse files Browse the repository at this point in the history
* chore: add dupword to golangci-lint

It checks for duplicate words in the source code.

Added in golangci-lint v1.50.0

Also, fix the reported issues

* chore: add usestdlibvars to golangci-lint

A linter that detect the possibility to use variables/constants from the Go standard library.

Added in golangci-lint v1.48.0

Also, fix the reported issue

* chore: add mirror to golangci-lint

A linter that reports wrong mirror patterns of bytes/strings usage.

Added in golangci-lint v1.53.0

Also, fix the reported issue

* chore: add thelper to golangci-lint

This linter checks tests helpers which is not start with t.Helper() method.

Added in golangci-lint v1.34.0

Also, fix the reported issues
  • Loading branch information
ccoVeille authored Jul 8, 2024
1 parent 2bc26fc commit 3c73133
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 8 deletions.
4 changes: 4 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ linters:
- bodyclose
- contextcheck
- dupl
- dupword
- durationcheck
- errname
- errorlint
Expand All @@ -91,6 +92,7 @@ linters:
- goprintffuncname
- gosec
- makezero
- mirror
- nakedret
- nilerr
- nilnil
Expand All @@ -105,8 +107,10 @@ linters:
- sqlclosecheck
- stylecheck
- tenv
- thelper
- tparallel
- unconvert
- unparam
- usestdlibvars
- wastedassign
- whitespace
2 changes: 1 addition & 1 deletion cmd/vale/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func fetch(src, dst string) error {

if err != nil {
return err
} else if resp.StatusCode != 200 {
} else if resp.StatusCode != http.StatusOK {
return fmt.Errorf("could not fetch '%s' (status code '%d')", src, resp.StatusCode)
}

Expand Down
2 changes: 1 addition & 1 deletion internal/check/existence.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func NewExistence(cfg *core.Config, generic baseCheck, path string) (Existence,
return rule, nil
}

// Run executes the the `existence`-based rule.
// Run executes the `existence`-based rule.
//
// This is simplest of the available extension points: it looks for any matches
// of its internal `pattern` (calculated from `NewExistence`) against the
Expand Down
2 changes: 1 addition & 1 deletion internal/check/repetition.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func NewRepetition(cfg *core.Config, generic baseCheck, path string) (Repetition
return rule, nil
}

// Run executes the the `repetition`-based rule.
// Run executes the `repetition`-based rule.
//
// The rule looks for repeated matches of its regex -- such as "this this".
func (o Repetition) Run(blk nlp.Block, _ *core.File) ([]core.Alert, error) {
Expand Down
2 changes: 1 addition & 1 deletion internal/check/substitution.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func NewSubstitution(cfg *core.Config, generic baseCheck, path string) (Substitu
return rule, nil
}

// Run executes the the `substitution`-based rule.
// Run executes the `substitution`-based rule.
//
// The rule looks for one pattern and then suggests a replacement.
func (s Substitution) Run(blk nlp.Block, _ *core.File) ([]core.Alert, error) {
Expand Down
2 changes: 1 addition & 1 deletion internal/core/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ func ReplaceAllStringSubmatchFunc(re *regexp.Regexp, str string, repl func([]str
result := ""
lastIndex := 0

for _, v := range re.FindAllSubmatchIndex([]byte(str), -1) {
for _, v := range re.FindAllStringSubmatchIndex(str, -1) {
groups := []string{}
for i := 0; i < len(v); i += 2 {
if v[i] == -1 || v[i+1] == -1 {
Expand Down
8 changes: 5 additions & 3 deletions internal/lint/lint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ func initLinter() (*Linter, error) {
return NewLinter(cfg)
}

func benchmarkLint(path string, b *testing.B) {
func benchmarkLint(b *testing.B, path string) {
b.Helper()

linter, err := initLinter()
if err != nil {
b.Fatal(err)
Expand All @@ -79,9 +81,9 @@ func benchmarkLint(path string, b *testing.B) {
}

func BenchmarkLintRST(b *testing.B) {
benchmarkLint("../../testdata/fixtures/benchmarks/bench.rst", b)
benchmarkLint(b, "../../testdata/fixtures/benchmarks/bench.rst")
}

func BenchmarkLintMD(b *testing.B) {
benchmarkLint("../../testdata/fixtures/benchmarks/bench.md", b)
benchmarkLint(b, "../../testdata/fixtures/benchmarks/bench.md")
}

0 comments on commit 3c73133

Please sign in to comment.