Summary#
[SuppressWarning("CODE")] is how you say I read that one, and I mean it.
[SuppressWarning("cost-unbounded-read")]
live var everyRoom = Room.ToList();A warning tells you something about your program that is usually a mistake. Some programs are correct and earn one anyway. Without a way to say so, you are left choosing between changing correct code and living with a message you have to re-read and re-dismiss every build — and a warning people learn to skip past has stopped working, for your case and for the next one.
Signature#
[SuppressWarning("CODE" [, "CODE"…])]CODE— the diagnostic code, exactly as the warning prints it — a compiler code (ENUM_VALUE_REINTERPRETED) or anosy lintrule id (cost-unbounded-read). String literals only.- Placed on a component member (an
action, amethod, a field, a lifecycle hook). - Several codes in one attribute, or several attributes, both work.
Description#
It covers ONE declaration#
The suppression applies to the declaration it sits on, and to nothing else. There is deliberately no file-wide or app-wide form: you are accepting one warning about one thing. A file-level switch would go on silencing the same warning in code written later, by someone who never made that judgement — which is the moment a suppression stops being a decision and becomes a blindfold.
It covers ONE code#
Naming a code silences that code. Every other warning the declaration earns — today's and tomorrow's — still arrives. That is what makes the attribute safe to leave in place: it does not turn anything off, it answers one question.
There is no bare [SuppressWarning]. It would mean "and whatever else this earns", which is the one thing you are
not in a position to agree to yet, so the compiler asks for the code instead.
It never touches an error#
Only warnings can be suppressed. An error says your program does not have a defined meaning; that is not a matter of opinion and there is nothing to accept.
Say WHY, in a comment#
The attribute records that you decided; it cannot record what you knew. A reader six months later needs the reason, and the reason is usually a sentence:
// There are eleven rooms and there will never be more — this is a fixed set, not a growing table.
[SuppressWarning("cost-unbounded-read")]
live var everyRoom = Room.ToList();If you cannot write that sentence, the warning is probably right.
Examples#
Accepting the commit-agency warning#
A board reads its whole column list on every visit. cost-unbounded-read is right that an unbounded read is usually
a paging bug waiting to happen — and here the set is fixed by the domain, so it is not.
[Principal] entity User { [MaxLength(255)] string Email; }
entity Column {
[MaxLength(80)] string Title;
security { allow read, create when IsAuthenticated; }
}
[Page("/board")]
component BoardPage() {
// A board has four columns and always will — this is a fixed set, not a growing table.
[SuppressWarning("cost-unbounded-read")]
live var columns = Column.ToList();
render {
Stack(gap: 2) {
foreach (var c in columns) { Text(c.Title); }
}
}
}Does one suppression cover the rest of the file?#
A suppression on one member says nothing about another. If a second member earns the same finding, it gets it — and that is the point: the first decision was about the first member.
[SuppressWarning("cost-unbounded-read")]
live var everyRoom = Room.ToList(); // accepted
live var everyBooking = Booking.ToList(); // still reported — nobody has said anything about this oneSee also#
- Log.* — writing to your app's own log, which is a different question from the compiler's.