From 36188788585813b6be5111892f31c7737629d3e0 Mon Sep 17 00:00:00 2001 From: Richardas Kuchinskas Date: Thu, 8 Aug 2024 22:43:48 +0300 Subject: [PATCH] refactoring for all types --- src/linter/quickfix.go | 4 ++-- src/linter/report.go | 2 +- src/linter/root_checker.go | 11 ++++------- 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/src/linter/quickfix.go b/src/linter/quickfix.go index f2452e14..1ffc3e49 100644 --- a/src/linter/quickfix.go +++ b/src/linter/quickfix.go @@ -47,11 +47,11 @@ func (g *QuickFixGenerator) NullForNotNullableProperty(prop *ir.PropertyStmt) qu } } -func (g *QuickFixGenerator) NullableStringType(param *ir.Name) quickfix.TextEdit { +func (g *QuickFixGenerator) NullableType(param *ir.Name) quickfix.TextEdit { return quickfix.TextEdit{ StartPos: param.Position.StartPos, EndPos: param.Position.EndPos, - Replacement: "?string", + Replacement: "?" + param.Value, } } diff --git a/src/linter/report.go b/src/linter/report.go index 3f64ac82..62996cee 100644 --- a/src/linter/report.go +++ b/src/linter/report.go @@ -26,7 +26,7 @@ func addBuiltinCheckers(reg *CheckersRegistry) { }, { - Name: "nullableString", + Name: "nullableType", Default: true, Quickfix: true, Comment: "Report not nullable string can be null.", diff --git a/src/linter/root_checker.go b/src/linter/root_checker.go index fc22f660..7acbfa3f 100644 --- a/src/linter/root_checker.go +++ b/src/linter/root_checker.go @@ -605,21 +605,18 @@ func (r *rootChecker) checkFuncParam(p *ir.Parameter) { return true }) r.CheckTypeHintFunctionParam(p) - r.CheckParamStringNullability(p) + r.CheckParamNullability(p) } -func (r *rootChecker) CheckParamStringNullability(p *ir.Parameter) { +func (r *rootChecker) CheckParamNullability(p *ir.Parameter) { if param, ok := p.VariableType.(*ir.Name); ok { - if param.Value != "string" { - return - } if defValue, ok := p.DefaultValue.(*ir.ConstFetchExpr); ok { if defValue.Constant.Value != "null" { return } - r.walker.Report(param, LevelWarning, "nullableString", "string with null default value should be explicitly nullable") - r.walker.addQuickFix("nullableString", r.quickfix.NullableStringType(param)) + r.walker.Report(param, LevelWarning, "nullableType", "string with null default value should be explicitly nullable") + r.walker.addQuickFix("nullableType", r.quickfix.NullableType(param)) } } }