Skip to content

Commit 5a6015c

Browse files
committed
Add bidichk linter
check for dangerous unicode character sequences
1 parent 9bb917d commit 5a6015c

File tree

5 files changed

+33
-0
lines changed

5 files changed

+33
-0
lines changed

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ require (
1515
github.com/bkielbasa/cyclop v1.2.0
1616
github.com/blizzy78/varnamelen v0.3.0
1717
github.com/bombsimon/wsl/v3 v3.3.0
18+
github.com/breml/bidichk v0.0.0-20211101215529-9b68d04c240e
1819
github.com/butuzov/ireturn v0.1.1
1920
github.com/charithe/durationcheck v0.0.9
2021
github.com/daixiang0/gci v0.2.9

go.sum

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/golinters/bidichk.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package golinters
2+
3+
import (
4+
"github.com/breml/bidichk/pkg/bidichk"
5+
"github.com/golangci/golangci-lint/pkg/golinters/goanalysis"
6+
"golang.org/x/tools/go/analysis"
7+
)
8+
9+
func NewBiDiChkFuncName() *goanalysis.Linter {
10+
return goanalysis.NewLinter(
11+
"bidichk",
12+
"Checks for dangerous unicode character sequences",
13+
[]*analysis.Analyzer{bidichk.Analyzer},
14+
nil,
15+
).WithLoadMode(goanalysis.LoadModeSyntax)
16+
}

pkg/lint/lintersdb/manager.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,10 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
542542
WithPresets(linter.PresetStyle).
543543
WithLoadForGoAnalysis().
544544
WithURL("https://github.com/blizzy78/varnamelen"),
545+
linter.NewConfig(golinters.NewBiDiChkFuncName()).
546+
WithSince("1.43.0").
547+
WithPresets(linter.PresetBugs).
548+
WithURL("https://github.com/breml/bidichk"),
545549

546550
// nolintlint must be last because it looks at the results of all the previous linters for unused nolint directives
547551
linter.NewConfig(golinters.NewNoLintLint()).

test/testdata/bidichk.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
//args: -Ebidichk
2+
package testdata
3+
4+
import "fmt"
5+
6+
func main() {
7+
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"
8+
}

0 commit comments

Comments
 (0)