diff --git a/.eslintrc.json b/.eslintrc.json index b6d1850..1646a0f 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -29,11 +29,16 @@ }, "env": { + "mocha": true, // needed for tests. Apply it globaly till eslint/selint#3611 "browser": true, "commonjs": true, "es6": true }, + "globals": { + "sinon": false // needed for tests. Apply it globaly till eslint/selint#3611 + }, + "extends": "eslint:recommended", // @see: http://eslint.org/docs/rules/ @@ -180,7 +185,7 @@ "object-shorthand": "warn", "prefer-arrow-callback": "warn", "prefer-const": "warn", - "prefer-reflect": "warn", + "prefer-reflect": ["warn", {"exceptions": ["delete"]}], "prefer-spread": "warn", "prefer-template": "warn", "require-yield": "error", @@ -189,7 +194,7 @@ "react/display-name": "warn", "react/forbid-prop-types": "warn", "react/jsx-boolean-value": "warn", - "react/jsx-closing-bracket-location": "warn", + "react/jsx-closing-bracket-location": "off", // can not configure for our code style "react/jsx-curly-spacing": "warn", "react/jsx-handler-names": ["warn", {"eventHandlerPrefix": "on", "eventHandlerPropPrefix": "on"}], "react/jsx-indent-props": "warn", diff --git a/src/components/accounts/actions.test.js b/src/components/accounts/actions.test.js index 270b814..c15b750 100644 --- a/src/components/accounts/actions.test.js +++ b/src/components/accounts/actions.test.js @@ -5,6 +5,7 @@ import { browserHistory } from 'services/history'; import logger from 'services/logger'; import { InternalServerError } from 'services/request'; +import { sessionStorage } from 'services/localStorage'; import authentication from 'services/api/authentication'; import { authenticate, diff --git a/src/services/api/oauth.js b/src/services/api/oauth.js index f374f00..77a59ef 100644 --- a/src/services/api/oauth.js +++ b/src/services/api/oauth.js @@ -1,3 +1,4 @@ +/* eslint camelcase: off */ import request from 'services/request'; export default { diff --git a/src/services/authFlow/AcceptRulesState.test.js b/src/services/authFlow/AcceptRulesState.test.js index d1c0c0f..d38badf 100644 --- a/src/services/authFlow/AcceptRulesState.test.js +++ b/src/services/authFlow/AcceptRulesState.test.js @@ -1,5 +1,3 @@ -import sinon from 'sinon'; - import AcceptRulesState from 'services/authFlow/AcceptRulesState'; import CompleteState from 'services/authFlow/CompleteState'; diff --git a/src/services/authFlow/AuthFlow.test.js b/src/services/authFlow/AuthFlow.test.js index 9b7db79..4883045 100644 --- a/src/services/authFlow/AuthFlow.test.js +++ b/src/services/authFlow/AuthFlow.test.js @@ -3,6 +3,7 @@ import sinon from 'sinon'; import AuthFlow from 'services/authFlow/AuthFlow'; import AbstractState from 'services/authFlow/AbstractState'; +import localStorage from 'services/localStorage'; import OAuthState from 'services/authFlow/OAuthState'; import RegisterState from 'services/authFlow/RegisterState'; diff --git a/src/services/authFlow/OAuthState.test.js b/src/services/authFlow/OAuthState.test.js index 3c0d12c..dfb846a 100644 --- a/src/services/authFlow/OAuthState.test.js +++ b/src/services/authFlow/OAuthState.test.js @@ -1,3 +1,4 @@ +/* eslint camelcase: off */ import sinon from 'sinon'; import OAuthState from 'services/authFlow/OAuthState'; diff --git a/src/services/errorsDict/errorsDict.js b/src/services/errorsDict/errorsDict.js index 162ca87..d3e74cc 100644 --- a/src/services/errorsDict/errorsDict.js +++ b/src/services/errorsDict/errorsDict.js @@ -69,10 +69,12 @@ const errorsMap = { 'error.account_not_activated': () => , 'error.account_banned': () => , - 'error.recently_sent_message': (props) => - }} />, + 'error.recently_sent_message': (props) => ( + + }} /> + ), 'error.email_not_found': () => , 'error.account_already_activated': () => , diff --git a/src/services/logger/abbreviate.js b/src/services/logger/abbreviate.js index 4cb70f1..82d5a55 100644 --- a/src/services/logger/abbreviate.js +++ b/src/services/logger/abbreviate.js @@ -1,4 +1,4 @@ -const STRING_MAX_LENGTH = 128*1024; +const STRING_MAX_LENGTH = 128 * 1024; /** * Create a copy of any object without non-serializable elements to make result safe for JSON.stringify(). @@ -13,19 +13,22 @@ const STRING_MAX_LENGTH = 128*1024; * that it won't exceed the limit) * * @see https://github.com/ftlabs/js-abbreviate + * + * @return {object} */ function abbreviate(obj, options = {}) { - var filter = options.filter || function(key, value) {return value;}; - var maxDepth = options.depth || 10; - var maxSize = options.maxSize || 1 * 1024 * 1024; + const filter = options.filter || function(key, value) {return value;}; + const maxDepth = options.depth || 10; + const maxSize = options.maxSize || 1 * 1024 * 1024; return abbreviateRecursive(undefined, obj, filter, {sizeLeft: maxSize}, maxDepth); } function limitStringLength(str) { if (str.length > STRING_MAX_LENGTH) { - return str.substring(0, STRING_MAX_LENGTH/2) + ' … ' + str.substring(str.length - STRING_MAX_LENGTH/2); + return `${str.substring(0, STRING_MAX_LENGTH / 2)} … ${str.substring(str.length - STRING_MAX_LENGTH / 2)}`; } + return str; } @@ -40,8 +43,8 @@ function abbreviateRecursive(key, obj, filter, state, maxDepth) { try { switch (typeof obj) { - case 'object': - if (null === obj) { + case 'object': { + if (obj === null) { return null; } @@ -49,14 +52,18 @@ function abbreviateRecursive(key, obj, filter, state, maxDepth) { break; // fall back to stringification } - var newobj = Array.isArray(obj) ? [] : {}; - for (var i in obj) { - newobj[i] = abbreviateRecursive(i, obj[i], filter, state, maxDepth-1); + const newobj = Array.isArray(obj) ? [] : {}; + + for (const i in obj) { + newobj[i] = abbreviateRecursive(i, obj[i], filter, state, maxDepth - 1); + if (state.sizeLeft < 0) { break; } } + return newobj; + } case 'string': obj = limitStringLength(obj); @@ -66,12 +73,13 @@ function abbreviateRecursive(key, obj, filter, state, maxDepth) { case 'number': case 'boolean': case 'undefined': + default: return obj; } } catch (err) {/* fall back to inspect*/} try { - obj = limitStringLength('' + obj); + obj = limitStringLength(`${obj}`); state.sizeLeft -= obj.length; return obj; } catch (err) { @@ -85,7 +93,7 @@ function commonFilter(key, val) { } if (val instanceof Date) { - return '**Date** ' + val; + return `**Date** ${val}`; } if (val instanceof Error) { @@ -96,7 +104,7 @@ function commonFilter(key, val) { name: val.name, }; - for (let i in val) { + for (const i in val) { err[i] = val[i]; } @@ -107,17 +115,16 @@ function commonFilter(key, val) { } function nodeFilter(key, val) { - // domain objects are huge and have circular references - if (key === 'domain' && 'object' === typeof val && val._events) { - return "**domain ignored**"; + if (key === 'domain' && typeof val === 'object' && val._events) { + return '**domain ignored**'; } if (key === 'domainEmitter') { - return "**domainEmitter ignored**"; + return '**domainEmitter ignored**'; } if (val === global) { - return "**global**"; + return '**global**'; } return commonFilter(key, val); @@ -125,17 +132,18 @@ function nodeFilter(key, val) { function browserFilter(key, val) { if (val === window) { - return "**window**"; + return '**window**'; } if (val === document) { - return "**document**"; + return '**document**'; } if (val instanceof HTMLElement) { - var outerHTML = val.outerHTML; - if ('undefined' != typeof outerHTML) { - return "**HTMLElement** " + outerHTML; + const outerHTML = val.outerHTML; + + if (typeof outerHTML != 'undefined') { + return `**HTMLElement** ${outerHTML}`; } }