Skip to content

Commit

Permalink
Refactor ignoring check as function
Browse files Browse the repository at this point in the history
  • Loading branch information
cdesaintguilhem committed Oct 13, 2024
1 parent b10b010 commit e77b629
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions src/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,16 @@ pub fn format_file(
// Read the patterns present on this line.
let pattern = Pattern::new(&line);

// Temporary state for working on this line
// Temporary state for working on this line.
let mut temp_state = state.clone();

// Update the state with the line number from the queue.
temp_state.linum_old = linum_old;
temp_state.ignore =
get_ignore(&line, &temp_state, logs, file, true);
temp_state.verbatim =
get_verbatim(&line, &temp_state, logs, file, true, &pattern);

// If the line should not be ignored ...
if !(temp_state.verbatim.visual || temp_state.ignore.visual) {
// ... format it.

if !set_format_ignore(&line, &mut temp_state, logs, file, &pattern)
{
// Check if the line should be split because of a pattern that should begin on a new line.
if needs_env_new_line(&line, &temp_state, &pattern) {
let (this_line, next_line) =
put_env_new_line(&line, &temp_state, file, args, logs);
Expand Down Expand Up @@ -119,6 +116,20 @@ pub fn format_file(
new_text
}

fn set_format_ignore(
line: &String,
temp_state: &mut State,
logs: &mut Vec<Log>,
file: &str,
pattern: &Pattern,
) -> bool {
temp_state.ignore = get_ignore(line, temp_state, logs, file, true);
temp_state.verbatim =
get_verbatim(line, temp_state, logs, file, true, pattern);

temp_state.verbatim.visual || temp_state.ignore.visual
}

/// Cleans the given text by removing extra line breaks and trailing spaces, and tabs if they shouldn't be used.
fn clean_text(text: &str, args: &Cli) -> String {
let mut text = remove_extra_newlines(text);
Expand Down

0 comments on commit e77b629

Please sign in to comment.