DEV: apply coding standards (#24)

DEV: apply coding standards (#24)

diff --git a/.eslintrc b/.eslintrc
new file mode 100644
index 0000000..7898fbf
--- /dev/null
+++ b/.eslintrc
@@ -0,0 +1,3 @@
+{
+  "extends": "eslint-config-discourse"
+}
diff --git a/.gitignore b/.gitignore
index b0f317f..d1ca10c 100644
--- a/.gitignore
+++ b/.gitignore
@@ -6,3 +6,6 @@ pkg/
 auto_generated
 .DS_Store
 *.swp
+node_modules
+yarn-error.log
+.rubocop-https---raw-githubusercontent-com-discourse-*
diff --git a/.template-lintrc.js b/.template-lintrc.js
new file mode 100644
index 0000000..a558b8e
--- /dev/null
+++ b/.template-lintrc.js
@@ -0,0 +1,4 @@
+module.exports = {
+  plugins: ["ember-template-lint-plugin-discourse"],
+  extends: "discourse:recommended",
+};
diff --git a/assets/javascripts/discourse/initializers/checklist.js.es6 b/assets/javascripts/discourse/initializers/checklist.js.es6
index 02c9808..73308de 100644
--- a/assets/javascripts/discourse/initializers/checklist.js.es6
+++ b/assets/javascripts/discourse/initializers/checklist.js.es6
@@ -1,6 +1,7 @@
 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");
@@ -24,7 +25,7 @@ export function checklistSyntax($elem, postDecorator) {
   }
 
   $boxes.each((idx, val) => {
-    $(val).click(ev => {
+    $(val).click((ev) => {
       const $box = $(ev.currentTarget);
 
       if ($box.hasClass("permanent")) return;
@@ -34,7 +35,7 @@ export function checklistSyntax($elem, postDecorator) {
       $box.after(iconHTML("spinner", { class: "fa-spin" })).hide();
 
       ajax(`/posts/${postModel.id}`, { type: "GET", cache: false }).then(
-        result => {
+        (result) => {
           const blocks = [];
 
           // Computing offsets where checkbox are not evaluated (i.e. inside
@@ -49,8 +50,8 @@ export function checklistSyntax($elem, postDecorator) {
             // italic/bold
             /_(?=\S).*?\S_/gm,
             // strikethrough
-            /~~(?=\S).*?\S~~/gm
-          ].forEach(regex => {
+            /~~(?=\S).*?\S~~/gm,
+          ].forEach((regex) => {
             let match;
             while ((match = regex.exec(result.raw)) != null) {
               blocks.push([match.index, match.index + match[0].length]);
@@ -59,8 +60,8 @@ export function checklistSyntax($elem, postDecorator) {
 
           [
             // italic/bold
-            /([^\[\n]|^)\*\S.+?\S\*(?=[^\]\n]|$)/gm
-          ].forEach(regex => {
+            /([^\[\n]|^)\*\S.+?\S\*(?=[^\]\n]|$)/gm,
+          ].forEach((regex) => {
             let match;
             while ((match = regex.exec(result.raw)) != null) {
               // Simulate lookbehind - skip the first character
@@ -79,7 +80,7 @@ export function checklistSyntax($elem, postDecorator) {
               }
 
               nth += blocks.every(
-                b => b[0] >= off + match.length || off > b[1]
+                (b) => b[0] >= off + match.length || off > b[1]
               );
 
               if (nth === idx) {
@@ -93,7 +94,7 @@ export function checklistSyntax($elem, postDecorator) {
 
           const save = postModel.save({
             raw: newRaw,
-            edit_reason: I18n.t("checklist.edit_reason")
+            edit_reason: I18n.t("checklist.edit_reason"),
           });
 
           if (save && save.then) {
@@ -113,7 +114,7 @@ export function checklistSyntax($elem, postDecorator) {
 
 export default {
   name: "checklist",
-  initialize: function() {
-    withPluginApi("0.1", api => initializePlugin(api));
-  }
+  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 7b9a430..6030567 100644
--- a/assets/javascripts/lib/discourse-markdown/checklist.js.es6
+++ b/assets/javascripts/lib/discourse-markdown/checklist.js.es6
@@ -95,10 +95,10 @@ export function setup(helper) {
     "span.chcklst-stroked",
     "span.chcklst-box fa fa-square-o fa-fw",
     "span.chcklst-box checked fa fa-check-square-o fa-fw",
-    "span.chcklst-box checked permanent fa fa-check-square fa-fw"
+    "span.chcklst-box checked permanent fa fa-check-square fa-fw",
   ]);
 
-  helper.registerPlugin(md =>
+  helper.registerPlugin((md) =>
     md.core.ruler.push("checklist", processChecklist)
   );
 }
diff --git a/package.json b/package.json
new file mode 100644
index 0000000..9df2b90
--- /dev/null
+++ b/package.json
@@ -0,0 +1,7 @@
+{
+  "author": "Discourse",
+  "license": "MIT",
+  "devDependencies": {
+    "eslint-config-discourse": "latest"
+  }
+}
diff --git a/test/javascripts/lib/checklist-test.js.es6 b/test/javascripts/lib/checklist-test.js.es6
index 0bc2b32..6ed258d 100644
--- a/test/javascripts/lib/checklist-test.js.es6
+++ b/test/javascripts/lib/checklist-test.js.es6
@@ -7,7 +7,7 @@ QUnit.module("initializer:checklist");
 
 async function prepare(raw) {
   const cooked = await cookAsync(raw, {
-    siteSettings: { checklist_enabled: true }
+    siteSettings: { checklist_enabled: true },
   });
   const model = Post.create({ id: 42, can_edit: true });
   const decoratorHelper = { getModel: () => model };
@@ -16,20 +16,20 @@ async function prepare(raw) {
   server.get("/posts/42", () => [
     200,
     { "Content-Type": "application/json" },
-    { raw }
+    { raw },
   ]);
 
   const $elem = $(cooked.string);
   checklistSyntax($elem, decoratorHelper);
 
-  const updated = new Promise(resolve => {
-    model.save = fields => resolve(fields.raw);
+  const updated = new Promise((resolve) => {
+    model.save = (fields) => resolve(fields.raw);
   });
 
   return [$elem, updated];
 }
 
-QUnit.test("checkbox before a code block", async assert => {
+QUnit.test("checkbox before a code block", async (assert) => {
   const [$elem, updated] = await prepare(`
 [ ] first
 [x] actual
@@ -45,7 +45,7 @@ QUnit.test("checkbox before a code block", async assert => {
   assert.ok(output.includes("[x] nope"));
 });
 
-QUnit.test("permanently checked checkbox", async assert => {
+QUnit.test("permanently checked checkbox", async (assert) => {
   const [$elem, updated] = await prepare(`
 [X] perma
 [x] not perma
@@ -60,7 +60,7 @@ QUnit.test("permanently checked checkbox", async assert => {
   assert.ok(output.includes("[ ] not perma"));
 });
 
-QUnit.test("checkbox before a multiline code block", async assert => {
+QUnit.test("checkbox before a multiline code block", async (assert) => {
   const [$elem, updated] = await prepare(`
 [ ] first
 [x] actual
@@ -79,7 +79,7 @@ QUnit.test("checkbox before a multiline code block", async assert => {
   assert.ok(output.includes("[x] nope"));
 });
 
-QUnit.test("checkbox before italic/bold sequence", async assert => {
+QUnit.test("checkbox before italic/bold sequence", async (assert) => {
   const [$elem, updated] = await prepare(` [x] *test*
   `);
 
@@ -90,7 +90,7 @@ QUnit.test("checkbox before italic/bold sequence", async assert => {
   assert.ok(output.includes("[ ] *test*"));
 });
 
-QUnit.test("checkboxes in an unordered list", async assert => {
+QUnit.test("checkboxes in an unordered list", async (assert) => {
   const [$elem, updated] = await prepare(`
 * [x] checked
 * [] test
@@ -106,7 +106,7 @@ QUnit.test("checkboxes in an unordered list", async assert => {
   assert.ok(output.includes("* [] two"));
 });
 
-QUnit.test("checkboxes in italic/bold-like blocks", async assert => {
+QUnit.test("checkboxes in italic/bold-like blocks", async (assert) => {
   const [$elem, updated] = await prepare(`
 *[x
 *a [*] x]*
@@ -129,7 +129,7 @@ QUnit.test("checkboxes in italic/bold-like blocks", async assert => {
   assert.ok(output.includes("* [ ] 3"));
 });
 
-QUnit.test("correct checkbox is selected", async assert => {
+QUnit.test("correct checkbox is selected", async (assert) => {

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

GitHub sha: 56cb4586

This commit appears in #24 which was merged by jjaffeux.