-
-
Notifications
You must be signed in to change notification settings - Fork 296
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
lib/utils: add mkWarnings #2848
base: main
Are you sure you want to change the base?
Conversation
cb0e51c
to
c742e9b
Compare
I like it just to be consistent treewide. Error is because you didn't inherit it in the lib/default.nix to get it available at top-level . |
Yes I plan to do it in this very PR. Was just waiting for feedback first ;)
Thanks, I'll change that. |
c0c458f
to
168ad19
Compare
Sorry, that was what I was trying to convey. I liked it to just get that consistency treewide without having to think about what our current warning formatting is and we only have to update it in one place to affect everywhere. |
Yes, I got this after answering ! |
168ad19
to
54a404c
Compare
@@ -82,6 +82,7 @@ lib.makeExtensible ( | |||
mkIfNonNull' | |||
mkRaw | |||
mkRawKey | |||
mkWarnings |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add a test to tests/lib-test.nix
?
54a404c
to
d69907c
Compare
lib/utils.nix
Outdated
|
||
processWarning = | ||
warning: | ||
lib.optional (warning.condition or true) ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Q: should the condition be inverted so that it matches assertion-style logic?
I always get confused when assertions have negative conditions and warnings have positive conditions.
Although "normal" warnings having positive conditions while nixvim-warnings having negative conditions would also be confusing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, my opinion is to keep them positive.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One way we could solve this is by having two well-known condition attrs: e.g. expect
and unless
or when
and whenNot
, etc
Speaking of names, I think condition
kinda implies "thing we expect to be true, warn when it is false"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One way we could solve this is by having two well-known condition attrs: e.g.
expect
andunless
orwhen
andwhenNot
, etc
I kinda like this... if we're going to create our own helper might as well make it feel more robust. I think we either have it follow upstream if just a plain condition or allow defining both postive/negative cases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree. I was planning to introduce a similar wrapper for assertions
too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could do something like:
processCondition = warning: warning.when or !(warning.expect or false);
?
Or could be more robust to prevent typos:
processCondition =
warning:
if warning ? when then
warning.when
else if warning ? expect then
!warning.expect
else if buitins.isString warning then
true
else
throw "warning is not a string and has no condition: ${toPretty { } warning}";
6574266
to
fef8f7a
Compare
Before you get too carried away with the treewide changes: We can consider using type = listOf (coercedTo attrs mkWarning str); This would prevent the need to have access to It may need to be a bit more complex than that, to allow for optional/conditional warning defs. So maybe we'd do this in another PR, if we even want to do it at all? |
fef8f7a
to
02aba2e
Compare
02aba2e
to
057364a
Compare
057364a
to
3fc2ae7
Compare
This aims to provide more consistency for our warnings.
Before:
After:
Notes:
mkWarnings
can either be a single conditional warning or a list of several ones.{ condition = ...; message = ...; }
attrs.