MCPcopy Create free account
hub / github.com/clockworklabs/SpacetimeDB / dotnet_format

Function dotnet_format

crates/cli/src/tasks/csharp.rs:111–143  ·  view source on GitHub ↗
(project_dir: &Path, files: impl IntoIterator<Item = PathBuf>)

Source from the content-addressed store, hash-verified

109}
110
111pub(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}

Callers 1

format_filesMethod · 0.85

Calls 7

joinMethod · 0.80
canonicalizeMethod · 0.80
OkFunction · 0.50
runMethod · 0.45
into_iterMethod · 0.45
unwrapMethod · 0.45
mapMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…