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..72afbb2c 100644 --- a/src/linter/root_checker.go +++ b/src/linter/root_checker.go @@ -605,21 +605,17 @@ 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", "parameter with null default value should be explicitly nullable") + r.walker.addQuickFix("nullableType", r.quickfix.NullableType(param)) } } }