(project_dir: &Path, files: impl IntoIterator<Item = PathBuf>)
| 109 | } |
| 110 | |
| 111 | pub(crate) fn dotnet_format(project_dir: &Path, files: impl IntoIterator<Item = PathBuf>) -> anyhow::Result<()> { |
| 112 | let cwd = std::env::current_dir().expect("Failed to retrieve current directory"); |
| 113 | duct::cmd( |
| 114 | "dotnet", |
| 115 | itertools::chain( |
| 116 | [ |
| 117 | "format", |
| 118 | // We can't guarantee that the output lives inside a valid project or solution, |
| 119 | // so to avoid crash we need to use the `dotnet whitespace --folder` mode instead |
| 120 | // of a full style-aware formatter. Still better than nothing though. |
| 121 | "whitespace", |
| 122 | "--folder", |
| 123 | project_dir.to_str().unwrap(), |
| 124 | // Our files are marked with <auto-generated /> and will be skipped without this option. |
| 125 | "--include-generated", |
| 126 | "--include", |
| 127 | ] |
| 128 | .into_iter() |
| 129 | .map_into::<OsString>(), |
| 130 | // Resolve absolute paths for all of the files, because we receive them as relative paths to cwd, but |
| 131 | // `dotnet format` will interpret those paths relative to `project_dir`. |
| 132 | files |
| 133 | .into_iter() |
| 134 | .map(|f| { |
| 135 | let f = if f.is_absolute() { f } else { cwd.join(f) }; |
| 136 | f.canonicalize().expect("Failed to canonicalize path: {f}") |
| 137 | }) |
| 138 | .map_into(), |
| 139 | ), |
| 140 | ) |
| 141 | .run()?; |
| 142 | Ok(()) |
| 143 | } |
no test coverage detected
searching dependent graphs…