diff --git a/.codeclimate.yml b/.codeclimate.yml index d1e464f..debdf0b 100644 --- a/.codeclimate.yml +++ b/.codeclimate.yml @@ -2,33 +2,23 @@ version: "2" checks: argument-count: - enabled: true - config: - threshold: 4 + enabled: false # handled by eslint rule "max-params" complex-logic: enabled: true config: threshold: 4 file-lines: - enabled: true - config: - threshold: 250 + enabled: false # handled by eslint rule "max-lines" method-complexity: - enabled: true - config: - threshold: 5 + enabled: false # handled by eslint rule "complexity" method-count: enabled: true config: threshold: 20 method-lines: - enabled: true - config: - threshold: 30 + enabled: false # handled by eslint rule "max-lines-per-function" nested-control-flow: - enabled: true - config: - threshold: 4 + enabled: false # handled by eslint rule "max-depth" return-statements: enabled: true config: @@ -41,7 +31,7 @@ checks: plugins: eslint: enabled: true - channel: "eslint-4" + channel: "eslint-5" config: sanitize_batch: false extensions: @@ -49,3 +39,9 @@ plugins: - .html fixme: enabled: true + +exclude_patterns: + - "bower_components/" + - "node_modules/" + - "demo/" + - "test/" \ No newline at end of file diff --git a/.eslintrc.json b/.eslintrc.json index f54a37f..51cc756 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,133 +1,298 @@ { - "env": { - "browser": true, - "es6": true - }, - "extends": "eslint:recommended", - "globals": { - "Cosmoz": false, - "CustomElements": false, - "HTMLImports": false, - "Polymer": false, - "WeakMap": false - }, - "plugins": [ - "html" - ], - "rules": { - "accessor-pairs": "warn", - "array-bracket-spacing": [ - "error", - "never" - ], - "arrow-parens": [ - "error", - "as-needed" - ], - "arrow-spacing": [ - "error", - { - "before": true, - "after": true - } - ], - "brace-style": "error", - "camelcase": "error", - "comma-spacing": [ - "error", - { - "after": true - } - ], - "comma-style": [ - "error", - "last" - ], - "curly": [ - "error", - "all" - ], - "eqeqeq": [ - "error", - "smart" - ], - "guard-for-in": "error", - "indent": [ - "error", - "tab" - ], - "key-spacing": [ - "error", - { - "afterColon": true, - "beforeColon": false - } - ], - "keyword-spacing": [ - "error", - { - "before": true - } - ], - "no-console": "off", - "no-else-return": "error", - "no-empty": "error", - "no-empty-function": "error", - "no-eval": "error", - "no-extra-bind": "error", - "no-extra-parens": "error", - "no-invalid-this": "error", - "no-labels": "error", - "no-lone-blocks": "error", - "no-lonely-if": "error", - "no-loop-func": "error", - "no-new": "error", - "no-param-reassign": "error", - "no-self-compare": "error", - "no-trailing-spaces": "error", - "no-unused-expressions": "error", - "no-unused-vars": "warn", - "no-use-before-define": "error", - "no-useless-call": "error", - "no-useless-concat": "error", - "object-shorthand": [ - "error", - "always" - ], - "one-var": [ - "error", - { - "var": "always", - "let": "always" - } - ], - "one-var-declaration-per-line": [ - "error", - "always" - ], - "prefer-arrow-callback": "error", - "quotes": [ - "error", - "single" - ], - "radix": "error", - "semi": [ - "error", - "always" - ], - "space-before-blocks": [ - "error", - "always" - ], - "space-before-function-paren": [ - "error", - { - "anonymous": "always", - "named": "never" - } - ], - "space-in-parens": "error", - "space-infix-ops": "error", - "valid-jsdoc": "warn" - } + "env": { + "browser": true, + "es6": true + }, + "extends": "eslint:recommended", + "globals": { + "Cosmoz": false, + "CustomElements": false, + "HTMLImports": false, + "Polymer": false, + "WeakMap": false + }, + "plugins": [ + "html" + ], + "rules": { + "accessor-pairs": "warn", + "array-bracket-newline": [ + "error", + "consistent" + ], + "array-bracket-spacing": [ + "error", + "never" + ], + "array-element-newline": [ + "error", + "consistent" + ], + "array-callback-return": "warn", + "arrow-parens": [ + "error", + "as-needed" + ], + "arrow-spacing": [ + "error", + { + "before": true, + "after": true + } + ], + "block-scoped-var": "error", + "block-spacing": "error", + "brace-style": "error", + "camelcase": "error", + "comma-dangle": [ + "error", + "never" + ], + "comma-spacing": [ + "error", + { + "after": true, + "before": false + } + ], + "comma-style": [ + "error", + "last" + ], + "complexity": [ + "warn", + 20 + ], + "computed-property-spacing": [ + "error", + "never" + ], + "consistent-this": [ + "error", + "that" + ], + "constructor-super": "error", + "curly": [ + "error", + "all" + ], + "eol-last": [ + "error", + "always" + ], + "eqeqeq": [ + "error", + "smart" + ], + "func-call-spacing": [ + "error", + "never" + ], + "func-name-matching": [ + "error", + "always" + ], + "func-names": [ + "error", + "never" + ], + "func-style": [ + "error", + "expression" + ], + "guard-for-in": "error", + "indent": [ + "error", + "tab" + ], + "key-spacing": [ + "error", + { + "afterColon": true, + "beforeColon": false, + "mode": "strict" + } + ], + "keyword-spacing": [ + "error", + { + "after": true, + "before": true + } + ], + "max-depth": [ + "error", + 4 + ], + "max-len": [ + "warn", + { + "code": 160, + "tabWidth": 4 + } + ], + "max-lines": [ + "warn", + 350 + ], + "max-lines-per-function": [ + "warn", + { + "max": 50, + "IIFEs": false, + "skipComments": true + } + ], + "max-nested-callbacks": [ + "error", + 5 + ], + "max-params": [ + "error", + 5 + ], + "max-statements": [ + "warn", + 15 + ], + "max-statements-per-line": [ + "error", + { + "max": 1 + } + ], + "multiline-ternary": [ + "error", + "always-multiline" + ], + "new-cap": [ + "warn", + { + "capIsNew": true, + "newIsCap": true + } + ], + "new-parens": "error", + "newline-per-chained-call": [ + "error", + { + "ignoreChainWithDepth": 3 + } + ], + "no-alert": "error", + "no-bitwise": "warn", + "no-console": "off", + "no-const-assign": "error", + "no-dupe-class-members": "error", + "no-duplicate-imports": "error", + "no-else-return": "error", + "no-empty": "error", + "no-empty-function": "error", + "no-eval": "error", + "no-extra-bind": "error", + "no-extra-parens": "error", + "no-global-assign": "error", + "no-implicit-globals": "error", + "no-invalid-this": "error", + "no-labels": "error", + "no-lone-blocks": "error", + "no-lonely-if": "error", + "no-loop-func": "error", + "no-multi-spaces": "error", + "no-new": "error", + "no-new-func": "error", + "no-nested-ternary": "error", + "no-param-reassign": "error", + "no-redeclare": "error", + "no-return-assign": "error", + "no-self-compare": "error", + "no-sequences": "error", + "no-template-curly-in-string": "error", + "no-this-before-super": "error", + "no-throw-literal": "error", + "no-trailing-spaces": "error", + "no-undef-init": "error", + "no-unmodified-loop-condition": "error", + "no-unneeded-ternary": "error", + "no-unused-expressions": "error", + "no-unused-vars": "error", + "no-use-before-define": "error", + "no-useless-call": "error", + "no-useless-catch": "error", + "no-useless-computed-key": "error", + "no-useless-concat": "error", + "no-useless-return": "error", + "no-var": "error", + "no-void": "error", + "no-whitespace-before-property": "error", + "no-with": "error", + "object-curly-newline": [ + "error", + { + "consistent": true + } + ], + "object-property-newline": [ + "error", + { + "allowAllPropertiesOnSameLine": true + } + ], + "object-shorthand": [ + "error", + "always" + ], + "one-var": [ + "error", + { + "var": "always", + "let": "always" + } + ], + "one-var-declaration-per-line": [ + "error", + "always" + ], + "prefer-arrow-callback": "error", + "prefer-const": "warn", + "quotes": [ + "error", + "single" + ], + "radix": "error", + "require-unicode-regexp": "error", + "semi": [ + "error", + "always" + ], + "semi-spacing": [ + "error", + { + "before": false, + "after": true + } + ], + "semi-style": [ + "error", + "last" + ], + "space-before-blocks": [ + "error", + "always" + ], + "space-before-function-paren": [ + "error", + { + "anonymous": "always", + "asyncArrow": "always", + "named": "never" + } + ], + "space-in-parens": "error", + "space-infix-ops": "error", + "space-unary-ops": "error", + "strict": "error", + "switch-colon-spacing": "error", + "valid-jsdoc": "warn" + } } \ No newline at end of file diff --git a/cosmoz-data-nav.js b/cosmoz-data-nav.js index 0404ebb..ae99093 100644 --- a/cosmoz-data-nav.js +++ b/cosmoz-data-nav.js @@ -38,7 +38,7 @@ return 'cosmoz-data-nav'; } - static get properties() { + static get properties() { // eslint-disable-line max-lines-per-function return { /** * The array of buffer elements. @@ -182,7 +182,7 @@ animating: { type: Boolean, value: false, - reflectToAttribute: true, + reflectToAttribute: true }, /** @@ -191,7 +191,7 @@ reverse: { type: Boolean, value: false, - reflectToAttribute: true, + reflectToAttribute: true }, /** @@ -327,7 +327,7 @@ this._incompleteCtor = Templatize.templatize(this._incompleteTemplate, this, { instanceProps: baseProps, parentModel: true, - forwardHostProp: this._forwardHostProp, + forwardHostProp: this._forwardHostProp }); } @@ -484,7 +484,11 @@ this._realignElements(index); } // update selected or force re-render if selected did not change - return this.selected === index ? this._updateSelected() : this.selected = index; + if (this.selected === index) { + return this._updateSelected(); + } + this.selected = index; + return index; } _realignElements(index) { @@ -708,7 +712,10 @@ const start = min(max(selected - offset, 0), length ? length - buffer : 0), end = max(min(selected + offset, length ? length - 1 : 0), buffer - 1), - indexes = Array(end + 1).fill().map((u, i) => i).slice(start >= 0 ? start : 0); + indexes = Array(end + 1) + .fill() + .map((u, i) => i) + .slice(start >= 0 ? start : 0); // Reset items indexes.forEach(i => this._resetElement(i)); @@ -735,15 +742,14 @@ if (!selectEl) { return; } - let inBetween = path.slice(path.indexOf(selectEl)), - ancestorNav = inBetween.find(e => e && e.constructor && e.constructor.is === this.constructor.is), - select; + const inBetween = path.slice(path.indexOf(selectEl)), + ancestorNav = inBetween.find(e => e && e.constructor && e.constructor.is === this.constructor.is); if (ancestorNav !== this) { return; } - select = parseInt(selectEl.getAttribute(attr), 10); + const select = parseInt(selectEl.getAttribute(attr), 10); if (isNaN(select)) { return; @@ -854,15 +860,17 @@ return false; } - const resizable = this._interestedResizables - .find(resizable => this._isDescendantOfElementInstance(resizable, element)); + const resizable = this._interestedResizables.find(resizable => + this._isDescendantOfElementInstance(resizable, element) + ); - if (!resizable) { + if (resizable == null) { return false; } this._notifyDescendant(resizable); - return instance.__resized = true; + instance.__resized = true; + return true; } /** @@ -873,10 +881,8 @@ * @return {void} */ selectById(id) { - var index, - item; - for (index = 0; index < this.items.length; index++) { - item = this.items[index]; + for (let index = 0; index < this.items.length; index++) { + const item = this.items[index]; if (typeof item === 'object' && item.id === id || item === id) { this.selected = index; return; @@ -889,8 +895,8 @@ if (Polymer.flush) { Polymer.flush(); } - const props = Object.assign({ [this.as]: item }, this._getBaseProps(idx)); - const instance = new this._elementCtor(props); + const props = Object.assign({ [this.as]: item }, this._getBaseProps(idx)), + instance = new this._elementCtor(props); element.__instance = instance; element.item = item; @@ -919,7 +925,15 @@ this._renderRan = this._renderAbort = false; this._indexRenderQueue = queue - .sort((a, b) => a === this.selected ? -1 : b === this.selected ? 1 : 0) + .sort((a, b) => { + if (a === this.selected) { + return -1; + } + if (b === this.selected) { + return 1; + } + return 0; + }) .map(this._renderQueueProcess, this) .filter(idx => idx != null); diff --git a/demo/index.html b/demo/index.html index c3073ac..b08f4db 100644 --- a/demo/index.html +++ b/demo/index.html @@ -69,6 +69,7 @@
cosmoz-data-nav
.