From 463378fb64e832d5358b9cb9758eb03ee8d81bfa Mon Sep 17 00:00:00 2001 From: Walker Randolph Smith Date: Sun, 16 Apr 2017 00:29:12 -0400 Subject: [PATCH 01/17] #384 Support eslint. No rules included. --- .eslintignore | 9 +++++++++ .eslintrc | 9 +++++++++ .gitignore | 3 ++- package.json | 4 +++- 4 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 .eslintignore create mode 100644 .eslintrc diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 000000000..7652eaed9 --- /dev/null +++ b/.eslintignore @@ -0,0 +1,9 @@ +dist/ +docs/ +examples/ +misc/ +test/ +gulpfile.js +index.js +/src/js/ace/**/*.* +/src/js/assets/**/*.* \ No newline at end of file diff --git a/.eslintrc b/.eslintrc new file mode 100644 index 000000000..e02e1fb18 --- /dev/null +++ b/.eslintrc @@ -0,0 +1,9 @@ +{ + "env": { + "browser": true + }, + "plugins": [], + "rules": { + + } +} \ No newline at end of file diff --git a/.gitignore b/.gitignore index 844710c57..837f7d1be 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,5 @@ build downloads node_modules *.zip -npm-debug.log \ No newline at end of file +npm-debug.log +.eslintcache \ No newline at end of file diff --git a/package.json b/package.json index 5632e4526..b76545c87 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,8 @@ "scripts": { "build": "gulp", "watch": "gulp watch", - "test": "mocha test" + "test": "mocha test", + "lint": "eslint -c .eslintrc --cache ." }, "dependencies": { "ajv": "4.11.6", @@ -28,6 +29,7 @@ "javascript-natural-sort": "0.7.1" }, "devDependencies": { + "eslint": "^3.19.0", "gulp": "3.9.1", "gulp-clean-css": "3.0.4", "gulp-concat-css": "2.3.0", From dd378fd2465697689710688048bb10ee5ef6f309 Mon Sep 17 00:00:00 2001 From: Walker Randolph Smith Date: Sun, 16 Apr 2017 00:30:05 -0400 Subject: [PATCH 02/17] #384 Enforce strict mode. --- .eslintrc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.eslintrc b/.eslintrc index e02e1fb18..f011dffc6 100644 --- a/.eslintrc +++ b/.eslintrc @@ -4,6 +4,6 @@ }, "plugins": [], "rules": { - + "strict": 0 } } \ No newline at end of file From e664f10a0f898c2f5676dc8893c12d85337af083 Mon Sep 17 00:00:00 2001 From: Walker Randolph Smith Date: Sun, 16 Apr 2017 00:31:01 -0400 Subject: [PATCH 03/17] #384 Enforce 2 space indentation --- .eslintrc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.eslintrc b/.eslintrc index f011dffc6..9248da453 100644 --- a/.eslintrc +++ b/.eslintrc @@ -4,6 +4,7 @@ }, "plugins": [], "rules": { - "strict": 0 + "strict": 0, + "indent": ["error", 2, { "SwitchCase": 1, "VariableDeclarator": 2 }] } } \ No newline at end of file From 7001ad56dffa66caab1db2167e809026b6ec9fb4 Mon Sep 17 00:00:00 2001 From: Walker Randolph Smith Date: Sun, 16 Apr 2017 00:32:26 -0400 Subject: [PATCH 04/17] #384 Enforce use of semicolons --- .eslintrc | 5 ++++- src/js/ModeSwitcher.js | 2 +- src/js/Node.js | 12 ++++++------ src/js/textmode.js | 4 ++-- src/js/treemode.js | 6 +++--- src/js/util.js | 4 ++-- 6 files changed, 18 insertions(+), 15 deletions(-) diff --git a/.eslintrc b/.eslintrc index 9248da453..9db2904db 100644 --- a/.eslintrc +++ b/.eslintrc @@ -5,6 +5,9 @@ "plugins": [], "rules": { "strict": 0, - "indent": ["error", 2, { "SwitchCase": 1, "VariableDeclarator": 2 }] + "indent": ["error", 2, { "SwitchCase": 1, "VariableDeclarator": 2 }], + "semi": [1, "always"], + "semi-spacing": [1, {"before": false, "after": true}], + "no-extra-semi": 2 } } \ No newline at end of file diff --git a/src/js/ModeSwitcher.js b/src/js/ModeSwitcher.js index 77c6c496d..65cf8e9e8 100644 --- a/src/js/ModeSwitcher.js +++ b/src/js/ModeSwitcher.js @@ -17,7 +17,7 @@ function ModeSwitcher(container, modes, current, onSwitch) { 'text': 'Code', 'title': 'Switch to code highlighter', 'click': function () { - onSwitch('code') + onSwitch('code'); } }, form: { diff --git a/src/js/Node.js b/src/js/Node.js index beb5565fb..9455a32c6 100644 --- a/src/js/Node.js +++ b/src/js/Node.js @@ -1438,7 +1438,7 @@ Node.prototype.validate = function () { error: { message: 'duplicate key "' + node.field + '"' } - } + }; }); } } @@ -2022,13 +2022,13 @@ Node._findEnum = function (schema) { var composite = schema.oneOf || schema.anyOf || schema.allOf; if (composite) { - var match = composite.filter(function (entry) {return entry.enum}); + var match = composite.filter(function (entry) {return entry.enum;}); if (match.length > 0) { return match[0].enum; } } - return null + return null; }; /** @@ -2044,14 +2044,14 @@ Node._findSchema = function (schema, path) { for (var i = 0; i < path.length && childSchema; i++) { var key = path[i]; if (typeof key === 'string' && childSchema.properties) { - childSchema = childSchema.properties[key] || null + childSchema = childSchema.properties[key] || null; } else if (typeof key === 'number' && childSchema.items) { - childSchema = childSchema.items + childSchema = childSchema.items; } } - return childSchema + return childSchema; }; /** diff --git a/src/js/textmode.js b/src/js/textmode.js index 7076fde58..d34cc4d4f 100644 --- a/src/js/textmode.js +++ b/src/js/textmode.js @@ -451,7 +451,7 @@ textmode.validate = function () { if (limit) { errors = errors.slice(0, MAX_ERRORS); var hidden = this.validateSchema.errors.length - MAX_ERRORS; - errors.push('(' + hidden + ' more errors...)') + errors.push('(' + hidden + ' more errors...)'); } var validationErrors = document.createElement('div'); @@ -467,7 +467,7 @@ textmode.validate = function () { '' + error.message + ''; } - return '' + message + '' + return '' + message + ''; }).join('') + '' + ''; diff --git a/src/js/treemode.js b/src/js/treemode.js index 1fc243e6b..feba1c7f6 100644 --- a/src/js/treemode.js +++ b/src/js/treemode.js @@ -410,10 +410,10 @@ treemode.validate = function () { return { node: root.findNode(error.dataPath), error: error - } + }; }) .filter(function hasNode (entry) { - return entry.node != null + return entry.node != null; }); } } @@ -1022,7 +1022,7 @@ treemode._findTopLevelNodes = function (start, end) { // startChild is a parent of endChild or vice versa startChild = root; endChild = root; - root = root.parent + root = root.parent; } else { // we have selected the root node (which doesn't have a parent) diff --git a/src/js/util.js b/src/js/util.js index e02e043ff..88aa8a926 100644 --- a/src/js/util.js +++ b/src/js/util.js @@ -169,7 +169,7 @@ exports.escapeUnicodeChars = function (text) { // as JSON doesn't interpret them as a single unicode char. return text.replace(/[\u007F-\uFFFF]/g, function(c) { return '\\u'+('0000' + c.charCodeAt(0).toString(16)).slice(-4); - }) + }); }; /** @@ -674,7 +674,7 @@ exports.parsePath = function parsePath(jsonPath) { throw new SyntaxError('Failed to parse path'); } - return [prop].concat(parsePath(remainder)) + return [prop].concat(parsePath(remainder)); }; /** From e20ce370b1637f71b2826e63056af0b89a54a1bb Mon Sep 17 00:00:00 2001 From: Walker Randolph Smith Date: Sun, 16 Apr 2017 00:34:34 -0400 Subject: [PATCH 05/17] #384 Enfore no trailing whitespace --- .eslintrc | 3 ++- src/js/textmode.js | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.eslintrc b/.eslintrc index 9db2904db..d65ad372a 100644 --- a/.eslintrc +++ b/.eslintrc @@ -8,6 +8,7 @@ "indent": ["error", 2, { "SwitchCase": 1, "VariableDeclarator": 2 }], "semi": [1, "always"], "semi-spacing": [1, {"before": false, "after": true}], - "no-extra-semi": 2 + "no-extra-semi": 2, + "no-trailing-spaces": 1 } } \ No newline at end of file diff --git a/src/js/textmode.js b/src/js/textmode.js index d34cc4d4f..d8ba6523e 100644 --- a/src/js/textmode.js +++ b/src/js/textmode.js @@ -291,7 +291,7 @@ textmode.destroy = function () { } this.textarea = null; - + this._debouncedValidate = null; }; From 2222171f2236033d8541bc0cfdff46f759d74f37 Mon Sep 17 00:00:00 2001 From: Walker Randolph Smith Date: Sun, 16 Apr 2017 00:38:21 -0400 Subject: [PATCH 06/17] #384 Show how to enforce line legth limit of 80 characters. Do not enforce the rule becasuse there are several violators. --- .eslintrc | 1 + 1 file changed, 1 insertion(+) diff --git a/.eslintrc b/.eslintrc index d65ad372a..24a495b3f 100644 --- a/.eslintrc +++ b/.eslintrc @@ -10,5 +10,6 @@ "semi-spacing": [1, {"before": false, "after": true}], "no-extra-semi": 2, "no-trailing-spaces": 1 + //"max-len": ["error", 80] } } \ No newline at end of file From 6a945a8c3496e8e4f0847adf4409a26fa5b67066 Mon Sep 17 00:00:00 2001 From: Walker Randolph Smith Date: Sun, 16 Apr 2017 00:42:41 -0400 Subject: [PATCH 07/17] #384 Enfore single quote strings --- .eslintrc | 3 ++- src/js/Node.js | 8 ++++---- src/js/treemode.js | 4 ++-- src/js/util.js | 16 ++++++++-------- 4 files changed, 16 insertions(+), 15 deletions(-) diff --git a/.eslintrc b/.eslintrc index 24a495b3f..26eabeb48 100644 --- a/.eslintrc +++ b/.eslintrc @@ -9,7 +9,8 @@ "semi": [1, "always"], "semi-spacing": [1, {"before": false, "after": true}], "no-extra-semi": 2, - "no-trailing-spaces": 1 + "no-trailing-spaces": 1, //"max-len": ["error", 80] + "quotes": [1, "single"] } } \ No newline at end of file diff --git a/src/js/Node.js b/src/js/Node.js index 9455a32c6..700f7c232 100644 --- a/src/js/Node.js +++ b/src/js/Node.js @@ -1282,7 +1282,7 @@ Node.prototype._updateDomValue = function () { // create select box when this node has an enum object if (!this.dom.select) { this.dom.select = document.createElement('select'); - this.id = this.field + "_" + new Date().getUTCMilliseconds(); + this.id = this.field + '_' + new Date().getUTCMilliseconds(); this.dom.select.id = this.id; this.dom.select.name = this.dom.select.id; @@ -1312,9 +1312,9 @@ Node.prototype._updateDomValue = function () { // If the enum is inside a composite type display // both the simple input and the dropdown field if(this.schema && ( - !this.schema.hasOwnProperty("oneOf") && - !this.schema.hasOwnProperty("anyOf") && - !this.schema.hasOwnProperty("allOf")) + !this.schema.hasOwnProperty('oneOf') && + !this.schema.hasOwnProperty('anyOf') && + !this.schema.hasOwnProperty('allOf')) ) { this.valueFieldHTML = this.dom.tdValue.innerHTML; this.dom.tdValue.style.visibility = 'hidden'; diff --git a/src/js/treemode.js b/src/js/treemode.js index feba1c7f6..83231065f 100644 --- a/src/js/treemode.js +++ b/src/js/treemode.js @@ -1126,11 +1126,11 @@ treemode._createTable = function () { this.colgroupContent = document.createElement('colgroup'); if (this.options.mode === 'tree') { col = document.createElement('col'); - col.width = "24px"; + col.width = '24px'; this.colgroupContent.appendChild(col); } col = document.createElement('col'); - col.width = "24px"; + col.width = '24px'; this.colgroupContent.appendChild(col); col = document.createElement('col'); this.colgroupContent.appendChild(col); diff --git a/src/js/util.js b/src/js/util.js index 88aa8a926..b0e20f16e 100644 --- a/src/js/util.js +++ b/src/js/util.js @@ -552,7 +552,7 @@ exports.getInternetExplorerVersion = function getInternetExplorerVersion() { if (navigator.appName == 'Microsoft Internet Explorer') { var ua = navigator.userAgent; - var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})"); + var re = new RegExp('MSIE ([0-9]{1,}[\.0-9]{0,})'); if (re.exec(ua) != null) { rv = parseFloat( RegExp.$1 ); } @@ -569,7 +569,7 @@ exports.getInternetExplorerVersion = function getInternetExplorerVersion() { * @returns {boolean} isFirefox */ exports.isFirefox = function isFirefox () { - return (navigator.userAgent.indexOf("Firefox") != -1); + return (navigator.userAgent.indexOf('Firefox') != -1); }; /** @@ -593,8 +593,8 @@ exports.addEventListener = function addEventListener(element, action, listener, if (useCapture === undefined) useCapture = false; - if (action === "mousewheel" && exports.isFirefox()) { - action = "DOMMouseScroll"; // For Firefox + if (action === 'mousewheel' && exports.isFirefox()) { + action = 'DOMMouseScroll'; // For Firefox } element.addEventListener(action, listener, useCapture); @@ -604,7 +604,7 @@ exports.addEventListener = function addEventListener(element, action, listener, var f = function () { return listener.call(element, window.event); }; - element.attachEvent("on" + action, f); + element.attachEvent('on' + action, f); return f; } }; @@ -621,14 +621,14 @@ exports.removeEventListener = function removeEventListener(element, action, list if (useCapture === undefined) useCapture = false; - if (action === "mousewheel" && exports.isFirefox()) { - action = "DOMMouseScroll"; // For Firefox + if (action === 'mousewheel' && exports.isFirefox()) { + action = 'DOMMouseScroll'; // For Firefox } element.removeEventListener(action, listener, useCapture); } else if (element.detachEvent) { // Old IE browsers - element.detachEvent("on" + action, listener); + element.detachEvent('on' + action, listener); } }; From 05d3a89adca527013cb442ba22634e22a4077e27 Mon Sep 17 00:00:00 2001 From: Walker Randolph Smith Date: Sun, 16 Apr 2017 00:55:59 -0400 Subject: [PATCH 08/17] #384 Enforce braces on the same line. currently the average (mode) style used is Stroustrup. Stroustrup: formatting where else statements in an if-else construct, as well as catch and finally, must be on its own line after the preceding closing brace --- .eslintrc | 3 ++- src/js/Node.js | 3 ++- src/js/util.js | 9 +++++---- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/.eslintrc b/.eslintrc index 26eabeb48..26b4c542d 100644 --- a/.eslintrc +++ b/.eslintrc @@ -11,6 +11,7 @@ "no-extra-semi": 2, "no-trailing-spaces": 1, //"max-len": ["error", 80] - "quotes": [1, "single"] + "quotes": [1, "single"], + "brace-style": ["error", "stroustrup", { "allowSingleLine": true }] } } \ No newline at end of file diff --git a/src/js/Node.js b/src/js/Node.js index 700f7c232..30a51bb38 100644 --- a/src/js/Node.js +++ b/src/js/Node.js @@ -1319,7 +1319,8 @@ Node.prototype._updateDomValue = function () { this.valueFieldHTML = this.dom.tdValue.innerHTML; this.dom.tdValue.style.visibility = 'hidden'; this.dom.tdValue.innerHTML = ''; - } else { + } + else { delete this.valueFieldHTML; } } diff --git a/src/js/util.js b/src/js/util.js index b0e20f16e..547cbf731 100644 --- a/src/js/util.js +++ b/src/js/util.js @@ -549,8 +549,7 @@ exports.getInnerText = function getInnerText(element, buffer) { exports.getInternetExplorerVersion = function getInternetExplorerVersion() { if (_ieVersion == -1) { var rv = -1; // Return value assumes failure. - if (navigator.appName == 'Microsoft Internet Explorer') - { + if (navigator.appName == 'Microsoft Internet Explorer') { var ua = navigator.userAgent; var re = new RegExp('MSIE ([0-9]{1,}[\.0-9]{0,})'); if (re.exec(ua) != null) { @@ -599,7 +598,8 @@ exports.addEventListener = function addEventListener(element, action, listener, element.addEventListener(action, listener, useCapture); return listener; - } else if (element.attachEvent) { + } + else if (element.attachEvent) { // Old IE browsers var f = function () { return listener.call(element, window.event); @@ -626,7 +626,8 @@ exports.removeEventListener = function removeEventListener(element, action, list } element.removeEventListener(action, listener, useCapture); - } else if (element.detachEvent) { + } + else if (element.detachEvent) { // Old IE browsers element.detachEvent('on' + action, listener); } From 8b1d0cae43955658de2c4b5070be6fa4b8b8944d Mon Sep 17 00:00:00 2001 From: Walker Randolph Smith Date: Sun, 16 Apr 2017 01:07:42 -0400 Subject: [PATCH 09/17] #384 Enforce one variable declaration per var statement. --- .eslintrc | 3 ++- src/js/ContextMenu.js | 5 ++++- src/js/JSONEditor.js | 3 ++- src/js/Node.js | 41 ++++++++++++++++++++++++++++------------- src/js/util.js | 12 ++++++++---- 5 files changed, 44 insertions(+), 20 deletions(-) diff --git a/.eslintrc b/.eslintrc index 26b4c542d..8d1fb2f37 100644 --- a/.eslintrc +++ b/.eslintrc @@ -12,6 +12,7 @@ "no-trailing-spaces": 1, //"max-len": ["error", 80] "quotes": [1, "single"], - "brace-style": ["error", "stroustrup", { "allowSingleLine": true }] + "brace-style": ["error", "stroustrup", { "allowSingleLine": true }], + "one-var": ["error", { "var": "never" }] } } \ No newline at end of file diff --git a/src/js/ContextMenu.js b/src/js/ContextMenu.js index 216a1bcc1..e5b637c3f 100644 --- a/src/js/ContextMenu.js +++ b/src/js/ContextMenu.js @@ -339,7 +339,10 @@ ContextMenu.prototype._onKeyDown = function (event) { var target = event.target; var keynum = event.which; var handled = false; - var buttons, targetIndex, prevButton, nextButton; + var buttons; + var targetIndex; + var prevButton; + var nextButton; if (keynum == 27) { // ESC // hide the menu on ESC key diff --git a/src/js/JSONEditor.js b/src/js/JSONEditor.js index 7420d4951..019dc97a1 100644 --- a/src/js/JSONEditor.js +++ b/src/js/JSONEditor.js @@ -344,7 +344,8 @@ JSONEditor.prototype.refresh = function () { * @param {Object | Array} mode A mode object or an array with multiple mode objects. */ JSONEditor.registerMode = function (mode) { - var i, prop; + var i; + var prop; if (util.isArray(mode)) { // multiple modes diff --git a/src/js/Node.js b/src/js/Node.js index 30a51bb38..8d08ee104 100644 --- a/src/js/Node.js +++ b/src/js/Node.js @@ -261,7 +261,8 @@ Node.prototype.getField = function() { * 'array', 'object', or 'string' */ Node.prototype.setValue = function(value, type) { - var childValue, child; + var childValue; + var child; // first clear all current childs (if any) var childs = this.childs; @@ -1588,9 +1589,20 @@ Node.onDrag = function (nodes, event) { var editor = nodes[0].editor; var mouseY = event.pageY - editor.drag.offsetY; var mouseX = event.pageX; - var trThis, trPrev, trNext, trFirst, trLast, trRoot; - var nodePrev, nodeNext; - var topThis, topPrev, topFirst, heightThis, bottomNext, heightNext; + var trThis; + var trPrev; + var trNext; + var trFirst; + var trLast; + var trRoot; + var nodePrev; + var nodeNext; + var topThis; + var topPrev; + var topFirst; + var heightThis; + var bottomNext; + var heightNext; var moved = false; // TODO: add an ESC option, which resets to the original position @@ -2204,11 +2216,11 @@ Node.prototype._createDomTree = function () { * @param {Event} event */ Node.prototype.onEvent = function (event) { - var type = event.type, - target = event.target || event.srcElement, - dom = this.dom, - node = this, - expandable = this._hasChilds(); + var type = event.type; + var target = event.target || event.srcElement; + var dom = this.dom; + var node = this; + var expandable = this._hasChilds(); // check if mouse is on menu or on dragarea. // If so, highlight current row and its childs @@ -2393,7 +2405,10 @@ Node.prototype.onKeyDown = function (event) { var shiftKey = event.shiftKey; var altKey = event.altKey; var handled = false; - var prevNode, nextNode, nextDom, nextDom2; + var prevNode; + var nextNode; + var nextDom; + var nextDom2; var editable = this.editor.options.mode === 'tree'; var oldSelection; var oldBeforeNode; @@ -3420,9 +3435,9 @@ Node.prototype._getType = function(value) { * @private */ Node.prototype._stringCast = function(str) { - var lower = str.toLowerCase(), - num = Number(str), // will nicely fail with '123ab' - numFloat = parseFloat(str); // will nicely fail with ' ' + var lower = str.toLowerCase(); + var num = Number(str); // will nicely fail with '123ab' + var numFloat = parseFloat(str); // will nicely fail with ' ' if (str == '') { return ''; diff --git a/src/js/util.js b/src/js/util.js index 547cbf731..b8d7f8183 100644 --- a/src/js/util.js +++ b/src/js/util.js @@ -357,7 +357,8 @@ exports.stripFormatting = function stripFormatting(divElement) { * @param {Element} contentEditableElement A content editable div */ exports.setEndOfContentEditable = function setEndOfContentEditable(contentEditableElement) { - var range, selection; + var range; + var selection; if(document.createRange) { range = document.createRange();//Create a range (a range is a like the selection but invisible) range.selectNodeContents(contentEditableElement);//Select the entire contents of the element with the range @@ -378,7 +379,8 @@ exports.selectContentEditable = function selectContentEditable(contentEditableEl return; } - var sel, range; + var sel; + var range; if (window.getSelection && document.createRange) { range = document.createRange(); range.selectNodeContents(contentEditableElement); @@ -639,7 +641,8 @@ exports.removeEventListener = function removeEventListener(element, action, list * @return {Array} */ exports.parsePath = function parsePath(jsonPath) { - var prop, remainder; + var prop; + var remainder; if (jsonPath.length === 0) { return []; @@ -738,7 +741,8 @@ exports.insideRect = function (parent, child, margin) { exports.debounce = function debounce(func, wait, immediate) { var timeout; return function() { - var context = this, args = arguments; + var context = this; + var args = arguments; var later = function() { timeout = null; if (!immediate) func.apply(context, args); From cd5e905acbce53c8a0acbd252d92cf385b1c8f44 Mon Sep 17 00:00:00 2001 From: Walker Randolph Smith Date: Sun, 16 Apr 2017 01:08:48 -0400 Subject: [PATCH 10/17] #384 Enfore camelcase --- .eslintrc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.eslintrc b/.eslintrc index 8d1fb2f37..8934f89ac 100644 --- a/.eslintrc +++ b/.eslintrc @@ -13,6 +13,7 @@ //"max-len": ["error", 80] "quotes": [1, "single"], "brace-style": ["error", "stroustrup", { "allowSingleLine": true }], - "one-var": ["error", { "var": "never" }] + "one-var": ["error", { "var": "never" }], + "camelcase": "error" } } \ No newline at end of file From ec70849016caa03552c04ed13f3221dcb4c5fee9 Mon Sep 17 00:00:00 2001 From: Walker Randolph Smith Date: Sun, 16 Apr 2017 01:16:36 -0400 Subject: [PATCH 11/17] #384 Enforce class names being capitalized with the exception of Ajv --- .eslintrc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.eslintrc b/.eslintrc index 8934f89ac..9e6b8a787 100644 --- a/.eslintrc +++ b/.eslintrc @@ -14,6 +14,7 @@ "quotes": [1, "single"], "brace-style": ["error", "stroustrup", { "allowSingleLine": true }], "one-var": ["error", { "var": "never" }], - "camelcase": "error" + "camelcase": "error", + "new-cap": ["error", { "capIsNewExceptions": ["Ajv"] }] } } \ No newline at end of file From 2c2487cb423a9b93c1ae418445f00fdd04426cf9 Mon Sep 17 00:00:00 2001 From: Walker Randolph Smith Date: Sun, 16 Apr 2017 01:27:11 -0400 Subject: [PATCH 12/17] #384 Enfore using single quotes in object keys only when needed --- .eslintrc | 3 +- src/js/History.js | 66 ++++++++++++++++++------------------- src/js/ModeSwitcher.js | 30 ++++++++--------- src/js/Node.js | 32 +++++++++--------- src/js/appendNodeFactory.js | 44 ++++++++++++------------- src/js/util.js | 6 ++-- 6 files changed, 91 insertions(+), 90 deletions(-) diff --git a/.eslintrc b/.eslintrc index 9e6b8a787..acaf6c2c7 100644 --- a/.eslintrc +++ b/.eslintrc @@ -15,6 +15,7 @@ "brace-style": ["error", "stroustrup", { "allowSingleLine": true }], "one-var": ["error", { "var": "never" }], "camelcase": "error", - "new-cap": ["error", { "capIsNewExceptions": ["Ajv"] }] + "new-cap": ["error", { "capIsNewExceptions": ["Ajv"] }], + "quote-props": ["error", "as-needed"] } } \ No newline at end of file diff --git a/src/js/History.js b/src/js/History.js index 1a8b0bf66..63208ba3d 100644 --- a/src/js/History.js +++ b/src/js/History.js @@ -16,62 +16,62 @@ function History (editor) { // map with all supported actions this.actions = { - 'editField': { - 'undo': function (params) { + editField: { + undo: function (params) { params.node.updateField(params.oldValue); }, - 'redo': function (params) { + redo: function (params) { params.node.updateField(params.newValue); } }, - 'editValue': { - 'undo': function (params) { + editValue: { + undo: function (params) { params.node.updateValue(params.oldValue); }, - 'redo': function (params) { + redo: function (params) { params.node.updateValue(params.newValue); } }, - 'changeType': { - 'undo': function (params) { + changeType: { + undo: function (params) { params.node.changeType(params.oldType); }, - 'redo': function (params) { + redo: function (params) { params.node.changeType(params.newType); } }, - 'appendNodes': { - 'undo': function (params) { + appendNodes: { + undo: function (params) { params.nodes.forEach(function (node) { params.parent.removeChild(node); }); }, - 'redo': function (params) { + redo: function (params) { params.nodes.forEach(function (node) { params.parent.appendChild(node); }); } }, - 'insertBeforeNodes': { - 'undo': function (params) { + insertBeforeNodes: { + undo: function (params) { params.nodes.forEach(function (node) { params.parent.removeChild(node); }); }, - 'redo': function (params) { + redo: function (params) { params.nodes.forEach(function (node) { params.parent.insertBefore(node, params.beforeNode); }); } }, - 'insertAfterNodes': { - 'undo': function (params) { + insertAfterNodes: { + undo: function (params) { params.nodes.forEach(function (node) { params.parent.removeChild(node); }); }, - 'redo': function (params) { + redo: function (params) { var afterNode = params.afterNode; params.nodes.forEach(function (node) { params.parent.insertAfter(params.node, afterNode); @@ -79,27 +79,27 @@ function History (editor) { }); } }, - 'removeNodes': { - 'undo': function (params) { + removeNodes: { + undo: function (params) { var parent = params.parent; var beforeNode = parent.childs[params.index] || parent.append; params.nodes.forEach(function (node) { parent.insertBefore(node, beforeNode); }); }, - 'redo': function (params) { + redo: function (params) { params.nodes.forEach(function (node) { params.parent.removeChild(node); }); } }, - 'duplicateNodes': { - 'undo': function (params) { + duplicateNodes: { + undo: function (params) { params.nodes.forEach(function (node) { params.parent.removeChild(node); }); }, - 'redo': function (params) { + redo: function (params) { var afterNode = params.afterNode; params.nodes.forEach(function (node) { params.parent.insertAfter(node, afterNode); @@ -107,28 +107,28 @@ function History (editor) { }); } }, - 'moveNodes': { - 'undo': function (params) { + moveNodes: { + undo: function (params) { params.nodes.forEach(function (node) { params.oldBeforeNode.parent.moveBefore(node, params.oldBeforeNode); }); }, - 'redo': function (params) { + redo: function (params) { params.nodes.forEach(function (node) { params.newBeforeNode.parent.moveBefore(node, params.newBeforeNode); }); } }, - 'sort': { - 'undo': function (params) { + sort: { + undo: function (params) { var node = params.node; node.hideChilds(); node.sort = params.oldSort; node.childs = params.oldChilds; node.showChilds(); }, - 'redo': function (params) { + redo: function (params) { var node = params.node; node.hideChilds(); node.sort = params.newSort; @@ -162,9 +162,9 @@ History.prototype.onChange = function () {}; History.prototype.add = function (action, params) { this.index++; this.history[this.index] = { - 'action': action, - 'params': params, - 'timestamp': new Date() + action: action, + params: params, + timestamp: new Date() }; // remove redo actions which are invalid now diff --git a/src/js/ModeSwitcher.js b/src/js/ModeSwitcher.js index 65cf8e9e8..b3f1977ff 100644 --- a/src/js/ModeSwitcher.js +++ b/src/js/ModeSwitcher.js @@ -14,37 +14,37 @@ function ModeSwitcher(container, modes, current, onSwitch) { // available modes var availableModes = { code: { - 'text': 'Code', - 'title': 'Switch to code highlighter', - 'click': function () { + text: 'Code', + title: 'Switch to code highlighter', + click: function () { onSwitch('code'); } }, form: { - 'text': 'Form', - 'title': 'Switch to form editor', - 'click': function () { + text: 'Form', + title: 'Switch to form editor', + click: function () { onSwitch('form'); } }, text: { - 'text': 'Text', - 'title': 'Switch to plain text editor', - 'click': function () { + text: 'Text', + title: 'Switch to plain text editor', + click: function () { onSwitch('text'); } }, tree: { - 'text': 'Tree', - 'title': 'Switch to tree editor', - 'click': function () { + text: 'Tree', + title: 'Switch to tree editor', + click: function () { onSwitch('tree'); } }, view: { - 'text': 'View', - 'title': 'Switch to tree view', - 'click': function () { + text: 'View', + title: 'Switch to tree view', + click: function () { onSwitch('view'); } } diff --git a/src/js/Node.js b/src/js/Node.js index 8d08ee104..7ac1b9163 100644 --- a/src/js/Node.js +++ b/src/js/Node.js @@ -567,8 +567,8 @@ Node.prototype.appendChild = function(node) { node.showChilds(); } - this.updateDom({'updateIndexes': true}); - node.updateDom({'recurse': true}); + this.updateDom({updateIndexes: true}); + node.updateDom({recurse: true}); } }; @@ -669,8 +669,8 @@ Node.prototype.insertBefore = function(node, beforeNode) { node.showChilds(); } - this.updateDom({'updateIndexes': true}); - node.updateDom({'recurse': true}); + this.updateDom({updateIndexes: true}); + node.updateDom({recurse: true}); } }; @@ -716,8 +716,8 @@ Node.prototype.search = function(text) { if (index != -1) { this.searchField = true; results.push({ - 'node': this, - 'elem': 'field' + node: this, + elem: 'field' }); } @@ -757,8 +757,8 @@ Node.prototype.search = function(text) { if (index != -1) { this.searchValue = true; results.push({ - 'node': this, - 'elem': 'value' + node: this, + elem: 'value' }); } } @@ -986,7 +986,7 @@ Node.prototype.removeChild = function(node) { var removedNode = this.childs.splice(index, 1)[0]; removedNode.parent = null; - this.updateDom({'updateIndexes': true}); + this.updateDom({updateIndexes: true}); return removedNode; } @@ -1104,7 +1104,7 @@ Node.prototype.changeType = function (newType) { this.focus(); } - this.updateDom({'updateIndexes': true}); + this.updateDom({updateIndexes: true}); }; /** @@ -1518,7 +1518,7 @@ Node.prototype.getDom = function() { dom.tree = this._createDomTree(); tdField.appendChild(dom.tree); - this.updateDom({'updateIndexes': true}); + this.updateDom({updateIndexes: true}); return dom.tr; }; @@ -3179,14 +3179,14 @@ Node.prototype._hasChilds = function () { // titles with explanation for the different types Node.TYPE_TITLES = { - 'auto': 'Field type "auto". ' + + auto: 'Field type "auto". ' + 'The field type is automatically determined from the value ' + 'and can be a string, number, boolean, or null.', - 'object': 'Field type "object". ' + + object: 'Field type "object". ' + 'An object contains an unordered set of key/value pairs.', - 'array': 'Field type "array". ' + + array: 'Field type "array". ' + 'An array contains an ordered collection of values.', - 'string': 'Field type "string". ' + + string: 'Field type "string". ' + 'Field type is not determined from the value, ' + 'but always returned as string.' }; @@ -3283,7 +3283,7 @@ Node.prototype.showContextMenu = function (anchor, onClose) { if (items.length) { // create a separator items.push({ - 'type': 'separator' + type: 'separator' }); } diff --git a/src/js/appendNodeFactory.js b/src/js/appendNodeFactory.js index 494dcb61c..1e1151965 100644 --- a/src/js/appendNodeFactory.js +++ b/src/js/appendNodeFactory.js @@ -137,43 +137,43 @@ function appendNodeFactory(Node) { var items = [ // create append button { - 'text': 'Append', - 'title': 'Append a new field with type \'auto\' (Ctrl+Shift+Ins)', - 'submenuTitle': 'Select the type of the field to be appended', - 'className': 'jsoneditor-insert', - 'click': function () { + text: 'Append', + title: 'Append a new field with type \'auto\' (Ctrl+Shift+Ins)', + submenuTitle: 'Select the type of the field to be appended', + className: 'jsoneditor-insert', + click: function () { node._onAppend('', '', 'auto'); }, - 'submenu': [ + submenu: [ { - 'text': 'Auto', - 'className': 'jsoneditor-type-auto', - 'title': titles.auto, - 'click': function () { + text: 'Auto', + className: 'jsoneditor-type-auto', + title: titles.auto, + click: function () { node._onAppend('', '', 'auto'); } }, { - 'text': 'Array', - 'className': 'jsoneditor-type-array', - 'title': titles.array, - 'click': function () { + text: 'Array', + className: 'jsoneditor-type-array', + title: titles.array, + click: function () { node._onAppend('', []); } }, { - 'text': 'Object', - 'className': 'jsoneditor-type-object', - 'title': titles.object, - 'click': function () { + text: 'Object', + className: 'jsoneditor-type-object', + title: titles.object, + click: function () { node._onAppend('', {}); } }, { - 'text': 'String', - 'className': 'jsoneditor-type-string', - 'title': titles.string, - 'click': function () { + text: 'String', + className: 'jsoneditor-type-string', + title: titles.string, + click: function () { node._onAppend('', '', 'string'); } } diff --git a/src/js/util.js b/src/js/util.js index b8d7f8183..c4fbd9d53 100644 --- a/src/js/util.js +++ b/src/js/util.js @@ -481,13 +481,13 @@ exports.getInnerText = function getInnerText(element, buffer) { var first = (buffer == undefined); if (first) { buffer = { - 'text': '', - 'flush': function () { + text: '', + flush: function () { var text = this.text; this.text = ''; return text; }, - 'set': function (text) { + set: function (text) { this.text = text; } }; From 3c9d1a403ebac3e3adee4d16f814a921d596b692 Mon Sep 17 00:00:00 2001 From: Walker Randolph Smith Date: Sun, 16 Apr 2017 01:29:15 -0400 Subject: [PATCH 13/17] #384 Enfore requiring a comma after and on the same line as an array element, object property, or variable declaration --- .eslintrc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.eslintrc b/.eslintrc index acaf6c2c7..12c8276d4 100644 --- a/.eslintrc +++ b/.eslintrc @@ -16,6 +16,7 @@ "one-var": ["error", { "var": "never" }], "camelcase": "error", "new-cap": ["error", { "capIsNewExceptions": ["Ajv"] }], - "quote-props": ["error", "as-needed"] + "quote-props": ["error", "as-needed"], + "comma-style": ["error", "last"] } } \ No newline at end of file From 8a4c6f554fda4d567ebc54b550e90127bddeefe2 Mon Sep 17 00:00:00 2001 From: Walker Randolph Smith Date: Sun, 16 Apr 2017 01:32:01 -0400 Subject: [PATCH 14/17] #384 Show how to enfore === !=== equality comparators. Many violators made me decied to punt on enforcing strict equality comparators --- .eslintrc | 1 + 1 file changed, 1 insertion(+) diff --git a/.eslintrc b/.eslintrc index 12c8276d4..69feed377 100644 --- a/.eslintrc +++ b/.eslintrc @@ -18,5 +18,6 @@ "new-cap": ["error", { "capIsNewExceptions": ["Ajv"] }], "quote-props": ["error", "as-needed"], "comma-style": ["error", "last"] + //"eqeqeq": "error" } } \ No newline at end of file From 41d1359667de0b26c2092a06fd2b96916410533f Mon Sep 17 00:00:00 2001 From: Walker Randolph Smith Date: Sun, 16 Apr 2017 10:28:56 -0400 Subject: [PATCH 15/17] #384 Enforce not extending prototype of native objects --- .eslintrc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.eslintrc b/.eslintrc index 69feed377..74a9201d6 100644 --- a/.eslintrc +++ b/.eslintrc @@ -17,7 +17,8 @@ "camelcase": "error", "new-cap": ["error", { "capIsNewExceptions": ["Ajv"] }], "quote-props": ["error", "as-needed"], - "comma-style": ["error", "last"] - //"eqeqeq": "error" + "comma-style": ["error", "last"], + //"eqeqeq": "error", + "no-extend-native": "error" } } \ No newline at end of file From 9b2765eb56de5e29c1b8597d6a0d6486b75b43c5 Mon Sep 17 00:00:00 2001 From: Walker Randolph Smith Date: Sun, 16 Apr 2017 10:39:11 -0400 Subject: [PATCH 16/17] #384 Show how to enforce maximum number of statements in a single function --- .eslintrc | 1 + 1 file changed, 1 insertion(+) diff --git a/.eslintrc b/.eslintrc index 74a9201d6..52db0cb97 100644 --- a/.eslintrc +++ b/.eslintrc @@ -20,5 +20,6 @@ "comma-style": ["error", "last"], //"eqeqeq": "error", "no-extend-native": "error" + //"max-statements": ["error", 10] } } \ No newline at end of file From 5d342f3913c34fc07d16f1be4e7398d542a493af Mon Sep 17 00:00:00 2001 From: Walker Randolph Smith Date: Sun, 16 Apr 2017 10:43:21 -0400 Subject: [PATCH 17/17] #384 Ensure every rule throws an error instead of warning --- .eslintrc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.eslintrc b/.eslintrc index 52db0cb97..18fd45b8c 100644 --- a/.eslintrc +++ b/.eslintrc @@ -6,12 +6,12 @@ "rules": { "strict": 0, "indent": ["error", 2, { "SwitchCase": 1, "VariableDeclarator": 2 }], - "semi": [1, "always"], - "semi-spacing": [1, {"before": false, "after": true}], + "semi": ["error", "always"], + "semi-spacing": ["error", {"before": false, "after": true}], "no-extra-semi": 2, "no-trailing-spaces": 1, //"max-len": ["error", 80] - "quotes": [1, "single"], + "quotes": ["error", "single"], "brace-style": ["error", "stroustrup", { "allowSingleLine": true }], "one-var": ["error", { "var": "never" }], "camelcase": "error",