Skip to content

Commit

Permalink
Add bidichk linter
Browse files Browse the repository at this point in the history
check for dangerous unicode character sequences
  • Loading branch information
breml committed Nov 1, 2021
1 parent 9bb917d commit 5a6015c
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 0 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ require (
github.com/bkielbasa/cyclop v1.2.0
github.com/blizzy78/varnamelen v0.3.0
github.com/bombsimon/wsl/v3 v3.3.0
github.com/breml/bidichk v0.0.0-20211101215529-9b68d04c240e
github.com/butuzov/ireturn v0.1.1
github.com/charithe/durationcheck v0.0.9
github.com/daixiang0/gci v0.2.9
Expand Down
4 changes: 4 additions & 0 deletions go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions pkg/golinters/bidichk.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package golinters

import (
"github.com/breml/bidichk/pkg/bidichk"
"github.com/golangci/golangci-lint/pkg/golinters/goanalysis"
"golang.org/x/tools/go/analysis"
)

func NewBiDiChkFuncName() *goanalysis.Linter {
return goanalysis.NewLinter(
"bidichk",
"Checks for dangerous unicode character sequences",
[]*analysis.Analyzer{bidichk.Analyzer},
nil,
).WithLoadMode(goanalysis.LoadModeSyntax)
}
4 changes: 4 additions & 0 deletions pkg/lint/lintersdb/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,10 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
WithPresets(linter.PresetStyle).
WithLoadForGoAnalysis().
WithURL("https://github.com/blizzy78/varnamelen"),
linter.NewConfig(golinters.NewBiDiChkFuncName()).
WithSince("1.43.0").
WithPresets(linter.PresetBugs).
WithURL("https://github.com/breml/bidichk"),

// nolintlint must be last because it looks at the results of all the previous linters for unused nolint directives
linter.NewConfig(golinters.NewNoLintLint()).
Expand Down
8 changes: 8 additions & 0 deletions test/testdata/bidichk.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//args: -Ebidichk
package testdata

import "fmt"

func main() {
fmt.Println("LEFT-TO-RIGHT-OVERRIDE: '‭', it is between the single quotes, but it is not visible with a regular editor") // ERROR "found dangerous unicode character sequence LEFT-TO-RIGHT-OVERRIDE"
}

0 comments on commit 5a6015c

Please sign in to comment.