MCPcopy Create free account
hub / github.com/0xMiden/node / comment_width

Function comment_width

xtask/src/main.rs:187–209  ·  view source on GitHub ↗
(explicit: Option<usize>, rustfmt_config: &Path)

Source from the content-addressed store, hash-verified

185}
186
187fn comment_width(explicit: Option<usize>, rustfmt_config: &Path) -> Result<usize> {
188 if let Some(width) = explicit {
189 return validate_width(width);
190 }
191
192 let source = match fs_err::read_to_string(rustfmt_config) {
193 Ok(source) => source,
194 Err(err) if err.kind() == ErrorKind::NotFound => return Ok(100),
195 Err(err) => {
196 return Err(err).with_context(|| format!("reading {}", rustfmt_config.display()));
197 },
198 };
199
200 let config = toml::from_str::<toml::Value>(&source)
201 .context("parsing rustfmt config for comment_width")?;
202 let width = config
203 .get("comment_width")
204 .and_then(toml::Value::as_integer)
205 .and_then(|width| usize::try_from(width).ok())
206 .unwrap_or(100);
207
208 validate_width(width)
209}
210
211fn validate_width(width: usize) -> Result<usize> {
212 ensure!(width >= 20, "comment width must be at least 20 columns");

Callers 1

run_fmt_commentsFunction · 0.85

Calls 4

validate_widthFunction · 0.85
kindMethod · 0.80
contextMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected