#85: fix linting errors and setup eslint to support source related test files

This commit is contained in:
SleepWalker 2017-06-07 21:40:44 +03:00
parent 6ead1bd01f
commit 7bc087d456
8 changed files with 48 additions and 31 deletions

View File

@ -29,11 +29,16 @@
}, },
"env": { "env": {
"mocha": true, // needed for tests. Apply it globaly till eslint/selint#3611
"browser": true, "browser": true,
"commonjs": true, "commonjs": true,
"es6": true "es6": true
}, },
"globals": {
"sinon": false // needed for tests. Apply it globaly till eslint/selint#3611
},
"extends": "eslint:recommended", "extends": "eslint:recommended",
// @see: http://eslint.org/docs/rules/ // @see: http://eslint.org/docs/rules/
@ -180,7 +185,7 @@
"object-shorthand": "warn", "object-shorthand": "warn",
"prefer-arrow-callback": "warn", "prefer-arrow-callback": "warn",
"prefer-const": "warn", "prefer-const": "warn",
"prefer-reflect": "warn", "prefer-reflect": ["warn", {"exceptions": ["delete"]}],
"prefer-spread": "warn", "prefer-spread": "warn",
"prefer-template": "warn", "prefer-template": "warn",
"require-yield": "error", "require-yield": "error",
@ -189,7 +194,7 @@
"react/display-name": "warn", "react/display-name": "warn",
"react/forbid-prop-types": "warn", "react/forbid-prop-types": "warn",
"react/jsx-boolean-value": "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-curly-spacing": "warn",
"react/jsx-handler-names": ["warn", {"eventHandlerPrefix": "on", "eventHandlerPropPrefix": "on"}], "react/jsx-handler-names": ["warn", {"eventHandlerPrefix": "on", "eventHandlerPropPrefix": "on"}],
"react/jsx-indent-props": "warn", "react/jsx-indent-props": "warn",

View File

@ -5,6 +5,7 @@ import { browserHistory } from 'services/history';
import logger from 'services/logger'; import logger from 'services/logger';
import { InternalServerError } from 'services/request'; import { InternalServerError } from 'services/request';
import { sessionStorage } from 'services/localStorage';
import authentication from 'services/api/authentication'; import authentication from 'services/api/authentication';
import { import {
authenticate, authenticate,

View File

@ -1,3 +1,4 @@
/* eslint camelcase: off */
import request from 'services/request'; import request from 'services/request';
export default { export default {

View File

@ -1,5 +1,3 @@
import sinon from 'sinon';
import AcceptRulesState from 'services/authFlow/AcceptRulesState'; import AcceptRulesState from 'services/authFlow/AcceptRulesState';
import CompleteState from 'services/authFlow/CompleteState'; import CompleteState from 'services/authFlow/CompleteState';

View File

@ -3,6 +3,7 @@ import sinon from 'sinon';
import AuthFlow from 'services/authFlow/AuthFlow'; import AuthFlow from 'services/authFlow/AuthFlow';
import AbstractState from 'services/authFlow/AbstractState'; import AbstractState from 'services/authFlow/AbstractState';
import localStorage from 'services/localStorage';
import OAuthState from 'services/authFlow/OAuthState'; import OAuthState from 'services/authFlow/OAuthState';
import RegisterState from 'services/authFlow/RegisterState'; import RegisterState from 'services/authFlow/RegisterState';

View File

@ -1,3 +1,4 @@
/* eslint camelcase: off */
import sinon from 'sinon'; import sinon from 'sinon';
import OAuthState from 'services/authFlow/OAuthState'; import OAuthState from 'services/authFlow/OAuthState';

View File

@ -69,10 +69,12 @@ const errorsMap = {
'error.account_not_activated': () => <Message {...messages.accountNotActivated} />, 'error.account_not_activated': () => <Message {...messages.accountNotActivated} />,
'error.account_banned': () => <Message {...messages.accountBanned} />, 'error.account_banned': () => <Message {...messages.accountBanned} />,
'error.recently_sent_message': (props) => <Message {...messages.emailFrequency} values={{ 'error.recently_sent_message': (props) => (
<Message {...messages.emailFrequency} values={{
// for msLeft @see AuthError.jsx // for msLeft @see AuthError.jsx
time: <Relative value={props.msLeft} updateInterval={1000} /> time: <Relative value={props.msLeft} updateInterval={1000} />
}} />, }} />
),
'error.email_not_found': () => <Message {...messages.emailNotFound} />, 'error.email_not_found': () => <Message {...messages.emailNotFound} />,
'error.account_already_activated': () => <Message {...messages.accountAlreadyActivated} />, 'error.account_already_activated': () => <Message {...messages.accountAlreadyActivated} />,

View File

@ -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(). * 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) * that it won't exceed the limit)
* *
* @see https://github.com/ftlabs/js-abbreviate * @see https://github.com/ftlabs/js-abbreviate
*
* @return {object}
*/ */
function abbreviate(obj, options = {}) { function abbreviate(obj, options = {}) {
var filter = options.filter || function(key, value) {return value;}; const filter = options.filter || function(key, value) {return value;};
var maxDepth = options.depth || 10; const maxDepth = options.depth || 10;
var maxSize = options.maxSize || 1 * 1024 * 1024; const maxSize = options.maxSize || 1 * 1024 * 1024;
return abbreviateRecursive(undefined, obj, filter, {sizeLeft: maxSize}, maxDepth); return abbreviateRecursive(undefined, obj, filter, {sizeLeft: maxSize}, maxDepth);
} }
function limitStringLength(str) { function limitStringLength(str) {
if (str.length > STRING_MAX_LENGTH) { 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; return str;
} }
@ -40,8 +43,8 @@ function abbreviateRecursive(key, obj, filter, state, maxDepth) {
try { try {
switch (typeof obj) { switch (typeof obj) {
case 'object': case 'object': {
if (null === obj) { if (obj === null) {
return null; return null;
} }
@ -49,14 +52,18 @@ function abbreviateRecursive(key, obj, filter, state, maxDepth) {
break; // fall back to stringification break; // fall back to stringification
} }
var newobj = Array.isArray(obj) ? [] : {}; const newobj = Array.isArray(obj) ? [] : {};
for (var i in obj) {
newobj[i] = abbreviateRecursive(i, obj[i], filter, state, maxDepth-1); for (const i in obj) {
newobj[i] = abbreviateRecursive(i, obj[i], filter, state, maxDepth - 1);
if (state.sizeLeft < 0) { if (state.sizeLeft < 0) {
break; break;
} }
} }
return newobj; return newobj;
}
case 'string': case 'string':
obj = limitStringLength(obj); obj = limitStringLength(obj);
@ -66,12 +73,13 @@ function abbreviateRecursive(key, obj, filter, state, maxDepth) {
case 'number': case 'number':
case 'boolean': case 'boolean':
case 'undefined': case 'undefined':
default:
return obj; return obj;
} }
} catch (err) {/* 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 (err) { } catch (err) {
@ -85,7 +93,7 @@ function commonFilter(key, val) {
} }
if (val instanceof Date) { if (val instanceof Date) {
return '**Date** ' + val; return `**Date** ${val}`;
} }
if (val instanceof Error) { if (val instanceof Error) {
@ -96,7 +104,7 @@ function commonFilter(key, val) {
name: val.name, name: val.name,
}; };
for (let i in val) { for (const i in val) {
err[i] = val[i]; err[i] = val[i];
} }
@ -107,17 +115,16 @@ function commonFilter(key, val) {
} }
function nodeFilter(key, val) { function nodeFilter(key, val) {
// domain objects are huge and have circular references // domain objects are huge and have circular references
if (key === 'domain' && 'object' === typeof val && val._events) { if (key === 'domain' && typeof val === 'object' && val._events) {
return "**domain ignored**"; return '**domain ignored**';
} }
if (key === 'domainEmitter') { if (key === 'domainEmitter') {
return "**domainEmitter ignored**"; return '**domainEmitter ignored**';
} }
if (val === global) { if (val === global) {
return "**global**"; return '**global**';
} }
return commonFilter(key, val); return commonFilter(key, val);
@ -125,17 +132,18 @@ function nodeFilter(key, val) {
function browserFilter(key, val) { function browserFilter(key, val) {
if (val === window) { if (val === window) {
return "**window**"; return '**window**';
} }
if (val === document) { if (val === document) {
return "**document**"; return '**document**';
} }
if (val instanceof HTMLElement) { if (val instanceof HTMLElement) {
var outerHTML = val.outerHTML; const outerHTML = val.outerHTML;
if ('undefined' != typeof outerHTML) {
return "**HTMLElement** " + outerHTML; if (typeof outerHTML != 'undefined') {
return `**HTMLElement** ${outerHTML}`;
} }
} }