Skip to content

bump bidichk from v0.1.1 to v0.2.0 #2347

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .golangci.example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,18 @@ output:

# all available settings of specific linters
linters-settings:
bidichk:
# The following configurations check for all mentioned invisible unicode
# runes. It can be omitted because all runes are enabled by default.
left-to-right-embedding: true
right-to-left-embedding: true
pop-directional-formatting: true
left-to-right-override: true
right-to-left-override: true
left-to-right-isolate: true
right-to-left-isolate: true
first-strong-isolate: true
pop-directional-isolate: true

cyclop:
# the maximal code complexity to report
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +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.1.1
github.com/breml/bidichk v0.2.0
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: 2 additions & 2 deletions go.sum

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

13 changes: 13 additions & 0 deletions pkg/config/linters_settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ var defaultLintersSettings = LintersSettings{
}

type LintersSettings struct {
BiDiChk BiDiChkSettings
Cyclop Cyclop
Depguard DepGuardSettings
Dogsled DogsledSettings
Expand Down Expand Up @@ -146,6 +147,18 @@ type LintersSettings struct {
Custom map[string]CustomLinterSettings
}

type BiDiChkSettings struct {
LeftToRightEmbedding bool `mapstructure:"left-to-right-embedding"`
RightToLeftEmbedding bool `mapstructure:"right-to-left-embedding"`
PopDirectionalFormatting bool `mapstructure:"pop-directional-formatting"`
LeftToRightOverride bool `mapstructure:"left-to-right-override"`
RightToLeftOverride bool `mapstructure:"right-to-left-override"`
LeftToRightIsolate bool `mapstructure:"left-to-right-isolate"`
RightToLeftIsolate bool `mapstructure:"right-to-left-isolate"`
FirstStrongIsolate bool `mapstructure:"first-strong-isolate"`
PopDirectionalIsolate bool `mapstructure:"pop-directional-isolate"`
}

type Cyclop struct {
MaxComplexity int `mapstructure:"max-complexity"`
PackageAverage float64 `mapstructure:"package-average"`
Expand Down
48 changes: 45 additions & 3 deletions pkg/golinters/bidichk.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,59 @@
package golinters

import (
"strings"

"github.com/breml/bidichk/pkg/bidichk"
"golang.org/x/tools/go/analysis"

"github.com/golangci/golangci-lint/pkg/config"
"github.com/golangci/golangci-lint/pkg/golinters/goanalysis"
)

func NewBiDiChkFuncName() *goanalysis.Linter {
func NewBiDiChkFuncName(cfg *config.BiDiChkSettings) *goanalysis.Linter {
a := bidichk.NewAnalyzer()

cfgMap := map[string]map[string]interface{}{}
if cfg != nil {
var opts []string

if cfg.LeftToRightEmbedding {
opts = append(opts, "LEFT-TO-RIGHT-EMBEDDING")
}
if cfg.RightToLeftEmbedding {
opts = append(opts, "RIGHT-TO-LEFT-EMBEDDING")
}
if cfg.PopDirectionalFormatting {
opts = append(opts, "POP-DIRECTIONAL-FORMATTING")
}
if cfg.LeftToRightOverride {
opts = append(opts, "LEFT-TO-RIGHT-OVERRIDE")
}
if cfg.RightToLeftOverride {
opts = append(opts, "RIGHT-TO-LEFT-OVERRIDE")
}
if cfg.LeftToRightIsolate {
opts = append(opts, "LEFT-TO-RIGHT-ISOLATE")
}
if cfg.RightToLeftIsolate {
opts = append(opts, "RIGHT-TO-LEFT-ISOLATE")
}
if cfg.FirstStrongIsolate {
opts = append(opts, "FIRST-STRONG-ISOLATE")
}
if cfg.PopDirectionalIsolate {
opts = append(opts, "POP-DIRECTIONAL-ISOLATE")
}

cfgMap[a.Name] = map[string]interface{}{
"disallowed-runes": strings.Join(opts, ","),
}
}

return goanalysis.NewLinter(
"bidichk",
"Checks for dangerous unicode character sequences",
[]*analysis.Analyzer{bidichk.Analyzer},
nil,
[]*analysis.Analyzer{a},
cfgMap,
).WithLoadMode(goanalysis.LoadModeSyntax)
}
4 changes: 3 additions & 1 deletion pkg/lint/lintersdb/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ func enableLinterConfigs(lcs []*linter.Config, isEnabled func(lc *linter.Config)

//nolint:funlen
func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
var bidichkCfg *config.BiDiChkSettings
var cyclopCfg *config.Cyclop
var errorlintCfg *config.ErrorLintSettings
var exhaustiveCfg *config.ExhaustiveSettings
Expand All @@ -126,6 +127,7 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
var nlreturnCfg *config.NlreturnSettings

if m.cfg != nil {
bidichkCfg = &m.cfg.LintersSettings.BiDiChk
cyclopCfg = &m.cfg.LintersSettings.Cyclop
errorlintCfg = &m.cfg.LintersSettings.ErrorLint
exhaustiveCfg = &m.cfg.LintersSettings.Exhaustive
Expand Down Expand Up @@ -542,7 +544,7 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
WithPresets(linter.PresetStyle).
WithLoadForGoAnalysis().
WithURL("https://github.com/blizzy78/varnamelen"),
linter.NewConfig(golinters.NewBiDiChkFuncName()).
linter.NewConfig(golinters.NewBiDiChkFuncName(bidichkCfg)).
WithSince("1.43.0").
WithPresets(linter.PresetBugs).
WithURL("https://github.com/breml/bidichk"),
Expand Down