Skip to content

Commit

Permalink
refactoring for all types
Browse files Browse the repository at this point in the history
  • Loading branch information
Hidanio committed Aug 8, 2024
1 parent 8ff9869 commit 3618878
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/linter/quickfix.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/linter/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func addBuiltinCheckers(reg *CheckersRegistry) {
},

{
Name: "nullableString",
Name: "nullableType",
Default: true,
Quickfix: true,
Comment: "Report not nullable string can be null.",
Expand Down
11 changes: 4 additions & 7 deletions src/linter/root_checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}
}
Expand Down

0 comments on commit 3618878

Please sign in to comment.