diff --git a/.eslintrc.js b/.eslintrc.js index 35fbbef6..bdd0cd98 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -60,7 +60,14 @@ module.exports = { "id-blacklist": "error", "id-length": "off", "id-match": "error", - "indent": "off", + "indent": [ + "warn", + "tab", + { + "outerIIFEBody": 0, + "SwitchCase": 1 + } + ], "init-declarations": "off", "jsx-quotes": "error", "key-spacing": "off", @@ -217,5 +224,6 @@ module.exports = { "wrap-regex": "error", "yield-star-spacing": "error", "yoda": "off" - } + }, + "root": true }; diff --git a/api/redraw.js b/api/redraw.js index e975d286..1b22271b 100644 --- a/api/redraw.js +++ b/api/redraw.js @@ -38,10 +38,10 @@ module.exports = function($window) { var index = callbacks.indexOf(key) if (index > -1) callbacks.splice(index, 2) } - function redraw() { - for (var i = 1; i < callbacks.length; i += 2) { - callbacks[i]() - } - } + function redraw() { + for (var i = 1; i < callbacks.length; i += 2) { + callbacks[i]() + } + } return {subscribe: subscribe, unsubscribe: unsubscribe, redraw: redraw, render: renderService.render} } diff --git a/api/tests/test-router.js b/api/tests/test-router.js index 3fcfbae7..9406de70 100644 --- a/api/tests/test-router.js +++ b/api/tests/test-router.js @@ -528,6 +528,7 @@ o.spec("route", function() { }) o(root.firstChild.nodeName).equals("DIV") + o(renderCount).equals(1) }) o("RouteResolver `render` does not have component semantics", function(done) { diff --git a/bundler/tests/test-bundler.js b/bundler/tests/test-bundler.js index 69aeba2c..15e7f932 100644 --- a/bundler/tests/test-bundler.js +++ b/bundler/tests/test-bundler.js @@ -24,9 +24,9 @@ o.spec("bundler", function() { write("b.js", "module.exports = 1") bundle(ns + "a.js", ns + "out.js") - o(read("out.js")).equals(";(function() {\nvar b = 1\n}());") + o(read("out.js")).equals(";(function() {\nvar b = 1\n}());") - remove("a.js") + remove("a.js") remove("b.js") remove("out.js") }) @@ -35,7 +35,7 @@ o.spec("bundler", function() { write("b.js", "module.exports = 1;") bundle(ns + "a.js", ns + "out.js") - o(read("out.js")).equals(";(function() {\nvar b = 1;\n}());") + o(read("out.js")).equals(";(function() {\nvar b = 1;\n}());") remove("a.js") remove("b.js") @@ -46,7 +46,7 @@ o.spec("bundler", function() { write("b.js", "module.exports = 1") bundle(ns + "a.js", ns + "out.js") - o(read("out.js")).equals(";(function() {\nlet b = 1\n}());") + o(read("out.js")).equals(";(function() {\nlet b = 1\n}());") remove("a.js") remove("b.js") @@ -57,7 +57,7 @@ o.spec("bundler", function() { write("b.js", "module.exports = 1") bundle(ns + "a.js", ns + "out.js") - o(read("out.js")).equals(";(function() {\nconst b = 1\n}());") + o(read("out.js")).equals(";(function() {\nconst b = 1\n}());") remove("a.js") remove("b.js") @@ -156,9 +156,9 @@ o.spec("bundler", function() { write("b.js", "module.exports = []") bundle(ns + "a.js", ns + "out.js") - o(read("out.js")).equals(";(function() {\nvar _0 = []\nvar b = _0\n\t.toString()\n}());") + o(read("out.js")).equals(";(function() {\nvar _0 = []\nvar b = _0\n\t.toString()\n}());") - remove("a.js") + remove("a.js") remove("b.js") remove("out.js") }) @@ -169,7 +169,7 @@ o.spec("bundler", function() { o(read("out.js")).equals(";(function() {\nvar _0 = function() {}\nvar b = _0()\n}());") - remove("a.js") + remove("a.js") remove("b.js") remove("out.js") }) diff --git a/package.json b/package.json index 0028fd4d..ffa0a1d7 100644 --- a/package.json +++ b/package.json @@ -14,6 +14,7 @@ "lintdocs": "node docs/lint", "gendocs": "node docs/generate", "lint": "eslint .", + "lint:fix": "eslint . --fix", "test": "node ospec/bin/ospec", "posttest": "npm run lint || true", "cover": "istanbul cover --print both ospec/bin/ospec", diff --git a/promise/tests/test-promise.js b/promise/tests/test-promise.js index e52e792b..48a9fac3 100644 --- a/promise/tests/test-promise.js +++ b/promise/tests/test-promise.js @@ -584,15 +584,15 @@ o.spec("promise", function() { var readCount = 0 var promise = Promise.resolve(1).then(function() { return Object.create(null, { - then: { - get: function () { - ++readCount - return function(onFulfilled) { - onFulfilled() - } - } - } - }) + then: { + get: function () { + ++readCount + return function(onFulfilled) { + onFulfilled() + } + } + } + }) }) promise.then(function() { diff --git a/stream/tests/test-stream.js b/stream/tests/test-stream.js index e435c888..89dd713a 100644 --- a/stream/tests/test-stream.js +++ b/stream/tests/test-stream.js @@ -162,6 +162,7 @@ o.spec("stream", function() { }) o(b()).equals(undefined) + o(count).equals(0) }) o("combine will throw with a helpful error if given non-stream values", function () { var spy = o.spy() diff --git a/test-utils/components.js b/test-utils/components.js index 1e6fdd72..109af9bb 100644 --- a/test-utils/components.js +++ b/test-utils/components.js @@ -1,29 +1,29 @@ "use strict" module.exports = [ - { - kind: "POJO", - create: function(methods) { - var res = {view: function() {return {tag:"div"}}} - Object.keys(methods || {}).forEach(function(m){res[m] = methods[m]}) - return res - } - }, { - kind: "constructible", - create: function(methods) { - function res(){} - res.prototype.view = function() {return {tag:"div"}} - Object.keys(methods || {}).forEach(function(m){res.prototype[m] = methods[m]}) - return res - } - }, { - kind: "closure", - create: function(methods) { - return function() { - var res = {view: function() {return {tag:"div"}}} - Object.keys(methods || {}).forEach(function(m){res[m] = methods[m]}) - return res - } - } - } + { + kind: "POJO", + create: function(methods) { + var res = {view: function() {return {tag:"div"}}} + Object.keys(methods || {}).forEach(function(m){res[m] = methods[m]}) + return res + } + }, { + kind: "constructible", + create: function(methods) { + function res(){} + res.prototype.view = function() {return {tag:"div"}} + Object.keys(methods || {}).forEach(function(m){res.prototype[m] = methods[m]}) + return res + } + }, { + kind: "closure", + create: function(methods) { + return function() { + var res = {view: function() {return {tag:"div"}}} + Object.keys(methods || {}).forEach(function(m){res[m] = methods[m]}) + return res + } + } + } ] diff --git a/test-utils/tests/test-components.js b/test-utils/tests/test-components.js index 30ea6175..e0ede703 100644 --- a/test-utils/tests/test-components.js +++ b/test-utils/tests/test-components.js @@ -4,51 +4,51 @@ var o = require("../../ospec/ospec") var components = require("../../test-utils/components") o.spec("test-utils/components", function() { - var test = o.spy(function(component) { - return function() { - o("works", function() { - o(typeof component.kind).equals("string") + var test = o.spy(function(component) { + return function() { + o("works", function() { + o(typeof component.kind).equals("string") - var methods = {oninit: function(){}, view: function(){}} + var methods = {oninit: function(){}, view: function(){}} - var cmp1, cmp2 + var cmp1, cmp2 - if (component.kind === "POJO") { - cmp1 = component.create() - cmp2 = component.create(methods) - } else if (component.kind === "constructible") { - cmp1 = new (component.create()) - cmp2 = new (component.create(methods)) - } else if (component.kind === "closure") { - cmp1 = component.create()() - cmp2 = component.create(methods)() - } else { - throw new Error("unexpected component kind") - } + if (component.kind === "POJO") { + cmp1 = component.create() + cmp2 = component.create(methods) + } else if (component.kind === "constructible") { + cmp1 = new (component.create()) + cmp2 = new (component.create(methods)) + } else if (component.kind === "closure") { + cmp1 = component.create()() + cmp2 = component.create(methods)() + } else { + throw new Error("unexpected component kind") + } - o(cmp1 != null).equals(true) - o(typeof cmp1.view).equals("function") + o(cmp1 != null).equals(true) + o(typeof cmp1.view).equals("function") - var vnode = cmp1.view() + var vnode = cmp1.view() - o(vnode != null).equals(true) - o(vnode).deepEquals({tag: "div"}) + o(vnode != null).equals(true) + o(vnode).deepEquals({tag: "div"}) - if (component.kind !== "constructible") { - o(cmp2).deepEquals(methods) - } else { + if (component.kind !== "constructible") { + o(cmp2).deepEquals(methods) + } else { // deepEquals doesn't search the prototype, do it manually - o(cmp2 != null).equals(true) - o(cmp2.view).equals(methods.view) - o(cmp2.oninit).equals(methods.oninit) - } - }) - } - }) - o.after(function(){ - o(test.callCount).equals(3) - }) - components.forEach(function(component) { - o.spec(component.kind, test(component)) - }) + o(cmp2 != null).equals(true) + o(cmp2.view).equals(methods.view) + o(cmp2.oninit).equals(methods.oninit) + } + }) + } + }) + o.after(function(){ + o(test.callCount).equals(3) + }) + components.forEach(function(component) { + o.spec(component.kind, test(component)) + }) })