Add more strict rules (eslint)

This commit is contained in:
RainLoop Team 2016-07-02 01:49:59 +03:00
parent b43bb17cdb
commit 52e2698cdf
38 changed files with 488 additions and 434 deletions

View file

@ -1,5 +1,6 @@
import {window, $} from 'common';
import window from 'window';
import $ from '$';
import {bMobileDevice, bSafari} from 'Common/Globals';
import * as Links from 'Common/Links';
import * as Events from 'Common/Events';

View file

@ -1,6 +1,7 @@
import window from 'window';
import progressJs from 'progressJs';
import Promise from 'Promise';
import STYLES_CSS from 'Styles/@Boot.css';
import LAYOUT_HTML from 'Html/Layout.html';
@ -32,7 +33,7 @@ function getComputedStyle(id, name)
*/
function includeStyle(styles)
{
window.document.write(unescape('%3Csty' + 'le%3E' + styles + '"%3E%3C/' + 'sty' + 'le%3E'));
window.document.write(unescape('%3Csty' + 'le%3E' + styles + '"%3E%3C/' + 'sty' + 'le%3E')); // eslint-disable-line no-useless-concat
}
/**
@ -41,7 +42,7 @@ function includeStyle(styles)
*/
function includeScr(src)
{
window.document.write(unescape('%3Csc' + 'ript type="text/jav' + 'ascr' + 'ipt" data-cfasync="false" sr' + 'c="' + src + '"%3E%3C/' + 'scr' + 'ipt%3E'));
window.document.write(unescape('%3Csc' + 'ript type="text/jav' + 'ascr' + 'ipt" data-cfasync="false" sr' + 'c="' + src + '"%3E%3C/' + 'scr' + 'ipt%3E')); // eslint-disable-line no-useless-concat
}
/**
@ -203,27 +204,30 @@ function runApp()
}
}
}),
common = window.Promise.all([
common = Promise.all([
window.jassl(appData.TemplatesLink),
window.jassl(appData.LangLink)
]);
window.Promise.all([libs, common])
Promise.all([libs, common])
.then(() => {
p.set(30);
return window.jassl(appData.StaticAppJsLink);
}).then(() => {
})
.then(() => {
p.set(50);
return appData.PluginsLink ? window.jassl(appData.PluginsLink) : window.Promise.resolve();
}).then(() => {
})
.then(() => {
p.set(70);
runMainBoot(false);
}).catch((e) => {
})
.catch((e) => {
runMainBoot(true);
throw e;
}).then(() => {
return window.jassl(appData.StaticEditorJsLink);
}).then(() => {
})
.then(() => window.jassl(appData.StaticEditorJsLink))
.then(() => {
if (window.CKEDITOR && window.__initEditor) {
window.__initEditor();
window.__initEditor = null;

View file

@ -1,5 +1,5 @@
import {_} from 'common';
import _ from '_';
import {Capa, MessageSetAction} from 'Common/Enums';
import {trim, pInt, isArray} from 'Common/Utils';
import * as Links from 'Common/Links';

View file

@ -1,5 +1,7 @@
import {window, JSON, $} from 'common';
import window from 'window';
import $ from '$';
import JSON from 'JSON';
import {isUnd} from 'Common/Utils';
import {CLIENT_SIDE_STORAGE_INDEX_NAME} from 'Common/Consts';
@ -21,7 +23,7 @@ class CookieDriver
const storageValue = $.cookie(CLIENT_SIDE_STORAGE_INDEX_NAME);
storageResult = null === storageValue ? null : JSON.parse(storageValue);
}
catch (e) {/* eslint-disable-line no-empty */}
catch (e) {} // eslint-disable-line no-empty
(storageResult || (storageResult = {}))[key] = data;
@ -33,7 +35,7 @@ class CookieDriver
result = true;
}
catch (e) {/* eslint-disable-line no-empty */}
catch (e) {} // eslint-disable-line no-empty
return result;
}
@ -54,7 +56,7 @@ class CookieDriver
result = (storageResult && !isUnd(storageResult[key])) ? storageResult[key] : null;
}
catch (e) {/* eslint-disable-line no-empty */}
catch (e) {} // eslint-disable-line no-empty
return result;
}

View file

@ -1,5 +1,6 @@
import {window, JSON} from 'common';
import window from 'window';
import JSON from 'JSON';
import {isUnd} from 'Common/Utils';
import {CLIENT_SIDE_STORAGE_INDEX_NAME} from 'Common/Consts';
@ -21,7 +22,7 @@ class LocalStorageDriver
const storageValue = window.localStorage[CLIENT_SIDE_STORAGE_INDEX_NAME] || null;
storageResult = null === storageValue ? null : JSON.parse(storageValue);
}
catch (e) {/* eslint-disable-line no-empty */}
catch (e) {} // eslint-disable-line no-empty
(storageResult || (storageResult = {}))[key] = data;
@ -30,7 +31,7 @@ class LocalStorageDriver
window.localStorage[CLIENT_SIDE_STORAGE_INDEX_NAME] = JSON.stringify(storageResult);
result = true;
}
catch (e) {/* eslint-disable-line no-empty */}
catch (e) {} // eslint-disable-line no-empty
return result;
}
@ -51,7 +52,7 @@ class LocalStorageDriver
result = (storageResult && !isUnd(storageResult[key])) ? storageResult[key] : null;
}
catch (e) {/* eslint-disable-line no-empty */}
catch (e) {} // eslint-disable-line no-empty
return result;
}

View file

@ -1,5 +1,5 @@
import {_} from 'common';
import _ from '_';
import {isObject, isUnd} from 'Common/Utils';
import * as Plugins from 'Common/Plugins';

View file

@ -1,6 +1,9 @@
/* global RL_COMMUNITY */
import {window, _, $, key} from 'common';
import window from 'window';
import _ from '_';
import $ from '$';
import key from 'key';
import ko from 'ko';
import {KeyState} from 'Common/Enums';
@ -182,9 +185,7 @@ export const leftPanelWidth = ko.observable(0);
// popups
export const popupVisibilityNames = ko.observableArray([]);
export const popupVisibility = ko.computed(() => {
return 0 < popupVisibilityNames().length;
});
export const popupVisibility = ko.computed(() => 0 < popupVisibilityNames().length);
popupVisibility.subscribe((bValue) => {
$html.toggleClass('rl-modal', bValue);
@ -196,9 +197,7 @@ export const keyScopeFake = ko.observable(KeyState.All);
export const keyScope = ko.computed({
owner: this,
read: () => {
return keyScopeFake();
},
read: () => keyScopeFake(),
write: function(sValue) {
if (KeyState.Menu !== sValue)

View file

@ -1,5 +1,7 @@
import {window, _, $} from 'common';
import window from 'window';
import _ from '_';
import $ from '$';
import {oHtmlEditorDefaultConfig, oHtmlEditorLangsMap} from 'Common/Globals';
import * as Settings from 'Storage/Settings';
@ -115,7 +117,7 @@ class HtmlEditor
this.editor.getData() + '</div>' : this.editor.getData();
}
}
catch (e) {/* eslint-disable-line no-empty */}
catch (e) {} // eslint-disable-line no-empty
if (clearSignatureSigns)
{
@ -154,7 +156,7 @@ class HtmlEditor
}
}
}
catch (e) {/* eslint-disable-line no-empty */}
catch (e) {} // eslint-disable-line no-empty
if (resize)
{
@ -184,7 +186,7 @@ class HtmlEditor
try {
this.editor.setData(html);
}
catch (e) {/* eslint-disable-line no-empty */}
catch (e) {} // eslint-disable-line no-empty
if (focus)
{
@ -200,7 +202,7 @@ class HtmlEditor
this.editor.setData(
this.editor.getData().replace(find, replaceHtml));
}
catch (e) {/* eslint-disable-line no-empty */}
catch (e) {} // eslint-disable-line no-empty
}
}
@ -217,7 +219,7 @@ class HtmlEditor
try {
this.editor.setData(plain);
}
catch (e) {/* eslint-disable-line no-empty */}
catch (e) {} // eslint-disable-line no-empty
}
if (focus)
@ -358,7 +360,7 @@ class HtmlEditor
try {
this.editor.focus();
}
catch (e) {/* eslint-disable-line no-empty */}
catch (e) {} // eslint-disable-line no-empty
}
}
@ -368,7 +370,7 @@ class HtmlEditor
try {
return !!this.editor.focusManager.hasFocus;
}
catch (e) {/* eslint-disable-line no-empty */}
catch (e) {} // eslint-disable-line no-empty
}
return false;
@ -380,7 +382,7 @@ class HtmlEditor
try {
this.editor.focusManager.blur(true);
}
catch (e) {/* eslint-disable-line no-empty */}
catch (e) {} // eslint-disable-line no-empty
}
}
@ -390,7 +392,7 @@ class HtmlEditor
try {
this.editor.resize(this.$element.width(), this.$element.innerHeight());
}
catch (e) {/* eslint-disable-line no-empty */}
catch (e) {} // eslint-disable-line no-empty
}
}
@ -400,7 +402,7 @@ class HtmlEditor
try {
this.editor.setReadOnly(!!value);
}
catch (e) {/* eslint-disable-line no-empty */}
catch (e) {} // eslint-disable-line no-empty
}
}

View file

@ -1,5 +1,5 @@
import {window} from 'common';
import window from 'window';
import {pString, pInt, isUnd, isNormal, trim, encodeURIComponent} from 'Common/Utils';
import * as Settings from 'Storage/Settings';

View file

@ -1,5 +1,8 @@
import {window, $, _, moment} from 'common';
import window from 'window';
import _ from '_';
import $ from '$';
import moment from 'moment';
import {i18n} from 'Common/Translator';
let _moment = null;

View file

@ -1,12 +1,13 @@
import {_} from 'common';
import _ from '_';
import {isFunc, isArray, isUnd} from 'Common/Utils';
import {data as GlobalsData} from 'Common/Globals';
import * as Settings from 'Storage/Settings';
const SIMPLE_HOOKS = {};
const USER_VIEW_MODELS_HOOKS = [];
const ADMIN_VIEW_MODELS_HOOKS = [];
const
SIMPLE_HOOKS = {},
USER_VIEW_MODELS_HOOKS = [],
ADMIN_VIEW_MODELS_HOOKS = [];
/**
* @param {string} name
@ -34,7 +35,7 @@ export function runHook(name, args = [])
if (isArray(SIMPLE_HOOKS[name]))
{
_.each(SIMPLE_HOOKS[name], (callback) => {
callback.apply(null, args);
callback(...args);
});
}
}

View file

@ -1,5 +1,7 @@
import {$, _, key} from 'common';
import $ from '$';
import _ from '_';
import key from 'key';
import ko from 'ko';
import {EventKeyCode} from 'Common/Enums';
import {isArray, inArray, noop, noopTrue} from 'Common/Utils';
@ -21,10 +23,7 @@ class Selector
{
this.list = koList;
this.listChecked = ko.computed(() => {
return _.filter(this.list(), (item) => item.checked());
}, this).extend({rateLimit: 0});
this.listChecked = ko.computed(() => _.filter(this.list(), (item) => item.checked())).extend({rateLimit: 0});
this.isListChecked = ko.computed(() => 0 < this.listChecked().length);
this.focusedItem = koFocusedItem || ko.observable(null);

View file

@ -1,5 +1,7 @@
import {window, $, _} from 'common';
import window from 'window';
import _ from '_';
import $ from '$';
import ko from 'ko';
import {Notification, UploadErrorCode} from 'Common/Enums';
import {pInt, isUnd, isNull, has, microtime, inArray} from 'Common/Utils';

View file

@ -19,21 +19,21 @@ const isUnd = _.isUndefined;
const isNull = _.isNull;
const has = _.has;
const bind = _.bind;
const noop = () => {};
const noop = () => {}; // eslint-disable-line no-empty-function
const noopTrue = () => true;
const noopFalse = () => false;
export {trim, inArray, isArray, isObject, isFunc, isUnd, isNull, has, bind, noop, noopTrue, noopFalse};
/**
* @param {Function} callback
* @param {Function} func
*/
export function silentTryCatch(callback)
export function silentTryCatch(func)
{
try {
callback();
func();
}
catch (e) {/* eslint-disable-line no-empty */}
catch (e) {} // eslint-disable-line no-empty
}
/**
@ -314,7 +314,7 @@ export function removeInFocus(force)
window.document.activeElement.blur();
}
}
catch (e) {/* eslint-disable-line no-empty */}
catch (e) {} // eslint-disable-line no-empty
}
}
@ -337,7 +337,7 @@ export function removeSelection()
window.document.selection.empty();
}
}
catch (e) {/* eslint-disable-line no-empty */}
catch (e) {} // eslint-disable-line no-empty
}
/**
@ -453,14 +453,16 @@ export function delegateRun(object, methodName, params, delay = 0)
if (object && object[methodName])
{
delay = pInt(delay);
params = isArray(params) ? params : [];
if (0 >= delay)
{
object[methodName].apply(object, isArray(params) ? params : []);
object[methodName](...params);
}
else
{
_.delay(() => {
object[methodName].apply(object, isArray(params) ? params : []);
object[methodName](...params);
}, delay);
}
}
@ -511,7 +513,6 @@ export function kill_CtrlA_CtrlS(event)
*/
export function createCommand(context, fExecute, fCanExecute = true)
{
let fResult = null;
const fNonEmpty = (...args) => {
if (fResult && fResult.canExecute && fResult.canExecute())
@ -526,15 +527,11 @@ export function createCommand(context, fExecute, fCanExecute = true)
if (isFunc(fCanExecute))
{
fResult.canExecute = ko.computed(() => {
return fResult.enabled() && fCanExecute.call(context);
});
fResult.canExecute = ko.computed(() => fResult.enabled() && fCanExecute.call(context));
}
else
{
fResult.canExecute = ko.computed(() => {
return fResult.enabled() && !!fCanExecute;
});
fResult.canExecute = ko.computed(() => fResult.enabled() && !!fCanExecute);
}
return fResult;
@ -848,14 +845,11 @@ export function htmlToPlain(html)
text = '';
const
convertBlockquote = (blockquoteText) => {
blockquoteText = '> ' + trim(blockquoteText).replace(/\n/gm, '\n> ');
return blockquoteText.replace(/(^|\n)([> ]+)/gm, (...args) => {
return (args && 2 < args.length) ? args[1] + trim(args[2].replace(/[\s]/g, '')) + ' ' : '';
});
return blockquoteText.replace(/(^|\n)([> ]+)/gm,
(...args) => (args && 2 < args.length ? args[1] + trim(args[2].replace(/[\s]/g, '')) + ' ' : ''));
},
convertDivs = (...args) => {
if (args && 1 < args.length)
{
@ -871,19 +865,9 @@ export function htmlToPlain(html)
return '';
},
convertPre = (...args) => {
return (args && 1 < args.length) ?
args[1].toString().replace(/[\n]/gm, '<br />').replace(/[\r]/gm, '') : '';
},
fixAttibuteValue = (...args) => {
return (args && 1 < args.length) ? '' + args[1] + _.escape(args[2]) : '';
},
convertLinks = (...args) => {
return (args && 1 < args.length) ? trim(args[1]) : '';
};
convertPre = (...args) => (args && 1 < args.length ? args[1].toString().replace(/[\n]/gm, '<br />').replace(/[\r]/gm, '') : ''),
fixAttibuteValue = (...args) => (args && 1 < args.length ? '' + args[1] + _.escape(args[2]) : ''),
convertLinks = (...args) => (args && 1 < args.length ? trim(args[1]) : '');
text = html
.replace(/\u0002([\s\S]*)\u0002/gm, '\u200C$1\u200C')
@ -971,10 +955,7 @@ export function htmlToPlain(html)
export function plainToHtml(plain, findEmailAndLinksInText = false)
{
plain = plain.toString().replace(/\r/g, '');
plain = plain.replace(/^>[> ]>+/gm, ([match]) => {
return match ? match.replace(/[ ]+/g, '') : match;
});
plain = plain.replace(/^>[> ]>+/gm, ([match]) => (match ? match.replace(/[ ]+/g, '') : match));
let
bIn = false,
@ -1110,7 +1091,7 @@ export function folderListOptionsBuilder(aSystem, aList, aDisabled, aHeaderLines
for (iIndex = 0, iLen = aSystem.length; iIndex < iLen; iIndex++)
{
oItem = aSystem[iIndex];
if (fVisibleCallback ? fVisibleCallback.call(null, oItem) : true)
if (fVisibleCallback ? fVisibleCallback(oItem) : true)
{
if (bSep && 0 < aResult.length)
{
@ -1126,11 +1107,11 @@ export function folderListOptionsBuilder(aSystem, aList, aDisabled, aHeaderLines
bSep = false;
aResult.push({
id: oItem.fullNameRaw,
name: fRenameCallback ? fRenameCallback.call(null, oItem) : oItem.name(),
name: fRenameCallback ? fRenameCallback(oItem) : oItem.name(),
system: true,
seporator: false,
disabled: !oItem.selectable || -1 < inArray(oItem.fullNameRaw, aDisabled) ||
(fDisableCallback ? fDisableCallback.call(null, oItem) : false)
(fDisableCallback ? fDisableCallback(oItem) : false)
});
}
}
@ -1142,7 +1123,7 @@ export function folderListOptionsBuilder(aSystem, aList, aDisabled, aHeaderLines
// if (oItem.subScribed() || !oItem.existen || bBuildUnvisible)
if ((oItem.subScribed() || !oItem.existen || bBuildUnvisible) && (oItem.selectable || oItem.hasSubScribedSubfolders()))
{
if (fVisibleCallback ? fVisibleCallback.call(null, oItem) : true)
if (fVisibleCallback ? fVisibleCallback(oItem) : true)
{
if (FolderType.User === oItem.type() || !bSystem || oItem.hasSubScribedSubfolders())
{
@ -1161,11 +1142,11 @@ export function folderListOptionsBuilder(aSystem, aList, aDisabled, aHeaderLines
aResult.push({
id: oItem.fullNameRaw,
name: (new window.Array(oItem.deep + 1 - iUnDeep)).join(sDeepPrefix) +
(fRenameCallback ? fRenameCallback.call(null, oItem) : oItem.name()),
(fRenameCallback ? fRenameCallback(oItem) : oItem.name()),
system: false,
seporator: false,
disabled: !oItem.selectable || -1 < inArray(oItem.fullNameRaw, aDisabled) ||
(fDisableCallback ? fDisableCallback.call(null, oItem) : false)
(fDisableCallback ? fDisableCallback(oItem) : false)
});
}
}
@ -1187,7 +1168,7 @@ export function folderListOptionsBuilder(aSystem, aList, aDisabled, aHeaderLines
*/
export function selectElement(element)
{
let sel, range;
let sel = null, range = null;
if (window.getSelection)
{
sel = window.getSelection();
@ -1205,9 +1186,7 @@ export function selectElement(element)
}
export const detectDropdownVisibility = _.debounce(() => {
dropdownVisibility(!!_.find(GlobalsData.aBootstrapDropdowns, (item) => {
return item.hasClass('open');
}));
dropdownVisibility(!!_.find(GlobalsData.aBootstrapDropdowns, (item) => item.hasClass('open')));
}, 50);
/**
@ -1246,7 +1225,7 @@ export function getConfigurationFromScriptTag(configuration)
{
return JSON.parse(configurationScriptTagCache[configuration].text());
}
catch (e) {/* eslint-disable-line no-empty */}
catch (e) {} // eslint-disable-line no-empty
return {};
}
@ -1615,13 +1594,12 @@ export function mailToHelper(mailToUrl, PopupComposeVoreModel)
email = mailToUrl.replace(/\?.+$/, ''),
query = mailToUrl.replace(/^[^\?]*\?/, ''),
EmailModel = require('Model/Email'),
fParseEmailLine = (line) => {
return line ? _.compact(_.map(decodeURIComponent(line).split(/[,]/), (item) => {
const emailObj = new EmailModel();
emailObj.mailsoParse(item);
return '' !== emailObj.email ? emailObj : null;
})) : null;
};
emailObj = new EmailModel(),
fParseEmailLine = (line) => (line ? _.compact(_.map(decodeURIComponent(line).split(/[,]/), (item) => {
emailObj.clear();
emailObj.mailsoParse(item);
return '' !== emailObj.email ? emailObj : null;
})) : null);
to = fParseEmailLine(email);
params = simpleQueryParser(query);