Skip to content
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

Open
wants to merge 23 commits into
base: main
Choose a base branch
from

Conversation

lucasew
Copy link

@lucasew lucasew commented Jan 8, 2025

  • add problem npv_169
  • preparations to detect npv_169

The plan is to detect open withs that have the chance of shadowing variable.

@infinisil
Copy link
Member

I'm just taking a look myself, I'll try to create a trampoline for the kind of ratchet you'll need

@infinisil
Copy link
Member

As discussed on Matrix, this should really be a ratchet check. I've now made #144 for the basic structure to support file ratchet checks (without introducing any checks), and #145 to show how this PR can take advantage of it :)

@lucasew
Copy link
Author

lucasew commented Jan 9, 2025

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.

@lucasew lucasew force-pushed the 20250108-toplevel-with branch from a2ce768 to b0edbd7 Compare January 9, 2025 14:32
@lucasew
Copy link
Author

lucasew commented Jan 9, 2025

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
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here

Copy link
Member

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

nixpkgs-vet/src/files.rs

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,
};
will be different (but similar). 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.

@lucasew lucasew marked this pull request as ready for review January 10, 2025 03:28
@lucasew lucasew requested a review from infinisil January 10, 2025 03:29
@lucasew
Copy link
Author

lucasew commented Jan 10, 2025

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

Copy link
Member

@infinisil infinisil left a 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:

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!

infinisil and others added 16 commits January 14, 2025 10:02
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]>
@lucasew lucasew force-pushed the 20250108-toplevel-with branch from e716f34 to 205d2c8 Compare January 14, 2025 13:02
@nixos-discourse
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants