about summary refs log tree commit diff
path: root/src/utils.rs
diff options
context:
space:
mode:
authorStéphane Campinas <stephane.campinas@gmail.com>2019-01-10 14:25:07 +0100
committerStéphane Campinas <stephane.campinas@gmail.com>2019-01-10 21:04:16 +0100
commitbaa62c609e421c4518070958df9ef721c20857e1 (patch)
treede1d023ad3c9264dbac2ddd09346026f6f15de34 /src/utils.rs
parent2c204c11d160cb2bee0802e4e9235fca0ffae421 (diff)
recognize strings inside comments in order to avoid indenting them
Close #3270
Diffstat (limited to 'src/utils.rs')
-rw-r--r--src/utils.rs15
1 files changed, 10 insertions, 5 deletions
diff --git a/src/utils.rs b/src/utils.rs
index a6a46df6ddc..dd480f9788f 100644
--- a/src/utils.rs
+++ b/src/utils.rs
@@ -527,8 +527,10 @@ pub fn trim_left_preserve_layout(orig: &str, indent: Indent, config: &Config) ->
                 Some(get_prefix_space_width(config, &line))
             };
 
-            let line = if veto_trim || (kind.is_string() && !line.ends_with('\\')) {
-                veto_trim = kind.is_string() && !line.ends_with('\\');
+            let new_veto_trim_value =
+                (kind.is_string() || kind.is_commented_string()) && !line.ends_with('\\');
+            let line = if veto_trim || new_veto_trim_value {
+                veto_trim = new_veto_trim_value;
                 trimmed = false;
                 line
             } else {
@@ -536,10 +538,13 @@ pub fn trim_left_preserve_layout(orig: &str, indent: Indent, config: &Config) ->
             };
             trimmed_lines.push((trimmed, line, prefix_space_width));
 
-            // When computing the minimum, do not consider lines within a string.
-            // The reason is there is a veto against trimming and indenting such lines
+            // Because there is a veto against trimming and indenting lines within a string,
+            // such lines should not be taken into account when computing the minimum.
             match kind {
-                FullCodeCharKind::InString | FullCodeCharKind::EndString => None,
+                FullCodeCharKind::InString
+                | FullCodeCharKind::EndString
+                | FullCodeCharKind::InStringCommented
+                | FullCodeCharKind::EndStringCommented => None,
                 _ => prefix_space_width,
             }
         })