DEV: Apply prettier

DEV: Apply prettier
From 0cfc82a23ce1f2b0d5d9969d13133ba285a89c15 Mon Sep 17 00:00:00 2001
From: David Taylor <david@taylorhq.com>
Date: Mon, 22 Oct 2018 19:49:32 +0100
Subject: [PATCH] DEV: Apply prettier


diff --git a/assets/javascripts/discourse/initializers/checklist.js.es6 b/assets/javascripts/discourse/initializers/checklist.js.es6
index b61b59d..e981d85 100644
--- a/assets/javascripts/discourse/initializers/checklist.js.es6
+++ b/assets/javascripts/discourse/initializers/checklist.js.es6
@@ -1,73 +1,72 @@
-import { withPluginApi } from 'discourse/lib/plugin-api';
-import AjaxLib from 'discourse/lib/ajax';
-import TextLib from 'discourse/lib/text';
+import { withPluginApi } from "discourse/lib/plugin-api";
+import AjaxLib from "discourse/lib/ajax";
+import TextLib from "discourse/lib/text";
 
-function initializePlugin(api)
-{
-  const siteSettings = api.container.lookup('site-settings:main');
+function initializePlugin(api) {
+  const siteSettings = api.container.lookup("site-settings:main");
 
-  if (siteSettings.checklist_enabled)
-  {
+  if (siteSettings.checklist_enabled) {
     api.decorateCooked(checklistSyntax);
   }
 }
 
-export function checklistSyntax($elem, post)
-{
-  if (!post) { return; }
+export function checklistSyntax($elem, post) {
+  if (!post) {
+    return;
+  }
 
   var boxes = $elem.find(".chcklst-box"),
     viewPost = post.getModel();
 
-  if (!viewPost.can_edit) { return; }
+  if (!viewPost.can_edit) {
+    return;
+  }
 
-  boxes.each(function(idx, val)
-  {
-    $(val).click(function(ev)
-    {
+  boxes.each(function(idx, val) {
+    $(val).click(function(ev) {
       var elem = $(ev.currentTarget),
-        new_value = elem.hasClass("checked") ? "[ ]": "[\\*]";
+        new_value = elem.hasClass("checked") ? "[ ]" : "[\\*]";
 
       elem.after('<i class="fa fa-spinner fa-spin fa-fw"></i>');
       elem.hide();
 
       var postId = viewPost.id;
-      AjaxLib.ajax("/posts/" + postId, { type: 'GET', cache: false }).then(function(result)
-      {
-        var nth = -1, // make the first run go to index = 0
-          new_raw = result.raw.replace(/\[(\s|\_|\-|\x|\\?\*)?\]/ig, function(match)
-          {
-            nth += 1;
-            return nth === idx ? new_value : match;
-          });
+      AjaxLib.ajax("/posts/" + postId, { type: "GET", cache: false }).then(
+        function(result) {
+          var nth = -1, // make the first run go to index = 0
+            new_raw = result.raw.replace(/\[(\s|\_|\-|\x|\\?\*)?\]/gi, function(
+              match
+            ) {
+              nth += 1;
+              return nth === idx ? new_value : match;
+            });
 
-        var props = {
-          raw: new_raw,
-          edit_reason: I18n.t("checklist.edit_reason"),
-        };
+          var props = {
+            raw: new_raw,
+            edit_reason: I18n.t("checklist.edit_reason")
+          };
 
-        if (TextLib.cookAsync) {
-          TextLib.cookAsync(new_raw).then(cooked => {
-            props.cooked = cooked.string;
+          if (TextLib.cookAsync) {
+            TextLib.cookAsync(new_raw).then(cooked => {
+              props.cooked = cooked.string;
+              viewPost.save(props);
+            });
+          } else {
+            props.cooked = TextLib.cook(new_raw).string;
             viewPost.save(props);
-          });
-        } else {
-          props.cooked = TextLib.cook(new_raw).string;
-          viewPost.save(props);
+          }
         }
-
-      });
+      );
     });
   });
 
   // confirm the feature is enabled by showing the click-ability
-  boxes.css({"cursor": "pointer"});
+  boxes.css({ cursor: "pointer" });
 }
 
 export default {
-  name: 'checklist',
-  initialize: function()
-  {
-    withPluginApi('0.1', api => initializePlugin(api));
+  name: "checklist",
+  initialize: function() {
+    withPluginApi("0.1", api => initializePlugin(api));
   }
 };
diff --git a/assets/javascripts/lib/discourse-markdown/checklist.js.es6 b/assets/javascripts/lib/discourse-markdown/checklist.js.es6
index 160df37..91e1790 100644
--- a/assets/javascripts/lib/discourse-markdown/checklist.js.es6
+++ b/assets/javascripts/lib/discourse-markdown/checklist.js.es6
@@ -1,9 +1,9 @@
-import { registerOption } from 'pretty-text/pretty-text';
+import { registerOption } from "pretty-text/pretty-text";
 
-const REGEX = /\[(\s?|_|-|x|\*)\]/ig;
+const REGEX = /\[(\s?|_|-|x|\*)\]/gi;
 
 function getClasses(str) {
-  switch(str.toLowerCase()) {
+  switch (str.toLowerCase()) {
     case "x":
       return "checked fa fa-check-square fa-fw";
     case "*":
@@ -19,25 +19,23 @@ function getClasses(str) {
 
 function addCheckbox(result, content, match, state) {
   let classes = getClasses(match[1]);
-  let token = new state.Token('check_open', 'span', 1);
-  token.attrs = [['class', `chcklst-box ${classes}`]];
+  let token = new state.Token("check_open", "span", 1);
+  token.attrs = [["class", `chcklst-box ${classes}`]];
   result.push(token);
 
-  token = new state.Token('check_close', 'span', -1);
+  token = new state.Token("check_close", "span", -1);
   result.push(token);
 }
 
 function applyCheckboxes(content, state) {
-
   let result = null,
-      pos = 0,
-      match;
-
-  while (match = REGEX.exec(content)) {
+    pos = 0,
+    match;
 
+  while ((match = REGEX.exec(content))) {
     if (match.index > pos) {
       result = result || [];
-      let token = new state.Token('text', '', 0);
+      let token = new state.Token("text", "", 0);
       token.content = content.slice(pos, match.index);
       result.push(token);
     }
@@ -49,7 +47,7 @@ function applyCheckboxes(content, state) {
   }
 
   if (result && pos < content.length) {
-    let token = new state.Token('text', '', 0);
+    let token = new state.Token("text", "", 0);
     token.content = content.slice(pos);
     result.push(token);
   }
@@ -58,12 +56,18 @@ function applyCheckboxes(content, state) {
 }
 
 function processChecklist(state) {
-  var i, j, l, tokens, token,
-      blockTokens = state.tokens,
-      nesting = 0;
+  var i,
+    j,
+    l,
+    tokens,
+    token,
+    blockTokens = state.tokens,
+    nesting = 0;
 
   for (j = 0, l = blockTokens.length; j < l; j++) {
-    if (blockTokens[j].type !== 'inline') { continue; }
+    if (blockTokens[j].type !== "inline") {
+      continue;
+    }
     tokens = blockTokens[j].children;
 
     // We scan from the end, to keep position when new tags are added.
@@ -73,30 +77,35 @@ function processChecklist(state) {
 
       nesting += token.nesting;
 
-      if (token.type === 'text' && nesting === 0) {
+      if (token.type === "text" && nesting === 0) {
         let processed = applyCheckboxes(token.content, state);
         if (processed) {
-          blockTokens[j].children = tokens = state.md.utils.arrayReplaceAt(tokens, i, processed);
+          blockTokens[j].children = tokens = state.md.utils.arrayReplaceAt(
+            tokens,
+            i,
+            processed
+          );
         }
       }
     }
   }
-
 }
 
 export function setup(helper) {
-  helper.registerOptions((opts, siteSettings)=>{
-    opts.features['checklist'] = !!siteSettings.checklist_enabled;
+  helper.registerOptions((opts, siteSettings) => {
+    opts.features["checklist"] = !!siteSettings.checklist_enabled;
   });
 
-  helper.whiteList([ 'span.chcklst-stroked',
-                     'span.chcklst-box fa fa-square-o fa-fw',
-                     'span.chcklst-box fa fa-square fa-fw',
-                     'span.chcklst-box fa fa-minus-square-o fa-fw',
-                     'span.chcklst-box checked fa fa-check-square fa-fw',
-                     'span.chcklst-box checked fa fa-check-square-o fa-fw' ]);
-
-  helper.registerPlugin(md =>{
-    md.core.ruler.push('checklist', processChecklist);
+  helper.whiteList([
+    "span.chcklst-stroked",
+    "span.chcklst-box fa fa-square-o fa-fw",
+    "span.chcklst-box fa fa-square fa-fw",
+    "span.chcklst-box fa fa-minus-square-o fa-fw",
+    "span.chcklst-box checked fa fa

GitHub