Skip to content

Commit

Permalink
Merge pull request #44 from cdesaintguilhem/tidy-new-line-checking
Browse files Browse the repository at this point in the history
Remove ignore check from new line checking
  • Loading branch information
WGUNDERWOOD authored Oct 21, 2024
2 parents b35ee7f + 0c7f17f commit 4553ff1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ pub fn format_file(
) {
// 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) {
if needs_env_new_line(&line, &pattern) {
// Split the line into two ...
let (this_line, next_line) =
put_env_new_line(&line, &temp_state, file, args, logs);
Expand Down
16 changes: 5 additions & 11 deletions src/subs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,17 @@ pub fn remove_trailing_spaces(text: &str) -> String {
}

/// Check if environment should be split onto a new line
pub fn needs_env_new_line(
line: &str,
state: &State,
pattern: &Pattern,
) -> bool {
pub fn needs_env_new_line(line: &str, pattern: &Pattern) -> bool {
// Check if we should format this line and if we've matched an environment.
let not_ignored_and_contains_env = !state.verbatim.visual
&& !state.ignore.visual
&& (pattern.contains_env_begin
|| pattern.contains_env_end
|| pattern.contains_item)
let contains_splittable_env = (pattern.contains_env_begin
|| pattern.contains_env_end
|| pattern.contains_item)
&& (RE_ENV_BEGIN_SHARED_LINE.is_match(line)
|| RE_ENV_END_SHARED_LINE.is_match(line)
|| RE_ITEM_SHARED_LINE.is_match(line));

// If we're not ignoring and we've matched an environment ...
if not_ignored_and_contains_env {
if contains_splittable_env {
// ... return `true` if the comment index is `None`
// (which implies the split point must be in text), otherwise
// compare the index of the comment with the split point.
Expand Down

0 comments on commit 4553ff1

Please sign in to comment.