From f7d2bdfd8b39361c0d83db8e264064cd29fa55f8 Mon Sep 17 00:00:00 2001 From: Frederic Junod Date: Tue, 20 Oct 2015 17:14:53 +0200 Subject: [PATCH 1/5] Lint the javascript code with eslint --- .eslintrc | 14 ++++++++++++++ gulpfile.js | 7 +++++++ package.json | 2 ++ 3 files changed, 23 insertions(+) create mode 100644 .eslintrc diff --git a/.eslintrc b/.eslintrc new file mode 100644 index 00000000..d959af7b --- /dev/null +++ b/.eslintrc @@ -0,0 +1,14 @@ +{ + "extends": "eslint:recommended", + "env": { + "browser": true + }, + "plugins": [ + "html" + ], + "globals": { + "CustomElements": true, + "HTMLImports": true, + "Polymer": true + } +} diff --git a/gulpfile.js b/gulpfile.js index c201c2c3..c9165940 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -20,6 +20,7 @@ var runseq = require('run-sequence'); var lazypipe = require('lazypipe'); var polyclean = require('polyclean'); var del = require('del'); +var eslint = require('gulp-eslint'); var path = require('path'); @@ -124,3 +125,9 @@ gulp.task('audit', function() { gulp.task('release', function(cb) { runseq('default', ['copy-bower-json', 'audit'], cb); }); + +gulp.task('eslint', function() { + return gulp.src('src/**/*.html') + .pipe(eslint()) + .pipe(eslint.format()); +}); diff --git a/package.json b/package.json index a086fad6..9ce05ebc 100644 --- a/package.json +++ b/package.json @@ -9,8 +9,10 @@ }, "devDependencies": { "del": "^1.1.1", + "eslint-plugin-html": "^1.3.0", "gulp": "^3.8.11", "gulp-audit": "^1.0.0", + "gulp-eslint": "^1.1.1", "gulp-rename": "^1.2.2", "gulp-replace": "^0.5.3", "gulp-vulcanize": "^6.0.1", From f3c4bb1cd66fa4137bc5f4b2aaa394f4aad21146 Mon Sep 17 00:00:00 2001 From: Daniel Freedman Date: Fri, 5 Feb 2016 12:08:01 -0800 Subject: [PATCH 2/5] Use ESLint for Polymer Modified version of #2600 - Ignores experimental and demo folders - A few style tweaks - Rename gulp task to `gulp lint`, and cause it to emit non-zero status for travis testing Thanks to @fredj for the base PR --- .eslintignore | 5 +++++ .eslintrc | 4 ++++ gulpfile.js | 5 +++-- 3 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 .eslintignore diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 00000000..552fce7f --- /dev/null +++ b/.eslintignore @@ -0,0 +1,5 @@ +node_modules/* +bower_components/* +test/* +src/**/demo/* +src/**/experimental/* diff --git a/.eslintrc b/.eslintrc index d959af7b..873b5c96 100644 --- a/.eslintrc +++ b/.eslintrc @@ -1,5 +1,9 @@ { "extends": "eslint:recommended", + "rules": { + "no-cond-assign": [2, "except-parens"], + "no-console": 0 + }, "env": { "browser": true }, diff --git a/gulpfile.js b/gulpfile.js index c9165940..b3e02279 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -126,8 +126,9 @@ gulp.task('release', function(cb) { runseq('default', ['copy-bower-json', 'audit'], cb); }); -gulp.task('eslint', function() { +gulp.task('lint', function() { return gulp.src('src/**/*.html') .pipe(eslint()) - .pipe(eslint.format()); + .pipe(eslint.format()) + .pipe(eslint.failAfterError()); }); From c7554d9daa39dda3b3a1e4c7f44e604e96148b6d Mon Sep 17 00:00:00 2001 From: Daniel Freedman Date: Fri, 5 Feb 2016 15:28:17 -0800 Subject: [PATCH 3/5] [ci skip] .eslintrc is deprecated, add .json suffix `no-cond-assing: [2, "except-parens"]` is default, removing --- .eslintrc => .eslintrc.json | 1 - 1 file changed, 1 deletion(-) rename .eslintrc => .eslintrc.json (84%) diff --git a/.eslintrc b/.eslintrc.json similarity index 84% rename from .eslintrc rename to .eslintrc.json index 873b5c96..94a41a64 100644 --- a/.eslintrc +++ b/.eslintrc.json @@ -1,7 +1,6 @@ { "extends": "eslint:recommended", "rules": { - "no-cond-assign": [2, "except-parens"], "no-console": 0 }, "env": { From acdfc1e097dbe9c984aad72c4aba94463341e599 Mon Sep 17 00:00:00 2001 From: Daniel Freedman Date: Mon, 8 Feb 2016 14:04:17 -0800 Subject: [PATCH 4/5] Test with ESLint enabled Fix linter errors --- .travis.yml | 1 + package.json | 2 +- src/lib/annotations/annotations.html | 778 +++++----- src/lib/array-splice.html | 10 +- src/lib/bind/accessors.html | 8 +- src/lib/collection.html | 10 +- src/lib/custom-style.html | 1 - src/lib/dom-api-effective-nodes-observer.html | 532 ++++--- src/lib/dom-api-shady.html | 18 +- src/lib/dom-innerHTML.html | 262 ++-- src/lib/dom-module.html | 4 +- src/lib/dom-tree-api.html | 36 +- src/lib/render-status.html | 8 +- src/lib/style-defaults.html | 181 ++- src/lib/style-extends.html | 202 +-- src/lib/style-properties.html | 6 +- src/lib/template/dom-repeat.html | 26 +- src/lib/template/templatizer.html | 8 +- src/micro/attributes.html | 5 +- src/micro/properties.html | 6 +- src/mini/shady.html | 16 +- src/standard/annotations.html | 2 +- src/standard/gestures.html | 2 +- src/standard/notify-path.html | 1265 +++++++++-------- src/standard/utils.html | 4 +- src/standard/x-styling.html | 3 +- 26 files changed, 1696 insertions(+), 1700 deletions(-) diff --git a/.travis.yml b/.travis.yml index 9d3a1a94..0bc7a848 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,6 +15,7 @@ before_script: - npm install -g bower - bower install script: +- gulp lint - xvfb-run wct - "if [ \"${TRAVIS_PULL_REQUEST}\" = \"false\" ]; then wct -s 'default'; fi" env: diff --git a/package.json b/package.json index 9ce05ebc..58036b0e 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,7 @@ }, "scripts": { "build": "gulp", - "test": "wct", + "test": "gulp lint && wct", "test-build": "gulp switch && wct && gulp restore" }, "repository": { diff --git a/src/lib/annotations/annotations.html b/src/lib/annotations/annotations.html index d3762755..de871dac 100644 --- a/src/lib/annotations/annotations.html +++ b/src/lib/annotations/annotations.html @@ -1,389 +1,389 @@ - - - - + + + + diff --git a/src/lib/array-splice.html b/src/lib/array-splice.html index f51279a7..8c4da154 100644 --- a/src/lib/array-splice.html +++ b/src/lib/array-splice.html @@ -10,7 +10,7 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN \ No newline at end of file + diff --git a/src/lib/bind/accessors.html b/src/lib/bind/accessors.html index 66175dea..99739813 100644 --- a/src/lib/bind/accessors.html +++ b/src/lib/bind/accessors.html @@ -23,7 +23,7 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN _notifyChange: function(source, event, value) { value = value === undefined ? this[source] : value; event = event || Polymer.CaseMap.camelToDashCase(source) + '-changed'; - this.fire(event, {value: value}, + this.fire(event, {value: value}, {bubbles: false, cancelable: false, _useCache: true}); }, @@ -221,8 +221,8 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN } else { // TODO(sorvell): even though we have a `value` argument, we *must* // lookup the current value of the property. Multiple listeners and - // queued events during configuration can theoretically lead to - // divergence of the passed value from the current value, but we + // queued events during configuration can theoretically lead to + // divergence of the passed value from the current value, but we // really need to track down a specific case where this happens. value = target[property]; if (!isStructured) { @@ -256,7 +256,7 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN //if (node._prepParentProperties || !node._propertyInfo || (p && p.notify)) { this._addNotifyListener(node, inst, info.event, info.changedFn); //} - }; + } }, // TODO(sorvell): note, adding these synchronously may impact performance, diff --git a/src/lib/collection.html b/src/lib/collection.html index 997b3a5f..91d6ca49 100644 --- a/src/lib/collection.html +++ b/src/lib/collection.html @@ -50,7 +50,7 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN }, removeKey: function(key) { - if (key = this._parseKey(key)) { + if ((key = this._parseKey(key))) { this._removeFromMap(this.store[key]); delete this.store[key]; } @@ -95,7 +95,7 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN }, setItem: function(key, item) { - if (key = this._parseKey(key)) { + if ((key = this._parseKey(key))) { var old = this.store[key]; if (old) { this._removeFromMap(old); @@ -110,7 +110,7 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN }, getItem: function(key) { - if (key = this._parseKey(key)) { + if ((key = this._parseKey(key))) { return this.store[key]; } }, @@ -140,7 +140,7 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN key = this.getKey(s.removed[j]); keyMap[key] = keyMap[key] ? null : -1; } - for (var j=0; j (function() { - var nativeShadow = Polymer.Settings.useNativeShadow; var propertyUtils = Polymer.StyleProperties; var styleUtil = Polymer.StyleUtil; var cssParse = Polymer.CssParse; diff --git a/src/lib/dom-api-effective-nodes-observer.html b/src/lib/dom-api-effective-nodes-observer.html index f98de7d4..9eb3fe7e 100644 --- a/src/lib/dom-api-effective-nodes-observer.html +++ b/src/lib/dom-api-effective-nodes-observer.html @@ -1,268 +1,264 @@ - - - \ No newline at end of file + + + diff --git a/src/lib/dom-api-shady.html b/src/lib/dom-api-shady.html index b15bfac7..7c4da0b2 100644 --- a/src/lib/dom-api-shady.html +++ b/src/lib/dom-api-shady.html @@ -93,7 +93,7 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN if (root) { // note: we always need to see if an insertion point is added // since this saves logical tree info; however, invalidation state - // needs + // needs var ipAdded = this._maybeAddInsertionPoint(node, this.node); // invalidate insertion points IFF not already invalid! if (!root._invalidInsertionPoints) { @@ -107,14 +107,14 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN // if not distributing and not adding to host, do a fast path addition var handled = this._maybeDistribute(node) || this.node.shadyRoot; - // if shady is handling this node, + // if shady is handling this node, // the actual dom may not be removed if the node or fragment contents // remain undistributed so we ensure removal here. // NOTE: we only remove from existing location iff shady dom is involved. // This is because a node fragment is passed to the native add method // which expects to see fragment children. Regular elements must also - // use this check because not doing so causes separation of - // attached/detached and breaks, for example, + // use this check because not doing so causes separation of + // attached/detached and breaks, for example, // dom-if's attached/detached checks. if (handled) { if (node.nodeType === Node.DOCUMENT_FRAGMENT_NODE) { @@ -137,7 +137,7 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN */ removeChild: function(node) { if (TreeApi.Logical.getParentNode(node) !== this.node) { - throw Error('The node to be removed is not a child of this node: ' + + throw Error('The node to be removed is not a child of this node: ' + node); } if (!this._removeNode(node)) { @@ -154,7 +154,7 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN return node; }, - // Try to remove node: update logical info and perform distribution iff + // Try to remove node: update logical info and perform distribution iff // needed. Return true if the removal has been handled. // note that it's possible for both the node's host and its parent // to require distribution... both cases are handled here. @@ -214,7 +214,7 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN } // memo-ize result for performance but only memo-ize a false-y // result if node is in the document. This avoids a problem where a root - // can be cached while an element is inside a fragment. + // can be cached while an element is inside a fragment. // If this happens and we cache the result, the value can become stale // because for perf we avoid processing the subtree of added fragments. if (root || document.documentElement.contains(node)) { @@ -298,7 +298,7 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN }, _nodeNeedsDistribution: function(node) { - return node && node.shadyRoot && + return node && node.shadyRoot && DomApi.hasInsertionPoint(node.shadyRoot); }, @@ -587,7 +587,7 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN return this.node.textContent; } else { var tc = []; - for (var i = 0, cn = this.childNodes, c; c = cn[i]; i++) { + for (var i = 0, cn = this.childNodes, c; (c = cn[i]); i++) { if (c.nodeType !== Node.COMMENT_NODE) { tc.push(c.textContent); } diff --git a/src/lib/dom-innerHTML.html b/src/lib/dom-innerHTML.html index 755eb4a3..09c8f3b9 100644 --- a/src/lib/dom-innerHTML.html +++ b/src/lib/dom-innerHTML.html @@ -1,131 +1,131 @@ - - + + diff --git a/src/lib/dom-module.html b/src/lib/dom-module.html index f1f9355a..468e55bf 100644 --- a/src/lib/dom-module.html +++ b/src/lib/dom-module.html @@ -45,7 +45,7 @@ * @param {String} id The id at which to register the dom-module. */ register: function(id) { - var id = id || this.id || + id = id || this.id || this.getAttribute('name') || this.getAttribute('is'); if (id) { this.id = id; @@ -103,7 +103,7 @@ var doc = script && script.ownerDocument || document; // find all dom-modules var modules = doc.querySelectorAll('dom-module'); - // minimize work by going backwards and stopping if we find an + // minimize work by going backwards and stopping if we find an // upgraded module. for (var i= modules.length-1, m; (i >=0) && (m=modules[i]); i--) { if (m.__upgraded__) { diff --git a/src/lib/dom-tree-api.html b/src/lib/dom-tree-api.html index 3fb61da7..ccf0dea0 100644 --- a/src/lib/dom-tree-api.html +++ b/src/lib/dom-tree-api.html @@ -11,20 +11,20 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN \ No newline at end of file + diff --git a/src/lib/style-defaults.html b/src/lib/style-defaults.html index 1ffedc18..c015da74 100644 --- a/src/lib/style-defaults.html +++ b/src/lib/style-defaults.html @@ -1,91 +1,90 @@ - - - - + + + + diff --git a/src/lib/style-extends.html b/src/lib/style-extends.html index 414f1ba2..97d71abc 100644 --- a/src/lib/style-extends.html +++ b/src/lib/style-extends.html @@ -1,101 +1,101 @@ - - - - + + + + diff --git a/src/lib/style-properties.html b/src/lib/style-properties.html index 544a0be9..74436cdc 100644 --- a/src/lib/style-properties.html +++ b/src/lib/style-properties.html @@ -71,7 +71,7 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN var m, rx = this.rx.VAR_ASSIGN; var cssText = rule.parsedCssText; var any; - while (m = rx.exec(cssText)) { + while ((m = rx.exec(cssText))) { // note: group 2 is var, 3 is mixin properties[m[1]] = (m[2] || m[3]).trim(); any = true; @@ -103,7 +103,7 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN collectPropertiesInCssText: function(cssText, props) { var m; - while (m = this.rx.VAR_CAPTURE.exec(cssText)) { + while ((m = this.rx.VAR_CAPTURE.exec(cssText))) { props[m[1]] = true; var def = m[2]; if (def && def.match(this.rx.IS_VAR)) { @@ -155,7 +155,7 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN valueForProperties: function(property, props) { var parts = property.split(';'); for (var i=0, p, m; i=0 ; i--) { + for (i=removedIdxs.length-1; i>=0 ; i--) { var idx = removedIdxs[i]; // Removed idx may be undefined if item was previously filtered out if (idx !== undefined) { @@ -583,7 +582,7 @@ Then the `observe` property should be configured as follows: }); // Insertion-sort new instances into place (from pool or newly created) var start = 0; - for (var i=0; i diff --git a/src/micro/properties.html b/src/micro/properties.html index 60257e2c..bd3b928d 100644 --- a/src/micro/properties.html +++ b/src/micro/properties.html @@ -116,7 +116,7 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN if (info) { return info; } - }; + } } return info || Polymer.nob; }, @@ -138,7 +138,7 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN // union properties, behaviors.properties, and propertyEffects _prepPropertyInfo: function() { this._propertyInfo = {}; - for (var i=0, p; i < this.behaviors.length; i++) { + for (var i=0; i < this.behaviors.length; i++) { this._addPropertyInfo(this._propertyInfo, this.behaviors[i].properties); } this._addPropertyInfo(this._propertyInfo, this.properties); @@ -174,7 +174,7 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN } } } - }, + } }); diff --git a/src/mini/shady.html b/src/mini/shady.html index c06bc2fd..9bc70164 100644 --- a/src/mini/shady.html +++ b/src/mini/shady.html @@ -77,12 +77,12 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN this.shadyRoot._isShadyRoot = true; this.shadyRoot._dirtyRoots = []; // capture insertion point list - var i$ = this.shadyRoot._insertionPoints = !this._notes || + var i$ = this.shadyRoot._insertionPoints = !this._notes || this._notes._hasContent ? this.shadyRoot.querySelectorAll('content') : []; // save logical tree info - // a. for shadyRoot - // b. for insertion points (fallback) + // a. for shadyRoot + // b. for insertion points (fallback) // c. for parents of insertion points TreeApi.Logical.saveChildNodes(this.shadyRoot); for (var i=0, c; i < i$.length; i++) { @@ -119,7 +119,7 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN */ distributeContent: function(updateInsertionPoints) { if (this.shadyRoot) { - this.shadyRoot._invalidInsertionPoints = + this.shadyRoot._invalidInsertionPoints = this.shadyRoot._invalidInsertionPoints || updateInsertionPoints; // Distribute the host that's the top of this element's distribution // tree. Distributing that host will *always* distibute this element. @@ -164,7 +164,7 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN // compose self if (this._useContent) { // note: it's important to mark this clean before distribution - // so that attachment that provokes additional distribution (e.g. + // so that attachment that provokes additional distribution (e.g. // adding something to your parentNode) works this.shadyRoot._distributionClean = true; if (DomApi.hasInsertionPoint(this.shadyRoot)) { @@ -331,7 +331,7 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN for (var i=0, d=0, s; (i - - + + + diff --git a/src/standard/utils.html b/src/standard/utils.html index 8f8f5fe9..f223b558 100644 --- a/src/standard/utils.html +++ b/src/standard/utils.html @@ -144,7 +144,7 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN getEffectiveTextContent: function() { var cn = this.getEffectiveChildNodes(); var tc = []; - for (var i=0, c; c = cn[i]; i++) { + for (var i=0, c; (c = cn[i]); i++) { if (c.nodeType !== Node.COMMENT_NODE) { tc.push(Polymer.dom(c).textContent); } @@ -215,7 +215,7 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN fire: function(type, detail, options) { options = options || Polymer.nob; var node = options.node || this; - var detail = (detail === null || detail === undefined) ? {} : detail; + detail = (detail === null || detail === undefined) ? {} : detail; var bubbles = options.bubbles === undefined ? true : options.bubbles; var cancelable = Boolean(options.cancelable); var useCache = options._useCache; diff --git a/src/standard/x-styling.html b/src/standard/x-styling.html index 8e0ef8ba..e50ff857 100644 --- a/src/standard/x-styling.html +++ b/src/standard/x-styling.html @@ -19,7 +19,6 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN var propertyUtils = Polymer.StyleProperties; var styleTransformer = Polymer.StyleTransformer; - var styleUtil = Polymer.StyleUtil; var styleDefaults = Polymer.StyleDefaults; var nativeShadow = Polymer.Settings.useNativeShadow; @@ -77,7 +76,7 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN _findStyleHost: function() { var e = this, root; - while (root = Polymer.dom(e).getOwnerRoot()) { + while ((root = Polymer.dom(e).getOwnerRoot())) { if (Polymer.isInstance(root.host)) { return root.host; } From cd4259551d656c9bfc91a62cd45b14261c813b20 Mon Sep 17 00:00:00 2001 From: Daniel Freedman Date: Mon, 8 Feb 2016 16:39:35 -0800 Subject: [PATCH 5/5] Rename _mapRule to _mapRuleOntoParent Makes the function name much more explicit about its purpose --- src/lib/style-extends.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib/style-extends.html b/src/lib/style-extends.html index 97d71abc..3b3896db 100644 --- a/src/lib/style-extends.html +++ b/src/lib/style-extends.html @@ -25,7 +25,7 @@ Polymer.StyleExtends = (function() { var rules = styleUtil.rulesForStyle(style); var self = this; styleUtil.forEachRule(rules, function(rule) { - self._mapRule(rule); + self._mapRuleOntoParent(rule); if (rule.parent) { var m; while ((m = self.rx.EXTEND.exec(rule.cssText))) { @@ -46,7 +46,7 @@ Polymer.StyleExtends = (function() { }, true); }, - _mapRule: function(rule) { + _mapRuleOntoParent: function(rule) { if (rule.parent) { var map = rule.parent.map || (rule.parent.map = {}); var parts = rule.selector.split(',');