DEV: Modernize tests, clean up (#47)

DEV: Modernize tests, clean up (#47)

diff --git a/.gitignore b/.gitignore
index d1ca10c..3c3629e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,11 +1 @@
-.idea
-*.iml
-.bundle/
-log/*.log
-pkg/
-auto_generated
-.DS_Store
-*.swp
 node_modules
-yarn-error.log
-.rubocop-https---raw-githubusercontent-com-discourse-*
diff --git a/.prettierrc b/.prettierrc
new file mode 100644
index 0000000..0967ef4
--- /dev/null
+++ b/.prettierrc
@@ -0,0 +1 @@
+{}
diff --git a/assets/javascripts/discourse/initializers/checklist.js b/assets/javascripts/discourse/initializers/checklist.js
new file mode 100644
index 0000000..b9247d1
--- /dev/null
+++ b/assets/javascripts/discourse/initializers/checklist.js
@@ -0,0 +1,122 @@
+import { withPluginApi } from "discourse/lib/plugin-api";
+import { ajax } from "discourse/lib/ajax";
+import { iconHTML } from "discourse-common/lib/icon-library";
+import I18n from "I18n";
+
+function initializePlugin(api) {
+  const siteSettings = api.container.lookup("site-settings:main");
+
+  if (siteSettings.checklist_enabled) {
+    api.decorateCooked(checklistSyntax, { id: "checklist" });
+  }
+}
+
+export function checklistSyntax($elem, postDecorator) {
+  if (!postDecorator) {
+    return;
+  }
+
+  const $boxes = $elem.find(".chcklst-box");
+  const postWidget = postDecorator.widget;
+  const postModel = postDecorator.getModel();
+
+  if (!postModel.can_edit) {
+    return;
+  }
+
+  $boxes.each((idx, val) => {
+    $(val).click((ev) => {
+      const $box = $(ev.currentTarget);
+
+      if ($box.hasClass("permanent")) {
+        return;
+      }
+
+      const newValue = $box.hasClass("checked") ? "[ ]" : "[x]";
+
+      $box.after(iconHTML("spinner", { class: "fa-spin" })).hide();
+
+      ajax(`/posts/${postModel.id}`, { type: "GET", cache: false }).then(
+        (result) => {
+          const blocks = [];
+
+          // Computing offsets where checkbox are not evaluated (i.e. inside
+          // code blocks).
+          [
+            // inline code
+            /`[^`\n]*\n?[^`\n]*`/gm,
+            // multi-line code
+            /^`‍``[^]*?^`‍``/gm,
+            // bbcode
+            /\[code\][^]*?\[\/code\]/gm,
+            // italic/bold
+            /_(?=\S).*?\S_/gm,
+            // strikethrough
+            /~~(?=\S).*?\S~~/gm,
+          ].forEach((regex) => {
+            let match;
+            while ((match = regex.exec(result.raw)) != null) {
+              blocks.push([match.index, match.index + match[0].length]);
+            }
+          });
+
+          [
+            // italic/bold
+            /([^\[\n]|^)\*\S.+?\S\*(?=[^\]\n]|$)/gm,
+          ].forEach((regex) => {
+            let match;
+            while ((match = regex.exec(result.raw)) != null) {
+              // Simulate lookbehind - skip the first character
+              blocks.push([match.index + 1, match.index + match[0].length]);
+            }
+          });
+
+          // make the first run go to index = 0
+          let nth = -1;
+          let found = false;
+          const newRaw = result.raw.replace(
+            /\[(\s|\_|\-|\x|\\?\*)?\]/gi,
+            (match, ignored, off) => {
+              if (found) {
+                return match;
+              }
+
+              nth += blocks.every(
+                (b) => b[0] >= off + match.length || off > b[1]
+              );
+
+              if (nth === idx) {
+                found = true; // Do not replace any further matches
+                return newValue;
+              }
+
+              return match;
+            }
+          );
+
+          const save = postModel.save({
+            raw: newRaw,
+            edit_reason: I18n.t("checklist.edit_reason"),
+          });
+
+          if (save && save.then) {
+            save.then(() => {
+              postWidget.attrs.isSaving = false;
+              postWidget.scheduleRerender();
+            });
+          }
+        }
+      );
+    });
+  });
+
+  // confirm the feature is enabled by showing the click-ability
+  $boxes.css({ cursor: "pointer" });
+}
+
+export default {
+  name: "checklist",
+  initialize: function () {
+    withPluginApi("0.1", (api) => initializePlugin(api));
+  },
+};
diff --git a/assets/javascripts/discourse/initializers/checklist.js.es6 b/assets/javascripts/discourse/initializers/checklist.js.es6
deleted file mode 100644
index b9247d1..0000000
--- a/assets/javascripts/discourse/initializers/checklist.js.es6
+++ /dev/null
@@ -1,122 +0,0 @@
-import { withPluginApi } from "discourse/lib/plugin-api";
-import { ajax } from "discourse/lib/ajax";
-import { iconHTML } from "discourse-common/lib/icon-library";
-import I18n from "I18n";
-
-function initializePlugin(api) {
-  const siteSettings = api.container.lookup("site-settings:main");
-
-  if (siteSettings.checklist_enabled) {
-    api.decorateCooked(checklistSyntax, { id: "checklist" });
-  }
-}
-
-export function checklistSyntax($elem, postDecorator) {
-  if (!postDecorator) {
-    return;
-  }
-
-  const $boxes = $elem.find(".chcklst-box");
-  const postWidget = postDecorator.widget;
-  const postModel = postDecorator.getModel();
-
-  if (!postModel.can_edit) {
-    return;
-  }
-
-  $boxes.each((idx, val) => {
-    $(val).click((ev) => {
-      const $box = $(ev.currentTarget);
-
-      if ($box.hasClass("permanent")) {
-        return;
-      }
-
-      const newValue = $box.hasClass("checked") ? "[ ]" : "[x]";
-
-      $box.after(iconHTML("spinner", { class: "fa-spin" })).hide();
-
-      ajax(`/posts/${postModel.id}`, { type: "GET", cache: false }).then(
-        (result) => {
-          const blocks = [];
-
-          // Computing offsets where checkbox are not evaluated (i.e. inside
-          // code blocks).
-          [
-            // inline code
-            /`[^`\n]*\n?[^`\n]*`/gm,
-            // multi-line code
-            /^`‍``[^]*?^`‍``/gm,
-            // bbcode
-            /\[code\][^]*?\[\/code\]/gm,
-            // italic/bold
-            /_(?=\S).*?\S_/gm,
-            // strikethrough
-            /~~(?=\S).*?\S~~/gm,
-          ].forEach((regex) => {
-            let match;
-            while ((match = regex.exec(result.raw)) != null) {
-              blocks.push([match.index, match.index + match[0].length]);
-            }
-          });
-
-          [
-            // italic/bold
-            /([^\[\n]|^)\*\S.+?\S\*(?=[^\]\n]|$)/gm,
-          ].forEach((regex) => {
-            let match;
-            while ((match = regex.exec(result.raw)) != null) {
-              // Simulate lookbehind - skip the first character
-              blocks.push([match.index + 1, match.index + match[0].length]);
-            }
-          });
-
-          // make the first run go to index = 0
-          let nth = -1;
-          let found = false;
-          const newRaw = result.raw.replace(
-            /\[(\s|\_|\-|\x|\\?\*)?\]/gi,
-            (match, ignored, off) => {
-              if (found) {
-                return match;
-              }
-
-              nth += blocks.every(
-                (b) => b[0] >= off + match.length || off > b[1]
-              );
-
-              if (nth === idx) {
-                found = true; // Do not replace any further matches
-                return newValue;
-              }
-
-              return match;
-            }
-          );
-
-          const save = postModel.save({
-            raw: newRaw,
-            edit_reason: I18n.t("checklist.edit_reason"),
-          });
-
-          if (save && save.then) {
-            save.then(() => {
-              postWidget.attrs.isSaving = false;
-              postWidget.scheduleRerender();
-            });
-          }
-        }
-      );
-    });
-  });
-
-  // confirm the feature is enabled by showing the click-ability
-  $boxes.css({ cursor: "pointer" });
-}
-
-export default {
-  name: "checklist",
-  initialize: function () {
-    withPluginApi("0.1", (api) => initializePlugin(api));
-  },
-};

[... diff too long, it was truncated ...]

GitHub sha: d8012abd3d6dccb72eec83e6a96ef4809dcad681

This commit appears in #47 which was approved by techAPJ. It was merged by CvX.