diff --git a/src/nix-style-linter/lib.rs b/src/nix-style-linter/lib.rs index 4454cee..3ef7f07 100644 --- a/src/nix-style-linter/lib.rs +++ b/src/nix-style-linter/lib.rs @@ -66,7 +66,8 @@ pub fn run( let mut found_tool_errors = false; for path in paths { - match collect_nix_files(path) { + let path = resolve_workspace_path(path); + match collect_nix_files(&path) { Ok(files) => { for file in files { match lint_file(&file) { @@ -103,6 +104,18 @@ pub fn run( } } +fn resolve_workspace_path(path: &Path) -> PathBuf { + if path.is_absolute() { + return path.to_path_buf(); + } + + if let Some(workspace) = std::env::var_os("BUILD_WORKSPACE_DIRECTORY") { + return PathBuf::from(workspace).join(path); + } + + path.to_path_buf() +} + pub fn lint_file(path: &Path) -> io::Result> { let source = fs::read_to_string(path)?; let parse = rnix::Root::parse(&source);