Fix linting errors

This commit is contained in:
SleepWalker 2017-04-11 22:25:27 +03:00
parent dcf95410d7
commit 80ca37da2b
3 changed files with 22 additions and 19 deletions

View File

@ -57,7 +57,7 @@
// best practice // best practice
"block-scoped-var": "error", "block-scoped-var": "error",
"curly": "error", "curly": "error",
"default-case": "error", "default-case": "warn",
"dot-location": ["error", "property"], "dot-location": ["error", "property"],
"dot-notation": "error", "dot-notation": "error",
"eqeqeq": ["error", "smart"], "eqeqeq": ["error", "smart"],
@ -162,7 +162,7 @@
"space-before-blocks": "error", "space-before-blocks": "error",
"space-before-function-paren": ["error", "never"], "space-before-function-paren": ["error", "never"],
"space-in-parens": "warn", "space-in-parens": "warn",
"space-infix-ops": "error", "space-infix-ops": "warn",
"space-unary-ops": "error", "space-unary-ops": "error",
"spaced-comment": "warn", "spaced-comment": "warn",

View File

@ -1,5 +1,6 @@
import { routeActions } from 'react-router-redux'; import { routeActions } from 'react-router-redux';
import { sessionStorage } from 'services/localStorage';
import authentication from 'services/api/authentication'; import authentication from 'services/api/authentication';
import { updateUser, setGuest } from 'components/user/actions'; import { updateUser, setGuest } from 'components/user/actions';
import { setLocale } from 'components/i18n/actions'; import { setLocale } from 'components/i18n/actions';

View File

@ -14,12 +14,10 @@ const STRING_MAX_LENGTH = 128*1024;
* *
* @see https://github.com/ftlabs/js-abbreviate * @see https://github.com/ftlabs/js-abbreviate
*/ */
function abbreviate(obj, options) { function abbreviate(obj, options = {}) {
if (!options) options = {}; var filter = options.filter || function(key, value) {return value;};
var filter = options.filter || function(k,v){return v;};
var maxDepth = options.depth || 10; var maxDepth = options.depth || 10;
var maxSize = options.maxSize || 1*1024*1024; var maxSize = options.maxSize || 1 * 1024 * 1024;
return abbreviateRecursive(undefined, obj, filter, {sizeLeft: maxSize}, maxDepth); return abbreviateRecursive(undefined, obj, filter, {sizeLeft: maxSize}, maxDepth);
} }
@ -41,7 +39,7 @@ function abbreviateRecursive(key, obj, filter, state, maxDepth) {
obj = filter(key, obj); obj = filter(key, obj);
try { try {
switch(typeof obj) { switch (typeof obj) {
case 'object': case 'object':
if (null === obj) { if (null === obj) {
return null; return null;
@ -52,9 +50,11 @@ function abbreviateRecursive(key, obj, filter, state, maxDepth) {
} }
var newobj = Array.isArray(obj) ? [] : {}; var newobj = Array.isArray(obj) ? [] : {};
for(var i in obj) { for (var i in obj) {
newobj[i] = abbreviateRecursive(i, obj[i], filter, state, maxDepth-1); newobj[i] = abbreviateRecursive(i, obj[i], filter, state, maxDepth-1);
if (state.sizeLeft < 0) break; if (state.sizeLeft < 0) {
break;
}
} }
return newobj; return newobj;
@ -68,36 +68,38 @@ function abbreviateRecursive(key, obj, filter, state, maxDepth) {
case 'undefined': case 'undefined':
return obj; return obj;
} }
} catch(e) {/* fall back to inspect*/} } catch (err) {/* fall back to inspect*/}
try { try {
obj = limitStringLength('' + obj); obj = limitStringLength('' + obj);
state.sizeLeft -= obj.length; state.sizeLeft -= obj.length;
return obj; return obj;
} catch(e) { } catch (err) {
return "**non-serializable**"; return '**non-serializable**';
} }
} }
function commonFilter(key, val) { function commonFilter(key, val) {
if ('function' === typeof val) { if (typeof val === 'function') {
return undefined; return undefined;
} }
if (val instanceof Date) { if (val instanceof Date) {
return "**Date** " + val; return '**Date** ' + val;
} }
if (val instanceof Error) { if (val instanceof Error) {
var err = { const err = {
// These properties are implemented as magical getters and don't show up in for in // These properties are implemented as magical getters and don't show up in for in
stack: val.stack, stack: val.stack,
message: val.message, message: val.message,
name: val.name, name: val.name,
}; };
for(var i in val) {
for (let i in val) {
err[i] = val[i]; err[i] = val[i];
} }
return err; return err;
} }
@ -150,5 +152,5 @@ export {
export default function(obj) { export default function(obj) {
return abbreviate(obj, { return abbreviate(obj, {
filter: browserFilter filter: browserFilter
}) });
}; }