Skip to content

Commit

Permalink
make add_newlines public/private function agnostic
Browse files Browse the repository at this point in the history
  • Loading branch information
c12i committed May 18, 2024
1 parent 0b58eb5 commit 1da8b37
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use std::{ffi::OsString, path::PathBuf};
use anyhow::Context;
use convert_case::{Case, Casing};
use dialoguer::{theme::ColorfulTheme, Input, Select, Validator};
use regex::Regex;

use crate::error::{ScaffoldError, ScaffoldResult};
use crate::file_tree::{dir_content, FileTree};
Expand Down Expand Up @@ -189,9 +190,14 @@ fn add_newlines(input: &str) -> String {
}

// Add newlines between non #[hdk_extern] annoteted functions
if (line.trim().starts_with("fn") && i > 0) && (!lines[i - 1].starts_with("#[hdk_extern")) {
let functon_regex =
Regex::new(r"(?m)^\s*(pub\s+fn|fn)\s+\w+\s*\(").expect("functon_regex is ivalid");
if (functon_regex.is_match(line.trim()) && i > 0)
&& (!lines[i - 1].starts_with("#[hdk_extern"))
{
formatted_code.push_str("\n");
}

// Add newlines between #[derive] annotated structs/enums
if line.trim().starts_with("#[derive") && i > 0 {
formatted_code.push_str("\n");
Expand Down

0 comments on commit 1da8b37

Please sign in to comment.