From 249d25279a010709bca4515da8914159f86554b5 Mon Sep 17 00:00:00 2001 From: Anton Telyshev Date: Sun, 3 Mar 2024 17:50:52 +0300 Subject: [PATCH] self-review fixes --- internal/checkers/bool_compare.go | 36 ++++--------------------------- internal/config/config.go | 2 +- 2 files changed, 5 insertions(+), 33 deletions(-) diff --git a/internal/checkers/bool_compare.go b/internal/checkers/bool_compare.go index 6ede3d28..43907123 100644 --- a/internal/checkers/bool_compare.go +++ b/internal/checkers/bool_compare.go @@ -157,15 +157,8 @@ func (checker BoolCompare) Check(pass *analysis.Pass, call *CallMeta) *analysis. arg1, ok1 := isComparisonWithTrue(pass, expr, token.EQL) arg2, ok2 := isComparisonWithFalse(pass, expr, token.NEQ) - if anyCondSatisfaction(pass, isEmptyInterface, arg1, arg2) { - return nil - } - if anyCondSatisfaction(pass, isBoolOverride, arg1, arg2) { - return nil - } - survivingArg, ok := anyVal([]bool{ok1, ok2}, arg1, arg2) - if ok { + if ok && !isEmptyInterface(pass, survivingArg) { return newNeedSimplifyDiagnostic(survivingArg, expr.Pos(), expr.End()) } } @@ -175,15 +168,8 @@ func (checker BoolCompare) Check(pass *analysis.Pass, call *CallMeta) *analysis. arg2, ok2 := isComparisonWithFalse(pass, expr, token.EQL) arg3, ok3 := isNegation(expr) - if anyCondSatisfaction(pass, isEmptyInterface, arg1, arg2, arg3) { - return nil - } - if anyCondSatisfaction(pass, isBoolOverride, arg1, arg2, arg3) { - return nil - } - survivingArg, ok := anyVal([]bool{ok1, ok2, ok3}, arg1, arg2, arg3) - if ok { + if ok && !isEmptyInterface(pass, survivingArg) { return newUseFalseDiagnostic(survivingArg, expr.Pos(), expr.End()) } } @@ -198,15 +184,8 @@ func (checker BoolCompare) Check(pass *analysis.Pass, call *CallMeta) *analysis. arg1, ok1 := isComparisonWithTrue(pass, expr, token.EQL) arg2, ok2 := isComparisonWithFalse(pass, expr, token.NEQ) - if anyCondSatisfaction(pass, isEmptyInterface, arg1, arg2) { - return nil - } - if anyCondSatisfaction(pass, isBoolOverride, arg1, arg2) { - return nil - } - survivingArg, ok := anyVal([]bool{ok1, ok2}, arg1, arg2) - if ok { + if ok && !isEmptyInterface(pass, survivingArg) { return newNeedSimplifyDiagnostic(survivingArg, expr.Pos(), expr.End()) } } @@ -216,15 +195,8 @@ func (checker BoolCompare) Check(pass *analysis.Pass, call *CallMeta) *analysis. arg2, ok2 := isComparisonWithFalse(pass, expr, token.EQL) arg3, ok3 := isNegation(expr) - if anyCondSatisfaction(pass, isEmptyInterface, arg1, arg2, arg3) { - return nil - } - if anyCondSatisfaction(pass, isBoolOverride, arg1, arg2, arg3) { - return nil - } - survivingArg, ok := anyVal([]bool{ok1, ok2, ok3}, arg1, arg2, arg3) - if ok { + if ok && !isEmptyInterface(pass, survivingArg) { return newUseTrueDiagnostic(survivingArg, expr.Pos(), expr.End()) } } diff --git a/internal/config/config.go b/internal/config/config.go index 9e559e8a..7eba0ea3 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -98,7 +98,7 @@ func BindToFlags(cfg *Config, fs *flag.FlagSet) { fs.Var(&cfg.EnabledCheckers, "enable", "comma separated list of enabled checkers (in addition to enabled by default)") fs.BoolVar(&cfg.BoolCompare.IgnoreCustomTypes, "bool-compare.ignore-custom-types", false, - "ignore user defined types (over builtin `bool`)") + "ignore user defined types (over builtin bool)") fs.Var(&cfg.ExpectedActual.ExpVarPattern, "expected-actual.pattern", "regexp for expected variable name") fs.Var(&cfg.RequireError.FnPattern, "require-error.fn-pattern", "regexp for error assertions that should only be analyzed") fs.Var(NewEnumValue(suiteExtraAssertCallModeAsString, &cfg.SuiteExtraAssertCall.Mode),