This lint rule ensures that std.Emit
calls are properly formatted for better readability, especially when they contain multiple arguments.
The std.Emit
function is commonly used for logging and event emission in Go programs. When these calls contain multiple key-value pairs, they can become difficult to read if not properly formatted. This rule aims to improve code readability and maintainability by enforcing a consistent formatting style for std.Emit
calls.
The rule will check for std.Emit
calls and suggest a formatted version if the call is not properly structured. The formatting guidelines are:
- The
std.Emit
call should be multi-line if it has more than 3 arguments. - The event type (first argument) should be on its own line.
- Each key-value pair should be on its own line.
- The closing parenthesis should be on a new line.
- Rule ID: emit-format
- Severity: warning
- Category: Style
- Auto-fixable: Yes
std.Emit(
"OwnershipChange",
"newOwner", newOwner.String(),
"oldOwner",
oldOwner.String(),
"anotherOwner", anotherOwner.String(),
)
std.Emit(
"OwnershipChange", // event type
"newOwner", newOwner.String(), // key-value pair
"oldOwner", oldOwner.String(), // key-value pair
"anotherOwner", anotherOwner.String(), // key-value pair
)