-
-
Notifications
You must be signed in to change notification settings - Fork 9
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
introduce npv_169 to detect top level withs #142
base: main
Are you sure you want to change the base?
Conversation
I'm just taking a look myself, I'll try to create a trampoline for the kind of ratchet you'll need |
I was playing on how to implement the validation itself and, after a lot of rust struggle, there it is: https://github.com/lucasew/playground/tree/master/projetos/20250108-with-detector-rust I may start using it more tho. |
a2ce768
to
b0edbd7
Compare
I rebased from #144 for the primitives |
src/files.rs
Outdated
) -> validation::Result<BTreeMap<RelativePathBuf, ratchet::File>> { | ||
process_nix_files(nixpkgs_path, nix_file_store, |nix_file| { | ||
if let Some(open_scope_with_lib) = find_invalid_withs(nix_file.syntax_root) { | ||
// TODO: what do I return |
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.
here
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.
Take a closer look at #145, which is pretty much what you need, except that
Lines 19 to 34 in 003a4ad
let file_is_str = match nix_file.syntax_root.expr() { | |
// This happens if the file can't be parsed, in which case we can't really decide | |
// whether it's a string or not | |
None => ratchet::RatchetState::NonApplicable, | |
// The expression is a string, not allowed for new files and for existing files to be | |
// changed to a string | |
Some(Str(_)) => ratchet::RatchetState::Loose( | |
npv_170::FileIsAString::new( | |
RelativePathBuf::from_path(nix_file.path.strip_prefix(nixpkgs_path).unwrap()) | |
.unwrap(), | |
) | |
.into(), | |
), | |
// This is good | |
Some(_) => ratchet::RatchetState::Tight, | |
}; |
file_is_str
(or a different name in your case) will be a RatchetState
, which should be Tight
if the code is as desired and it can't be improved further, and Loose
if there's an improvement to make.
The xrefcheck fail is related to a non-related test to this PR, a broken symlink but it seems on purpose to test a scenario |
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'm only reviewing the diff to #144 with this comparison. My feedback:
- You should document the new check here, describing exactly how it behaves. Based on that I also feel like the error message should be changed, because it doesn't seem to be just about top-level
with
's. - You should add a test that ensures an existing top-level with doesn't give an error if it still exists after a PR, similar to this test from Introduce bogus ratchet check ensuring that no new Nix string files are introduced #145
- The code should have more code comments explaining what it does
However, I guess most importantly, I don't think there's yet any consensus among Nixpkgs committers as to whether such a check is wanted or how exactly it should behave. Of course with the code here already written, it's easy to change the behavior, so I'd engage in NixOS/nixpkgs#371862, emphasising that you can easily change the code as desired, and maybe even make a Discourse post to get more input.
Sorry for the delayed reviews, am quite busy, but already thanks a lot for moving forward with improving CI, this is very valuable work!
A future commit introduces checks on all Nix files, but this is problematic if the base Nixpkgs version is part of the main Nixpkgs version
Signed-off-by: lucasew <[email protected]>
Signed-off-by: lucasew <[email protected]>
Signed-off-by: lucasew <[email protected]>
Signed-off-by: lucasew <[email protected]>
Signed-off-by: lucasew <[email protected]>
Signed-off-by: lucasew <[email protected]>
Signed-off-by: lucasew <[email protected]>
Signed-off-by: lucasew <[email protected]>
Signed-off-by: lucasew <[email protected]>
Signed-off-by: lucasew <[email protected]>
Signed-off-by: lucasew <[email protected]>
Signed-off-by: lucasew <[email protected]>
Signed-off-by: lucasew <[email protected]>
Signed-off-by: lucasew <[email protected]>
Signed-off-by: lucasew <[email protected]>
Signed-off-by: lucasew <[email protected]>
Signed-off-by: lucasew <[email protected]>
Signed-off-by: lucasew <[email protected]>
e716f34
to
205d2c8
Compare
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/best-practices-with-with/58857/6 |
Signed-off-by: lucasew <[email protected]>
Signed-off-by: lucasew <[email protected]>
The plan is to detect open
with
s that have the chance of shadowing variable.