diff --git a/.eslintrc.js b/.eslintrc.js index 40b8f5c5..523eeb4c 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -1,257 +1,221 @@ module.exports = { - "env": { - "browser": true, - "commonjs": true, - "node": true - }, - "globals": { - "Promise": true - }, - "extends": "eslint:recommended", - "rules": { - "accessor-pairs": "error", - "array-bracket-spacing": [ - "error", - "never" - ], - "array-callback-return": "error", - "arrow-body-style": "error", - "arrow-parens": "error", - "arrow-spacing": "error", - "block-scoped-var": "off", - "block-spacing": [ - "error", - "never" - ], - "brace-style": "off", - "callback-return": "off", - "camelcase": "error", - "comma-dangle": "off", - "comma-spacing": [ - "error", - { - "after": true, - "before": false - } - ], - "comma-style": [ - "error", - "last" - ], - "complexity": "off", - "computed-property-spacing": [ - "error", - "never" - ], - "consistent-return": "off", - "consistent-this": "off", - "curly": "off", - "default-case": "off", - "dot-location": [ - "error", - "property" - ], - "dot-notation": "off", - "eol-last": "off", - "eqeqeq": "off", - "func-names": "off", - "func-style": "off", - "generator-star-spacing": "error", - "global-require": "error", - "guard-for-in": "off", - "handle-callback-err": "error", - "id-blacklist": "error", - "id-length": "off", - "id-match": "error", - "indent": "off", - "init-declarations": "off", - "jsx-quotes": "error", - "key-spacing": "error", - "keyword-spacing": [ - "error", - { - "before": true, - "after": true - } - ], - "lines-around-comment": "error", - "max-depth": "off", - "max-len": "off", - "max-nested-callbacks": "error", - "max-params": "off", - "max-statements": "off", - "max-statements-per-line": "off", - "new-parens": "off", - "newline-after-var": "off", - "newline-before-return": "off", - "newline-per-chained-call": "off", - "no-alert": "error", - "no-array-constructor": "error", - "no-bitwise": "off", - "no-caller": "error", - "no-catch-shadow": "error", - "no-cond-assign": "off", - "no-confusing-arrow": "error", - "no-continue": "error", - "no-div-regex": "error", - "no-duplicate-imports": "error", - "no-else-return": "off", - "no-empty-function": "off", - "no-eq-null": "off", - "no-eval": "error", - "no-extend-native": "error", - "no-extra-bind": "error", - "no-extra-label": "error", - "no-extra-parens": "off", - "no-floating-decimal": "error", - "no-implicit-coercion": "error", - "no-implicit-globals": "error", - "no-implied-eval": "error", - "no-inline-comments": "off", - "no-inner-declarations": [ - "error", - "functions" - ], - "no-invalid-this": "off", - "no-iterator": "error", - "no-label-var": "error", - "no-labels": "error", - "no-lone-blocks": "error", - "no-lonely-if": "off", - "no-loop-func": "off", - "no-magic-numbers": "off", - "no-mixed-requires": "error", - "no-multi-spaces": "error", - "no-multi-str": "error", - "no-multiple-empty-lines": "error", - "no-native-reassign": "error", - "no-negated-condition": "off", - "no-nested-ternary": "off", - "no-new": "off", - "no-new-func": "off", - "no-new-object": "error", - "no-new-require": "error", - "no-new-wrappers": "error", - "no-octal-escape": "error", - "no-param-reassign": "off", - "no-path-concat": "error", - "no-plusplus": "off", - "no-process-env": "error", - "no-process-exit": "error", - "no-proto": "error", - "no-redeclare": "off", - "no-restricted-globals": "error", - "no-restricted-imports": "error", - "no-restricted-modules": "error", - "no-restricted-syntax": "error", - "no-return-assign": "off", - "no-script-url": "error", - "no-self-compare": "error", - "no-sequences": "off", - "no-shadow": "off", - "no-shadow-restricted-names": "error", - "no-spaced-func": "error", - "no-sync": "off", - "no-ternary": "off", - "no-throw-literal": "error", - "no-trailing-spaces": [ - "error", - { - "skipBlankLines": true - } - ], - "no-undef-init": "error", - "no-undefined": "off", - "no-underscore-dangle": "error", - "no-unmodified-loop-condition": "error", - "no-unneeded-ternary": "error", - "no-unsafe-finally": "error", - "no-unused-expressions": "off", - "no-unused-vars": [ - "error", - { - "varsIgnorePattern": "module" - } - ], - "no-use-before-define": "off", - "no-useless-call": "error", - "no-useless-computed-key": "error", - "no-useless-concat": "error", - "no-useless-constructor": "error", - "no-useless-escape": "off", - "no-var": "off", - "no-void": "error", - "no-warning-comments": "off", - "no-whitespace-before-property": "error", - "no-with": "error", - "object-curly-spacing": [ - "error", - "never" - ], - "object-property-newline": [ - "error", - { - "allowMultiplePropertiesPerLine": true - } - ], - "object-shorthand": "off", - "one-var": "off", - "one-var-declaration-per-line": "off", - "operator-assignment": [ - "error", - "always" - ], - "operator-linebreak": [ - "error", - "after" - ], - "padded-blocks": "off", - "prefer-arrow-callback": "off", - "prefer-const": "error", - "prefer-reflect": "off", - "prefer-rest-params": "off", - "prefer-spread": "off", - "prefer-template": "off", - "quote-props": "off", - "quotes": [ - "error", - "double" - ], - "radix": [ - "error", - "as-needed" - ], - "require-jsdoc": "off", - "require-yield": "error", - "semi": "off", - "semi-spacing": [ - "error", - { - "after": true, - "before": false - } - ], - "sort-imports": "error", - "sort-vars": "off", - "space-before-blocks": "error", - "space-before-function-paren": "off", - "space-in-parens": [ - "error", - "never" - ], - "space-infix-ops": "error", - "space-unary-ops": "off", - "spaced-comment": "off", - "strict": "off", - "template-curly-spacing": "error", - "valid-jsdoc": "error", - "vars-on-top": "off", - "wrap-iife": "error", - "wrap-regex": "error", - "yield-star-spacing": "error", - "yoda": [ - "error", - "never" - ] - } -}; + "env": { + "browser": true, + "commonjs": true, + "es6": true, + "node": true + }, + "extends": "eslint:recommended", + "rules": { + "accessor-pairs": "error", + "array-bracket-spacing": [ + "error", + "never" + ], + "array-callback-return": "error", + "arrow-body-style": "error", + "arrow-parens": "error", + "arrow-spacing": "error", + "block-scoped-var": "off", + "block-spacing": "off", + "brace-style": "off", + "callback-return": "off", + "camelcase": [ + "error", + { + "properties": "never" + } + ], + "comma-dangle": [ + "error", + "only-multiline" + ], + "comma-spacing": "off", + "comma-style": [ + "error", + "last" + ], + "complexity": "off", + "computed-property-spacing": [ + "error", + "never" + ], + "consistent-return": "off", + "consistent-this": "off", + "curly": "off", + "default-case": "off", + "dot-location": [ + "error", + "property" + ], + "dot-notation": "off", + "eol-last": "off", + "eqeqeq": "off", + "func-names": "off", + "func-style": "off", + "generator-star-spacing": "error", + "global-require": "error", + "guard-for-in": "off", + "handle-callback-err": "error", + "id-blacklist": "error", + "id-length": "off", + "id-match": "error", + "indent": "off", + "init-declarations": "off", + "jsx-quotes": "error", + "key-spacing": "off", + "keyword-spacing": "off", + "linebreak-style": "off", + "lines-around-comment": "off", + "max-depth": "off", + "max-len": "off", + "max-nested-callbacks": "error", + "max-params": "off", + "max-statements": "off", + "max-statements-per-line": "off", + "new-parens": "off", + "newline-after-var": "off", + "newline-before-return": "off", + "newline-per-chained-call": "off", + "no-alert": "error", + "no-array-constructor": "error", + "no-bitwise": "error", + "no-caller": "error", + "no-catch-shadow": "off", + "no-cond-assign": "off", + "no-confusing-arrow": "error", + "no-console": "off", + "no-continue": "off", + "no-div-regex": "error", + "no-duplicate-imports": "error", + "no-else-return": "off", + "no-empty-function": "off", + "no-eq-null": "off", + "no-eval": "error", + "no-extend-native": "off", + "no-extra-bind": "error", + "no-extra-label": "error", + "no-extra-parens": "off", + "no-floating-decimal": "error", + "no-implicit-coercion": "error", + "no-implicit-globals": "error", + "no-implied-eval": "error", + "no-inline-comments": "off", + "no-invalid-this": "off", + "no-iterator": "error", + "no-label-var": "off", + "no-labels": "off", + "no-lone-blocks": "error", + "no-lonely-if": "off", + "no-loop-func": "off", + "no-magic-numbers": "off", + "no-mixed-requires": "error", + "no-multi-spaces": "error", + "no-multi-str": "error", + "no-multiple-empty-lines": "error", + "no-native-reassign": "error", + "no-negated-condition": "off", + "no-nested-ternary": "off", + "no-new": "off", + "no-new-func": "off", + "no-new-object": "error", + "no-new-require": "error", + "no-new-wrappers": "error", + "no-octal-escape": "error", + "no-param-reassign": "off", + "no-path-concat": "off", + "no-plusplus": "off", + "no-process-env": "error", + "no-process-exit": "error", + "no-proto": "error", + "no-redeclare": "off", + "no-restricted-globals": "error", + "no-restricted-imports": "error", + "no-restricted-modules": "error", + "no-restricted-syntax": "error", + "no-return-assign": "off", + "no-script-url": "error", + "no-self-compare": "error", + "no-sequences": "off", + "no-shadow": "off", + "no-shadow-restricted-names": "error", + "no-spaced-func": "error", + "no-sync": "off", + "no-ternary": "off", + "no-throw-literal": "off", + "no-trailing-spaces": [ + "error", + { + "skipBlankLines": true + } + ], + "no-undef-init": "error", + "no-undefined": "off", + "no-underscore-dangle": "off", + "no-unmodified-loop-condition": "error", + "no-unneeded-ternary": "error", + "no-unused-expressions": "off", + "no-use-before-define": "off", + "no-useless-call": "error", + "no-useless-concat": "error", + "no-useless-constructor": "error", + "no-useless-escape": "off", + "no-var": "off", + "no-void": "off", + "no-warning-comments": "off", + "no-whitespace-before-property": "error", + "no-with": "error", + "object-curly-spacing": [ + "error", + "never" + ], + "object-shorthand": "off", + "one-var": "off", + "one-var-declaration-per-line": "off", + "operator-assignment": [ + "error", + "always" + ], + "operator-linebreak": "off", + "padded-blocks": "off", + "prefer-arrow-callback": "off", + "prefer-const": "error", + "prefer-reflect": "off", + "prefer-rest-params": "off", + "prefer-spread": "error", + "prefer-template": "off", + "quote-props": "off", + "quotes": [ + "error", + "double", + "avoid-escape" + ], + "radix": [ + "error", + "always" + ], + "require-jsdoc": "off", + "require-yield": "error", + "semi": "off", + "semi-spacing": "off", + "sort-imports": "error", + "sort-vars": "off", + "space-before-blocks": "off", + "space-before-function-paren": "off", + "space-in-parens": [ + "error", + "never" + ], + "space-infix-ops": "off", + "space-unary-ops": "error", + "spaced-comment": "off", + "strict": "off", + "template-curly-spacing": "error", + "valid-jsdoc": "off", + "vars-on-top": "off", + "wrap-iife": "off", + "wrap-regex": "error", + "yield-star-spacing": "error", + "yoda": "off" + } +}; \ No newline at end of file diff --git a/bundler/bundle.js b/bundler/bundle.js index 04d1b4b4..a8e318cc 100644 --- a/bundler/bundle.js +++ b/bundler/bundle.js @@ -22,7 +22,7 @@ function run(input, output) { var declaration = /^\s*(?:var|let|const|function)[\t ]+([\w_$]+)/gm var include = /(?:((?:var|let|const|,|)[\t ]*)([\w_$\.]+)(\s*=\s*))?require\(([^\)]+)\)(\s*[`\.\(\[])?/gm var uuid = 0 - function process(filepath, data) { + var process = function(filepath, data) { data.replace(declaration, function(match, binding) {bindings[binding] = 0}) return data.replace(include, function(match, def, variable, eq, dep, rest) { @@ -38,7 +38,7 @@ function run(input, output) { }) } - function resolve(filepath, filename) { + var resolve = function(filepath, filename) { if (filename[0] !== ".") { // resolve as npm dependency var packagePath = "./node_modules/" + filename + "/package.json" @@ -52,7 +52,7 @@ function run(input, output) { } } - function exportCode(filename, filepath, def, variable, eq, rest, uuid) { + var exportCode = function(filename, filepath, def, variable, eq, rest, uuid) { var code = read(filepath) // if there's a syntax error, report w/ proper stack trace try {new Function(code)} catch (e) { @@ -63,7 +63,7 @@ function run(input, output) { // disambiguate collisions var ignored = {} - code.replace(include, function(match, def, variable, eq, dep, rest) { + code.replace(include, function(match, def, variable, eq, dep) { var filename = new Function("return " + dep).call() var binding = modules[resolve(filepath, filename)] if (binding != null) ignored[binding] = true @@ -119,7 +119,7 @@ function run(input, output) { module.exports = function(input, output, options) { run(input, output) if (options && options.watch) { - fs.watch(process.cwd(), {recursive: true}, function(file, type) { + fs.watch(process.cwd(), {recursive: true}, function(file) { if (typeof file === "string" && path.resolve(output) !== path.resolve(file)) run(input, output) }) } diff --git a/bundler/lintdocs.js b/bundler/lintdocs.js index f356fd12..8ac04147 100644 --- a/bundler/lintdocs.js +++ b/bundler/lintdocs.js @@ -17,7 +17,7 @@ function ensureCodeIsHighlightable(file, data) { block = block.slice(3, -3) if (block.indexOf("javascript") !== 0) { try {if (new Function(block)) console.log(file + " - javascript block missing language tag after triple backtick\n\n" + block + "\n\n---\n\n")} - catch (e) {} + catch (e) {/*not a js block, ignore*/} } }) } @@ -46,7 +46,7 @@ function ensureCodeIsRunnable(file, data) { try { new Function("console,fetch,module,require", code).call(this, silentConsole, fetch, {exports: {}}, function(dep) { if (dep.indexOf("./mycomponent") === 0) return {view: function() {}} - if (dep === "mithril") return m + if (dep === "mithril") return global.m }) } catch (e) {console.log(file + " - javascript code cannot run\n\n" + e.stack + "\n\n" + code + "\n\n---\n\n")} @@ -93,7 +93,7 @@ global.document = window.document global.m = require("../index") //run -traverseDirectory("./docs", function(pathname, stat, children) { +traverseDirectory("./docs", function(pathname) { if (pathname.indexOf(".md") > -1 && pathname.indexOf("migration") < 0) { fs.readFile(pathname, "utf8", function(err, data) { if (err) console.log(err) diff --git a/mithril.js b/mithril.js index 546bec54..5d66f1ae 100644 --- a/mithril.js +++ b/mithril.js @@ -86,11 +86,11 @@ var _7 = function(log) { if (arguments.length > 0 && arguments[0] !== HALT) updateStream(stream, arguments[0], undefined) return stream._state.value } - initStream(stream, arguments) + initStream(stream) if (arguments.length > 0 && arguments[0] !== HALT) updateStream(stream, arguments[0], undefined) return stream } - function initStream(stream, args) { + function initStream(stream) { stream.constructor = createStream stream._state = {id: guid++, value: undefined, error: undefined, state: 0, derive: undefined, recover: undefined, deps: {}, parents: [], errorStream: undefined, endStream: undefined} stream.map = map, stream.ap = ap, stream.of = createStream @@ -103,7 +103,7 @@ var _7 = function(log) { if (arguments.length > 0 && arguments[0] !== HALT) updateStream(stream, undefined, arguments[0]) return stream._state.error } - initStream(errorStream, []) + initStream(errorStream) initDependency(errorStream, [stream], noop, noop) stream._state.errorStream = errorStream } @@ -291,7 +291,6 @@ var buildQueryString = function(object) { else args.push(encodeURIComponent(key0) + (value1 != null && value1 !== "" ? "=" + encodeURIComponent(value1) : "")) } } -var StreamFactory = _7 var _9 = function($window, Stream0) { var callbackCount = 0 var oncompletion @@ -414,7 +413,7 @@ var _9 = function($window, Stream0) { return {request: request, jsonp: jsonp, setCompletionCallback: setCompletionCallback} } var requestService = _9(window, Stream) -var _13 = function() { +var _12 = function() { var callbacks = [] function unsubscribe(callback) { var index0 = callbacks.indexOf(callback) @@ -427,9 +426,9 @@ var _13 = function() { } return {subscribe: callbacks.push.bind(callbacks), unsubscribe: unsubscribe, publish: publish} } -var redrawService = _13() +var redrawService = _12() requestService.setCompletionCallback(redrawService.publish) -var _15 = function($window) { +var _14 = function($window) { var $doc = $window.document var $emptyFragment = $doc.createDocumentFragment() var onevent @@ -937,7 +936,7 @@ var _15 = function($window) { } return {render: render, setEventCallback: setEventCallback} } -var renderService = _15(window) +var renderService = _14(window) var throttle = function(callback1) { //60fps translates to 16.6ms, round it down since setTimeout requires int var time = 16 @@ -971,7 +970,7 @@ var autoredraw = function(root, renderer, pubsub, callback0) { } return root.redraw = run1 } -var _19 = function(renderer, pubsub) { +var _18 = function(renderer, pubsub) { return function(root, component) { if (component === null) { renderer.render(root, []) @@ -988,7 +987,7 @@ var _19 = function(renderer, pubsub) { run0() } } -m.mount = _19(renderService, redrawService) +m.mount = _18(renderService, redrawService) var mount = m.mount var parseQueryString = function(string) { if (string === "" || string == null) return {} @@ -1129,7 +1128,7 @@ var coreRouter = function($window) { } return {setPrefix: setPrefix, getPath: getPath, setPath: setPath, defineRoutes: defineRoutes, link: link} } -var _25 = function($window, mount0) { +var _24 = function($window, mount0) { var router = coreRouter($window) var currentResolve, currentComponent, currentRender, currentArgs, currentPath var RouteComponent = {view: function() { @@ -1174,7 +1173,7 @@ var _25 = function($window, mount0) { route.get = function() {return currentPath} return route } -m.route = _25(window, mount) +m.route = _24(window, mount) m.withAttr = function(attrName, callback2, context) { return function(e) { return callback2.call(context || this, attrName in e.currentTarget ? e.currentTarget[attrName] : e.currentTarget.getAttribute(attrName)) diff --git a/mithril.min.js b/mithril.min.js index 14df1588..6475ad96 100644 --- a/mithril.min.js +++ b/mithril.min.js @@ -1,8 +1,8 @@ new function(){function u(b,e,l,g,k,h){return{tag:b,key:e,attrs:l,children:g,text:k,dom:h,domSize:void 0,state:{},events:void 0,instance:void 0,skip:!1}}function w(b){if(null==b||"string"!==typeof b&&null==b.view)throw Error("The selector must be either a string or a component.");if("string"===typeof b&&void 0===G[b]){for(var e,l,g=[],k={};e=P.exec(b);){var h=e[1],q=e[2];""===h&&""!==q?l=q:"#"===h?k.id=q:"."===h?g.push(q):"["===e[3][0]&&((h=e[6])&&(h=h.replace(/\\(["'])/g,"$1").replace(/\\\\/g,"\\")), k[e[4]]=h||!0)}0d.filter(E).length)throw Error("Ensure that each item passed to m.prop.combine/m.prop.merge is a stream");return x(e(),d,function(){var b= diff --git a/module/module.js b/module/module.js index 661b65d0..b81953b8 100644 --- a/module/module.js +++ b/module/module.js @@ -11,7 +11,7 @@ require.$$current = function() { return src.replace(/\.js$/, "") } -var module = { +window.module = { get exports() {return require.$$modules[require.$$current()]}, set exports(value) {require.$$modules[require.$$current()] = value}, } diff --git a/ospec/ospec.js b/ospec/ospec.js index 50b9899e..85ed47b2 100644 --- a/ospec/ospec.js +++ b/ospec/ospec.js @@ -164,7 +164,7 @@ module.exports = new function init() { function define(name, verb, compare) { Assert.prototype[name] = function assert(value) { if (compare(this.value, value)) record(null) - else record(serialize(this.value) + " " + verb + " " + serialize(value)) + else record(serialize(this.value) + "\n" + verb + "\n" + serialize(value)) return function(message) { var result = results[results.length - 1] result.message = message + "\n\n" + result.message @@ -198,7 +198,7 @@ module.exports = new function init() { for (var i = 0, r; r = results[i]; i++) { if (!r.pass) { var stackTrace = r.error.match(/^(?:(?!Error|[\/\\]ospec[\/\\]ospec\.js).)*$/m) - console.error(r.context + ": " + highlight(r.message) + (stackTrace ? "\n\n" + stackTrace + "\n\n" : ""), hasProcess ? "" : "color:red", hasProcess ? "" : "color:black") + console.error(r.context + ":\n" + highlight(r.message) + (stackTrace ? "\n\n" + stackTrace + "\n\n" : ""), hasProcess ? "" : "color:red", hasProcess ? "" : "color:black") status = 1 } } diff --git a/promise/promise.js b/promise/promise.js index d96c988d..7151e5ce 100644 --- a/promise/promise.js +++ b/promise/promise.js @@ -63,7 +63,7 @@ Promise.prototype.catch = function(onRejection) { } Promise.resolve = function(value) { if (value instanceof Promise) return value - return new Promise(function(resolve, reject) {resolve(value)}) + return new Promise(function(resolve) {resolve(value)}) } Promise.reject = function(value) { return new Promise(function(resolve, reject) {reject(value)}) diff --git a/request/request.js b/request/request.js index 30c1eedc..b98ebc3c 100644 --- a/request/request.js +++ b/request/request.js @@ -1,7 +1,6 @@ "use strict" var buildQueryString = require("../querystring/build") -var StreamFactory = require("../util/stream") module.exports = function($window, Stream) { var callbackCount = 0 diff --git a/util/stream.js b/util/stream.js index 526ab1c8..c3edc31c 100644 --- a/util/stream.js +++ b/util/stream.js @@ -7,13 +7,13 @@ module.exports = function(log) { if (arguments.length > 0 && arguments[0] !== HALT) updateStream(stream, arguments[0], undefined) return stream._state.value } - initStream(stream, arguments) + initStream(stream) if (arguments.length > 0 && arguments[0] !== HALT) updateStream(stream, arguments[0], undefined) return stream } - function initStream(stream, args) { + function initStream(stream) { stream.constructor = createStream stream._state = {id: guid++, value: undefined, error: undefined, state: 0, derive: undefined, recover: undefined, deps: {}, parents: [], errorStream: undefined, endStream: undefined} stream.map = map, stream.ap = ap, stream.of = createStream @@ -27,7 +27,7 @@ module.exports = function(log) { if (arguments.length > 0 && arguments[0] !== HALT) updateStream(stream, undefined, arguments[0]) return stream._state.error } - initStream(errorStream, []) + initStream(errorStream) initDependency(errorStream, [stream], noop, noop) stream._state.errorStream = errorStream }