Skip to content

celfmt is not idempotent and eats comments #58

@efd6

Description

@efd6

It is not safe to run celfmt on formatted code for some comments. This is demonstrated by the following terminal session sequence where the comments here are progressively eaten by the formatter.

$ celfmt -agent -i data_stream/audit/agent/stream/cel.yml.hbs -o data_stream/audit/agent/stream/cel.yml.hbs 
$ git diff
diff --git a/packages/o365/data_stream/audit/agent/stream/cel.yml.hbs b/packages/o365/data_stream/audit/agent/stream/cel.yml.hbs
index 1209932495..b74dd101b2 100644
--- a/packages/o365/data_stream/audit/agent/stream/cel.yml.hbs
+++ b/packages/o365/data_stream/audit/agent/stream/cel.yml.hbs
@@ -469,17 +469,15 @@ program: |-
         )
       )
   ).as(state,
-    (
-      // Ensure that we bring the current type up to the current time,
-      // even if we did not get any content for the query period.
-      has(state.?work.curr_type) && state.?cursor.last_for.optMap(last_for,
-        state.work.curr_type.to_lower().as(curr_type, curr_type in last_for ?
-            timestamp(last_for[curr_type]) < now - duration("1h")
-          :
-            false
-        )
-      ).orValue(false) && !state.work.todo_type.exists(t, t == state.work.curr_type)
-    ) ?
+    (// Ensure that we bring the current type up to the current time,
+    // even if we did not get any content for the query period.
+    has(state.?work.curr_type) && state.?cursor.last_for.optMap(last_for,
+      state.work.curr_type.to_lower().as(curr_type, (curr_type in last_for) ?
+        (timestamp(last_for[curr_type]) < now - duration("1h"))
+      :
+        false
+      )
+    ).orValue(false) && !state.work.todo_type.exists(t, t == state.work.curr_type)) ?
       state.with(
         {
           "work": state.work.with({"todo_type": [state.work.curr_type] + state.work.todo_type}),
@@ -491,7 +489,8 @@ program: |-
     state.with(
       {
         "want_more": state.work.as(w,
-          size(w.?todo_type.orValue([])) != 0 || size(w.?todo_content.orValue([])) != 0 || w.?next_list.orValue("") != ""
+          size(w.?todo_type.orValue([])) != 0 || size(w.?todo_content.orValue([])) != 0 ||
+          w.?next_list.orValue("") != ""
         ),
       }
     )
$ celfmt -agent -i data_stream/audit/agent/stream/cel.yml.hbs -o data_stream/audit/agent/stream/cel.yml.hbs
$ git diff
diff --git a/packages/o365/data_stream/audit/agent/stream/cel.yml.hbs b/packages/o365/data_stream/audit/agent/stream/cel.yml.hbs
index 1209932495..60369197a9 100644
--- a/packages/o365/data_stream/audit/agent/stream/cel.yml.hbs
+++ b/packages/o365/data_stream/audit/agent/stream/cel.yml.hbs
@@ -469,17 +469,14 @@ program: |-
         )
       )
   ).as(state,
-    (
-      // Ensure that we bring the current type up to the current time,
-      // even if we did not get any content for the query period.
-      has(state.?work.curr_type) && state.?cursor.last_for.optMap(last_for,
-        state.work.curr_type.to_lower().as(curr_type, curr_type in last_for ?
-            timestamp(last_for[curr_type]) < now - duration("1h")
-          :
-            false
-        )
-      ).orValue(false) && !state.work.todo_type.exists(t, t == state.work.curr_type)
-    ) ?
+    (// even if we did not get any content for the query period.
+    has(state.?work.curr_type) && state.?cursor.last_for.optMap(last_for,
+      state.work.curr_type.to_lower().as(curr_type, (curr_type in last_for) ?
+        (timestamp(last_for[curr_type]) < now - duration("1h"))
+      :
+        false
+      )
+    ).orValue(false) && !state.work.todo_type.exists(t, t == state.work.curr_type)) ?
       state.with(
         {
           "work": state.work.with({"todo_type": [state.work.curr_type] + state.work.todo_type}),
@@ -491,7 +488,8 @@ program: |-
     state.with(
       {
         "want_more": state.work.as(w,
-          size(w.?todo_type.orValue([])) != 0 || size(w.?todo_content.orValue([])) != 0 || w.?next_list.orValue("") != ""
+          size(w.?todo_type.orValue([])) != 0 || size(w.?todo_content.orValue([])) != 0 ||
+          w.?next_list.orValue("") != ""
         ),
       }
     )
$ celfmt -agent -i data_stream/audit/agent/stream/cel.yml.hbs -o data_stream/audit/agent/stream/cel.yml.hbs
$ git diff
diff --git a/packages/o365/data_stream/audit/agent/stream/cel.yml.hbs b/packages/o365/data_stream/audit/agent/stream/cel.yml.hbs
index 1209932495..a86e327995 100644
--- a/packages/o365/data_stream/audit/agent/stream/cel.yml.hbs
+++ b/packages/o365/data_stream/audit/agent/stream/cel.yml.hbs
@@ -469,17 +469,13 @@ program: |-
         )
       )
   ).as(state,
-    (
-      // Ensure that we bring the current type up to the current time,
-      // even if we did not get any content for the query period.
-      has(state.?work.curr_type) && state.?cursor.last_for.optMap(last_for,
-        state.work.curr_type.to_lower().as(curr_type, curr_type in last_for ?
-            timestamp(last_for[curr_type]) < now - duration("1h")
-          :
-            false
-        )
-      ).orValue(false) && !state.work.todo_type.exists(t, t == state.work.curr_type)
-    ) ?
+    (has(state.?work.curr_type) && state.?cursor.last_for.optMap(last_for,
+      state.work.curr_type.to_lower().as(curr_type, (curr_type in last_for) ?
+        (timestamp(last_for[curr_type]) < now - duration("1h"))
+      :
+        false
+      )
+    ).orValue(false) && !state.work.todo_type.exists(t, t == state.work.curr_type)) ?
       state.with(
         {
           "work": state.work.with({"todo_type": [state.work.curr_type] + state.work.todo_type}),
@@ -491,7 +487,8 @@ program: |-
     state.with(
       {
         "want_more": state.work.as(w,
-          size(w.?todo_type.orValue([])) != 0 || size(w.?todo_content.orValue([])) != 0 || w.?next_list.orValue("") != ""
+          size(w.?todo_type.orValue([])) != 0 || size(w.?todo_content.orValue([])) != 0 ||
+          w.?next_list.orValue("") != ""
         ),
       }
     )

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions