#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": {
"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",

View File

@ -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,

View File

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

View File

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

View File

@ -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';

View File

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

View File

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