From 5c99214ae37132dac54878eee8e3af71a26e7b36 Mon Sep 17 00:00:00 2001 From: coderaiser Date: Fri, 17 Feb 2017 16:14:21 +0200 Subject: [PATCH] feature(eslintrc) add no-use-before-define --- .eslintrc | 3 ++- client/client.js | 4 +--- client/config.js | 15 ++++++++------- client/dom.js | 20 ++++++++++---------- client/edit-file.js | 3 +-- client/edit-names.js | 3 +-- client/help.js | 4 ++-- client/load.js | 36 +++++++++++++++--------------------- client/menu.js | 6 ++---- client/operation.js | 22 +++++++++++----------- client/upload.js | 3 +-- 11 files changed, 54 insertions(+), 65 deletions(-) diff --git a/.eslintrc b/.eslintrc index 0b3ccc16..eb6279f1 100644 --- a/.eslintrc +++ b/.eslintrc @@ -10,7 +10,8 @@ }, "rules": { "indent": ["error", 4], - "semi": "error" + "semi": "error", + "no-use-before-define": ["error", "nofunc"] }, "extends": ["eslint:recommended"] } diff --git a/client/client.js b/client/client.js index a62154ff..899bd2ac 100644 --- a/client/client.js +++ b/client/client.js @@ -438,9 +438,7 @@ function CloudCmdProto(Util, DOM, CloudFunc) { CloudCmd.log('reading dir: "' + path + '";'); - var dirStorage = CloudCmd.config(dirStorage); - - if (!dirStorage) + if (!CloudCmd.config('dirStorage')) return create(); Storage.get(path, create); diff --git a/client/config.js b/client/config.js index 5a352caa..6d685f5e 100644 --- a/client/config.js +++ b/client/config.js @@ -58,13 +58,6 @@ function ConfigProto() { const href = getHost(); const prefix = CloudCmd.PREFIX; const FIVE_SECONDS = 5000; - const save = (data) => { - onSave(data); - socket.send(data); - }; - - if (error) - return; const socket = io.connect(href + prefix + '/config', { 'max reconnection attempts' : Math.pow(2, 32), @@ -72,6 +65,14 @@ function ConfigProto() { path: prefix + '/socket.io' }); + const save = (data) => { + onSave(data); + socket.send(data); + }; + + if (error) + return; + authCheck(socket); socket.on('connect', () => { diff --git a/client/dom.js b/client/dom.js index 8fdb0857..8e153fd0 100644 --- a/client/dom.js +++ b/client/dom.js @@ -326,19 +326,19 @@ function CmdProto() { isArray = itype.array(module.local), version = module.version, - funcON = function() { - load.parallel(remote, function(error) { - if (error) - funcOFF(); - else - callback(); - }); + funcOFF = () => { + load.parallel(local, callback); }, - funcOFF = function() { - load.parallel(local, callback); + funcON = () => { + load.parallel(remote, (error) => { + if (error) + return funcOFF(); + + callback(); + }); }; - + if (isArray) { remoteTmpls = module.remote; local = module.local; diff --git a/client/edit-file.js b/client/edit-file.js index fbb3f883..eb39444a 100644 --- a/client/edit-file.js +++ b/client/edit-file.js @@ -114,6 +114,7 @@ CloudCmd.EditFile = function EditFileProto(callback) { !Menu && DOM.loadRemote('menu', (error) => { let noFocus; + const editor = CloudCmd.Edit.getEditor(); const options = { beforeShow: (params) => { params.x -= 18; @@ -125,8 +126,6 @@ CloudCmd.EditFile = function EditFileProto(callback) { } }; - const editor = CloudCmd.Edit.getEditor(); - const menuData = { 'Save Ctrl+S' : () => { editor.save(); diff --git a/client/edit-names.js b/client/edit-names.js index d6e84032..119fec1b 100644 --- a/client/edit-names.js +++ b/client/edit-names.js @@ -146,6 +146,7 @@ CloudCmd.EditNames = function EditNamesProto(callback) { !Menu && DOM.loadRemote('menu', (error) => { MenuIO = window.MenuIO; let noFocus; + const editor = CloudCmd.Edit.getEditor(); const options = { beforeShow: (params) => { params.x -= 18; @@ -157,8 +158,6 @@ CloudCmd.EditNames = function EditNamesProto(callback) { } }; - const editor = CloudCmd.Edit.getEditor(); - const menuData = { 'Save Ctrl+S' : () => { editor.save(); diff --git a/client/help.js b/client/help.js index 3a922400..885acd36 100644 --- a/client/help.js +++ b/client/help.js @@ -4,6 +4,8 @@ CloudCmd.Help = HelpProto; +const {Images} = require('./dom'); + function HelpProto() { Images.show.load('top'); show(); @@ -11,8 +13,6 @@ function HelpProto() { return exports; } -const {Images} = require('./dom'); - module.exports.show = show; module.exports.hide = hide; diff --git a/client/load.js b/client/load.js index 12155279..ad7da78f 100644 --- a/client/load.js +++ b/client/load.js @@ -46,19 +46,14 @@ function load(params) { notAppend, } = params; - /* - * if passed arguments function - * then it's onload by default - * - * if object - then onload and onerror - */ - const funcLoad = () => { - const callback = func && func.onload || func; - - Events.remove('error', element, funcError); - - exec(callback); - }; + let element = document.getElementById(id); + + if (element) { + exec(func); + return element; + } + + element = document.createElement(name); const funcError = () => { const msg = `file ${src} could not be loaded`; @@ -73,14 +68,13 @@ function load(params) { exec(callback, error); }; - let element = document.getElementById(id); - - if (element) { - exec(func); - return element; - } - - element = document.createElement(name); + const funcLoad = () => { + const callback = func && func.onload || func; + + Events.remove('error', element, funcError); + + exec(callback); + }; if (/^(script|link)$/.test(name)) Events.addOnce('load', element, funcLoad) diff --git a/client/menu.js b/client/menu.js index 71dbf069..957af2b2 100644 --- a/client/menu.js +++ b/client/menu.js @@ -267,11 +267,7 @@ function MenuProto(position) { files.forEach((file) => { const selected = DOM.isSelected(file); - const id = load.getIdBySrc(path); const isDir = DOM.isCurrentIsDir(file); - - CloudCmd.log('downloading file ' + path + '...'); - /* * if we send ajax request - * no need in hash so we escape # @@ -280,7 +276,9 @@ function MenuProto(position) { const path = DOM.getCurrentPath(file) .replace(/#/g, '%23'); + CloudCmd.log('downloading file ' + path + '...'); const encodedPath = encodeURI(path); + const id = load.getIdBySrc(path); let src; diff --git a/client/operation.js b/client/operation.js index 36f791c9..0f061b10 100644 --- a/client/operation.js +++ b/client/operation.js @@ -173,21 +173,21 @@ function OperationProto(operation, data) { options = {}; } - var done; - var lastError; + let done; + let lastError; - var listeners = { - progress: function(value) { + const listeners = { + progress: (value) => { done = value === 100; Images.setProgress(value); }, - end: function() { + end: () => { Images .hide() .clearProgress(); - events.forEach(function(name) { + Object.keys(listeners).forEach((name) => { emitter.removeListener(name, listeners[name]); }); @@ -195,7 +195,7 @@ function OperationProto(operation, data) { callback(lastError); }, - error: function(error) { + error: (error) => { lastError = error; if (options.noContinue) { @@ -203,18 +203,18 @@ function OperationProto(operation, data) { Dialog.alert(TITLE, error); } else { Dialog.confirm(TITLE, error + '\n Continue?') - .then(function() { + .then(() => { emitter.continue(); - }, function() { + }, () => { emitter.abort(); }); } } }; - var events = Object.keys(listeners); + const events = Object.keys(listeners); - events.forEach(function(name) { + events.forEach((name) => { emitter.on(name, listeners[name]); }); } diff --git a/client/upload.js b/client/upload.js index 6884da02..6f5b87b8 100644 --- a/client/upload.js +++ b/client/upload.js @@ -6,6 +6,7 @@ const exec = require('execon'); const load = require('./load'); const Files = require('./files'); +const {Images} = DOM; CloudCmd.Upload = UploadProto; @@ -20,8 +21,6 @@ function UploadProto() { return exports; } -const {Images} = DOM; - module.exports.show = show; module.exports.hide = hide;