From ce618f440801e0c04f1660050a225f8556f72003 Mon Sep 17 00:00:00 2001 From: Alexey Kasyanchuk Date: Wed, 8 Aug 2018 23:55:47 +0300 Subject: [PATCH] eslint --- .eslintrc.json | 3 +- src/app/app.js | 16 ++++---- src/app/filters-page.js | 2 +- src/app/pages-pie.js | 4 +- src/app/torrent.js | 4 +- src/background/api.js | 8 ++-- src/background/background.js | 6 +-- src/background/bt/cpu-usage-global.js | 48 ++++++++++++------------ src/background/bt/spider.js | 2 +- src/background/bt/token.js | 4 +- src/background/bt/udp-tracker-request.js | 2 +- src/background/dbPatcher.js | 2 +- src/background/mysql.js | 12 +++--- src/background/server.js | 6 +-- src/background/sphinx.js | 6 +-- src/background/spider.js | 6 +-- src/background/torrentClient.js | 2 +- 17 files changed, 67 insertions(+), 66 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index 1614848..bbe74af 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -11,6 +11,7 @@ "react" ], "rules": { - "indent": ["error", "tab"] + "indent": ["error", "tab"], + "space-infix-ops": ["error", {"int32Hint": false}] } } \ No newline at end of file diff --git a/src/app/app.js b/src/app/app.js index c13b33f..8d1ecdc 100644 --- a/src/app/app.js +++ b/src/app/app.js @@ -155,15 +155,15 @@ class App extends Component { } document.addEventListener('dragover', (event) => { - event.stopPropagation(); - event.preventDefault(); - event.dataTransfer.dropEffect = 'copy'; // Explicitly show this is a copy. - }, false); - document.addEventListener('drop', (event) => { - event.stopPropagation(); + event.stopPropagation(); event.preventDefault(); - processTorrents(event.dataTransfer.files); // FileList object. - }, false); + event.dataTransfer.dropEffect = 'copy'; // Explicitly show this is a copy. + }, false); + document.addEventListener('drop', (event) => { + event.stopPropagation(); + event.preventDefault(); + processTorrents(event.dataTransfer.files); // FileList object. + }, false); window.router() appReady = true; diff --git a/src/app/filters-page.js b/src/app/filters-page.js index 4249a08..41e0296 100644 --- a/src/app/filters-page.js +++ b/src/app/filters-page.js @@ -249,7 +249,7 @@ export default class ConfigPage extends Page { null } { - this.removed > 0 && !this.toRemove && !this.toRemoveProbably + this.removed > 0 && !this.toRemove && !this.toRemoveProbably ?
{this.realRemove ? __('removing') : __('calculation')}...: {this.removed}{this.removedMax > 0 ? '/' + this.removedMax : ''}
: diff --git a/src/app/pages-pie.js b/src/app/pages-pie.js index 13ea30a..88261a8 100644 --- a/src/app/pages-pie.js +++ b/src/app/pages-pie.js @@ -58,13 +58,13 @@ class PagesPie extends Component { { this.pie.map(({Page, params}, index) => { let focus = false; - if (index === this.pie.length-1) { + if (index === this.pie.length - 1) { focus = true; } return ( { index> 0 ? this.close() : null}} + closeHandler={() => { index > 0 ? this.close() : null}} index={index} key={index} ref={index} diff --git a/src/app/torrent.js b/src/app/torrent.js index af689cf..a5cd8eb 100644 --- a/src/app/torrent.js +++ b/src/app/torrent.js @@ -187,7 +187,7 @@ export default class Torrent extends Component { componentDidMount() { - scrollBack() + scrollBack() this.downloading = (hash) => { if(this.props.torrent.hash != hash) @@ -275,7 +275,7 @@ export default class Torrent extends Component { return true; } */ - window.rememberYOffset = window.pageYOffset + window.rememberYOffset = window.pageYOffset window.routerFix() PagesPie.instance().open(TorrentPage, {replace: 'all', hash: torrent.hash, peer: torrent.peer}) }} diff --git a/src/background/api.js b/src/background/api.js index 17547e9..c3faa7c 100644 --- a/src/background/api.js +++ b/src/background/api.js @@ -209,7 +209,7 @@ module.exports = async ({ p2p.on('randomTorrents', (nil, callback) => { if(typeof callback != 'function') return; - + const cpu = cpuUsage() const limit = Math.max(1, 5 - (cpu / 20) | 0) @@ -1003,15 +1003,15 @@ module.exports = async ({ if(peer.info && peer.info.feed) { if(peer.info.feed > feed.size() // list bigger than our - || (peer.info.feed == feed.size() && peer.info.feedDate > feed.feedDate)) // or same but more new + || (peer.info.feed == feed.size() && peer.info.feedDate > feed.feedDate)) // or same but more new { peer.emit('feed', null, (remoteFeed) => { if(!remoteFeed) return - + if(Array.isArray(remoteFeed) || !remoteFeed.feed) return // old version call - + if(remoteFeed.feed.length > feed.size() || (remoteFeed.feed.length == feed.size() && remoteFeed.feedDate > feed.feedDate)) { logT('feed', 'replace our feed with remote feed') diff --git a/src/background/background.js b/src/background/background.js index 16e64c0..874b2a7 100644 --- a/src/background/background.js +++ b/src/background/background.js @@ -84,9 +84,9 @@ const stringHashCode = (str) => { if (str.length === 0) return hash; for (i = 0; i < str.length; i++) { - chr = str.charCodeAt(i); - hash = ((hash << 5) - hash) + chr; - hash |= 0; // Convert to 32bit integer + chr = str.charCodeAt(i); + hash = ((hash << 5) - hash) + chr; + hash |= 0; // Convert to 32bit integer } return hash; }; diff --git a/src/background/bt/cpu-usage-global.js b/src/background/bt/cpu-usage-global.js index 3d1a5b2..d637a4e 100644 --- a/src/background/bt/cpu-usage-global.js +++ b/src/background/bt/cpu-usage-global.js @@ -3,27 +3,27 @@ var os = require("os"); //Create function to get CPU information function cpuAverage() { - //Initialise sum of idle and time of cores and fetch CPU info - let totalIdle = 0, totalTick = 0; - const cpus = os.cpus(); + //Initialise sum of idle and time of cores and fetch CPU info + let totalIdle = 0, totalTick = 0; + const cpus = os.cpus(); - //Loop through CPU cores - for(let i = 0, len = cpus.length; i < len; i++) { + //Loop through CPU cores + for(let i = 0, len = cpus.length; i < len; i++) { - //Select CPU core - const cpu = cpus[i]; + //Select CPU core + const cpu = cpus[i]; - //Total up the time in the cores tick - for(const type in cpu.times) { - totalTick += cpu.times[type]; - } + //Total up the time in the cores tick + for(const type in cpu.times) { + totalTick += cpu.times[type]; + } - //Total up the idle time of the core - totalIdle += cpu.times.idle; - } + //Total up the idle time of the core + totalIdle += cpu.times.idle; + } - //Return the average Idle and Tick times - return {idle: totalIdle / cpus.length, total: totalTick / cpus.length}; + //Return the average Idle and Tick times + return {idle: totalIdle / cpus.length, total: totalTick / cpus.length}; } //Grab first CPU Measure @@ -33,16 +33,16 @@ let percentageCPU = 0 //Set delay for second Measure const cpuTimer = setInterval(function() { - //Grab second Measure - const endMeasure = cpuAverage(); + //Grab second Measure + const endMeasure = cpuAverage(); - //Calculate the difference in idle and total time between the measures - const idleDifference = endMeasure.idle - startMeasure.idle; - const totalDifference = endMeasure.total - startMeasure.total; + //Calculate the difference in idle and total time between the measures + const idleDifference = endMeasure.idle - startMeasure.idle; + const totalDifference = endMeasure.total - startMeasure.total; - //Calculate the average percentage CPU usage - percentageCPU = 100 - ~~(100 * idleDifference / totalDifference); - startMeasure = endMeasure + //Calculate the average percentage CPU usage + percentageCPU = 100 - ~~(100 * idleDifference / totalDifference); + startMeasure = endMeasure }, 300); diff --git a/src/background/bt/spider.js b/src/background/bt/spider.js index 4c1c09b..54c4d79 100644 --- a/src/background/bt/spider.js +++ b/src/background/bt/spider.js @@ -33,7 +33,7 @@ function generateTid() { class Spider extends Emiter { constructor(client) { super() - const options = arguments.length? arguments[0]: {} + const options = arguments.length ? arguments[0] : {} this.table = new Table(options.tableCaption || 1000) this.bootstraps = options.bootstraps || bootstraps this.token = new Token() diff --git a/src/background/bt/token.js b/src/background/bt/token.js index 735e174..30d0cf2 100644 --- a/src/background/bt/token.js +++ b/src/background/bt/token.js @@ -3,7 +3,7 @@ module.exports = class { constructor() { this.generate() - const it = setInterval(() => this.generate(), 60000*15) + const it = setInterval(() => this.generate(), 60000 * 15) it.unref() } @@ -12,6 +12,6 @@ module.exports = class { } generate() { - this.token = new Buffer([parseInt(Math.random()*200), parseInt(Math.random()*200)]) + this.token = new Buffer([parseInt(Math.random() * 200), parseInt(Math.random() * 200)]) } } \ No newline at end of file diff --git a/src/background/bt/udp-tracker-request.js b/src/background/bt/udp-tracker-request.js index 3a1af26..e761d80 100644 --- a/src/background/bt/udp-tracker-request.js +++ b/src/background/bt/udp-tracker-request.js @@ -24,7 +24,7 @@ let connectTracker = function(connection) { debug('start screape connection'); let buffer = new Buffer(16); - const transactionId = Math.floor((Math.random()*100000)+1); + const transactionId = Math.floor((Math.random() * 100000) + 1); buffer.fill(0); diff --git a/src/background/dbPatcher.js b/src/background/dbPatcher.js index b1eb544..a200c9a 100644 --- a/src/background/dbPatcher.js +++ b/src/background/dbPatcher.js @@ -209,7 +209,7 @@ module.exports = async (callback, mainWindow, sphinxApp) => { if(torrentsArray.length >= 20000) { fs.writeFileSync(`${sphinxApp.directoryPath}/torrents.patch.${patch++}`, JSON.stringify(torrentsArray, null, 4), 'utf8'); - logT('patcher', 'write torrents dump', `${sphinxApp.directoryPath}/torrents.patch.${patch-1}`) + logT('patcher', 'write torrents dump', `${sphinxApp.directoryPath}/torrents.patch.${patch - 1}`) torrentsArray = [] } }) diff --git a/src/background/mysql.js b/src/background/mysql.js index c37e358..750174b 100644 --- a/src/background/mysql.js +++ b/src/background/mysql.js @@ -150,12 +150,12 @@ const pool = async () => { let currentConnection = 0 for(let i = 0; i < connectionsLimit; i++) { - connectionPool[i] = await single().waitConnection() + connectionPool[i] = await single().waitConnection() } const buildPoolMethod = (name, ...args) => { if(!connectionPool) return - + const data = connectionPool[currentConnection][name](...args) currentConnection = (currentConnection + 1) % connectionsLimit return data @@ -220,7 +220,7 @@ const single = (callback) => { promiseResolve = resolve }) mysqlSingle.waitConnection = () => connectionPromise; - + mysqlSingle._mysql.connect((mysqlError) => { if (mysqlError) { logT('sql', 'error connecting: ' + mysqlError.stack); @@ -232,7 +232,7 @@ const single = (callback) => { promiseResolve(proxySingle) }); - + mysqlSingle._mysql.on('error', (err) => { if(err.code === 'PROTOCOL_CONNECTION_LOST') { // Connection to the MySQL server is usually logT('sql', 'lost connection, restart single sql connection') @@ -245,7 +245,7 @@ const single = (callback) => { }); mysqlSingle._mysql = expand(mysqlSingle._mysql) - + // fix prevent query after closing const end = mysqlSingle._mysql.end.bind(mysqlSingle._mysql) mysqlSingle._mysql.end = (cb) => new Promise(resolve => { @@ -254,7 +254,7 @@ const single = (callback) => { resolve() if(cb) cb() - }) + }) }) return proxySingle diff --git a/src/background/server.js b/src/background/server.js index 2aa8e23..fd28bdc 100644 --- a/src/background/server.js +++ b/src/background/server.js @@ -21,9 +21,9 @@ const stringHashCode = (str) => { if (str.length === 0) return hash; for (i = 0; i < str.length; i++) { - chr = str.charCodeAt(i); - hash = ((hash << 5) - hash) + chr; - hash |= 0; // Convert to 32bit integer + chr = str.charCodeAt(i); + hash = ((hash << 5) - hash) + chr; + hash |= 0; // Convert to 32bit integer } return hash; }; diff --git a/src/background/sphinx.js b/src/background/sphinx.js index 2dced30..80ef98c 100644 --- a/src/background/sphinx.js +++ b/src/background/sphinx.js @@ -158,8 +158,8 @@ module.exports = (callback, dataDirectory, onClose) => { } // check external sphinx instance for using - const sphinxPid=`${sphinxConfigDirectory}/searchd.pid` - const isSphinxExternal=fs.existsSync(sphinxPid) && isRunning(parseInt(fs.readFileSync(sphinxPid))) + const sphinxPid = `${sphinxConfigDirectory}/searchd.pid` + const isSphinxExternal = fs.existsSync(sphinxPid) && isRunning(parseInt(fs.readFileSync(sphinxPid))) if(isSphinxExternal) logT('sphinx', `founded running sphinx instance in ${sphinxPid}, using it`) @@ -230,7 +230,7 @@ module.exports = (callback, dataDirectory, onClose) => { sphinx.onClose = onFinish if(replaceFinish) sphinx.replaceOnClose = true // sometime we don't want to call default callback - + if (!sphinx.isExternal) exec(`"${sphinxPath}" --config "${config}" --stopwait`) else diff --git a/src/background/spider.js b/src/background/spider.js index d50bf38..cc02ea8 100644 --- a/src/background/spider.js +++ b/src/background/spider.js @@ -81,7 +81,7 @@ module.exports = function (send, recive, dataDirectory, version, env) p2p.info.torrents = (await sphinxSingle.query("SELECT COUNT(*) as cnt from torrents"))[0].cnt p2p.info.files = (await sphinxSingle.query("SELECT COUNT(*) as cnt from files"))[0].cnt const sphinxSingleAlternative = await single().waitConnection() - + // start function baseRowData(row) @@ -388,7 +388,7 @@ module.exports = function (send, recive, dataDirectory, version, env) sphinxSingle.query('SELECT count(*) as files_count FROM files WHERE hash = ?', [torrent.hash], function(err, rows) { if(!rows) return - + const db_files = rows[0]['files_count']; if(db_files !== torrent.files) { @@ -575,7 +575,7 @@ module.exports = function (send, recive, dataDirectory, version, env) } }); - + let downloadersCallbacks = {} events.on('insert', (torrent) => { const { hash } = torrent diff --git a/src/background/torrentClient.js b/src/background/torrentClient.js index 8ebed07..0a95015 100644 --- a/src/background/torrentClient.js +++ b/src/background/torrentClient.js @@ -67,7 +67,7 @@ torrentClient.dht.on('peer', (peer, infoHash) => { torrentClient._downloader(peer, infoHash, (...data) => { if(metaHashes[hash]) metaHashes[hash](...data) - + delete metaHashes[hash] }) }