From 75dda2c75bc94f5768c9997ffa04518dd9acc2d4 Mon Sep 17 00:00:00 2001 From: Oliver Hamlet Date: Wed, 14 Sep 2016 18:47:11 +0100 Subject: [PATCH] Update JS style config, and code to match --- .eslintrc.yml | 18 ++--- resources/l10n/template.pot | 84 ++++++++---------------- scripts/potomo.js | 4 +- scripts/vulcanize.js | 2 + src/gui/html/js/dom.js | 4 +- src/gui/html/js/events.js | 14 ++-- src/gui/html/js/filters.js | 2 +- src/gui/html/js/game.js | 36 +++++----- src/gui/html/js/plugin.js | 22 ++++--- src/gui/html/js/translator.js | 3 +- src/tests/gui/html/js/mock_dom.js | 8 --- src/tests/gui/html/js/test_filters.js | 4 +- src/tests/gui/html/js/test_game.js | 2 +- src/tests/gui/html/js/test_query.js | 20 +++--- src/tests/gui/html/js/test_state.js | 8 +++ src/tests/gui/html/js/test_translator.js | 42 ++++++------ 16 files changed, 129 insertions(+), 144 deletions(-) diff --git a/.eslintrc.yml b/.eslintrc.yml index bc061e24..43d9228e 100644 --- a/.eslintrc.yml +++ b/.eslintrc.yml @@ -5,9 +5,6 @@ env: node: true browser: true -ecmaFeatures: - modules: false - globals: loot: false should: false @@ -17,13 +14,18 @@ extends: - "airbnb-base" rules: - strict: - - 2 - - global + strict: off no-param-reassign: - - 2 + - error - props: false - max-len: 1 + max-len: warn + linebreak-style: off + no-underscore-dangle: off + arrow-parens: off + no-undef: warn + no-mixed-operators: + - error + - allowSamePrecedence: true plugins: - eslint-plugin-html diff --git a/resources/l10n/template.pot b/resources/l10n/template.pot index 1f3f707d..ccf5347b 100644 --- a/resources/l10n/template.pot +++ b/resources/l10n/template.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: LOOT 0.9.2\n" "Report-Msgid-Bugs-To: https://github.com/loot/loot/issues\n" -"POT-Creation-Date: 2016-09-10 10:52+0100\n" +"POT-Creation-Date: 2016-09-14 18:51+0100\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -17,64 +17,64 @@ msgstr "" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" -#: src/gui/html/js/events.js:16 +#: src/gui/html/js/events.js:18 msgid "Identifying conflicting plugins..." msgstr "" -#: src/gui/html/js/events.js:96 +#: src/gui/html/js/events.js:100 msgid "No masterlist update was necessary." msgstr "" -#: src/gui/html/js/events.js:146 +#: src/gui/html/js/events.js:150 msgid "Sorting made no changes to the load order." msgstr "" -#: src/gui/html/js/events.js:178 +#: src/gui/html/js/events.js:182 msgid "Redate Plugins?" msgstr "" -#: src/gui/html/js/events.js:178 +#: src/gui/html/js/events.js:182 msgid "" "This feature is provided so that modders using the Creation Kit may set the " "load order it uses. A side-effect is that any subscribed Steam Workshop mods " "will be re-downloaded by Steam. Do you wish to continue?" msgstr "" -#: src/gui/html/js/events.js:178 +#: src/gui/html/js/events.js:182 msgid "Redate" msgstr "" -#: src/gui/html/js/events.js:187 +#: src/gui/html/js/events.js:191 msgid "" "Are you sure you want to clear all existing user-added metadata from all " "plugins?" msgstr "" -#: src/gui/html/js/events.js:187 src/gui/html/js/events.js:395 +#: src/gui/html/js/events.js:191 src/gui/html/js/events.js:401 msgid "Clear" msgstr "" -#: src/gui/html/js/events.js:198 +#: src/gui/html/js/events.js:202 msgid "All user-added metadata has been cleared." msgstr "" -#: src/gui/html/js/events.js:221 +#: src/gui/html/js/events.js:225 msgid "LOOT's content has been copied to the clipboard." msgstr "" -#: src/gui/html/js/events.js:232 +#: src/gui/html/js/events.js:236 msgid "The load order has been copied to the clipboard." msgstr "" -#: src/gui/html/js/events.js:263 src/gui/html/js/translateStaticText.js:195 +#: src/gui/html/js/events.js:267 src/gui/html/js/translateStaticText.js:195 msgid "Quit" msgstr "" -#: src/gui/html/js/events.js:275 +#: src/gui/html/js/events.js:279 msgid "sorted load order" msgstr "" -#: src/gui/html/js/events.js:277 +#: src/gui/html/js/events.js:281 msgid "metadata edits" msgstr "" @@ -584,32 +584,18 @@ msgid "" "can be accessed through the main menu." msgstr "" -#: src/gui/query_handler.cpp:133 +#: src/gui/query/get_game_data_query.h:45 msgid "Parsing, merging and evaluating metadata..." msgstr "" -#: src/gui/query_handler.cpp:191 src/gui/query_handler.cpp:194 -msgid "Failed to change game. Details: %1%" -msgstr "" - -#: src/gui/query_handler.cpp:208 src/gui/query_handler.cpp:211 -#: src/gui/query_handler.cpp:289 src/gui/query_handler.cpp:292 -#: src/gui/query_handler.cpp:320 src/gui/query_handler.cpp:323 -msgid "Failed to copy plugin metadata. Details: %1%" -msgstr "" - -#: src/gui/query_handler.cpp:229 src/gui/query_handler.cpp:239 -msgid "Failed to apply plugin metadata. Details: %1%" -msgstr "" - -#: src/gui/query_handler.cpp:592 +#: src/gui/query/get_game_data_query.h:80 msgid "" "An error occurred while parsing the masterlist: %1%. This probably happened " "because an update to LOOT changed its metadata syntax support. Try updating " "your masterlist to resolve the error." msgstr "" -#: src/gui/query_handler.cpp:607 +#: src/gui/query/get_game_data_query.h:94 msgid "" "An error occurred while parsing the userlist: %1%. This probably happened " "because an update to LOOT changed its metadata syntax support. Your user " @@ -625,36 +611,24 @@ msgid "" "[LOOT's website](https://loot.github.io/)." msgstr "" -#: src/gui/query_handler.cpp:712 src/gui/query_handler.cpp:715 -msgid "Failed to get game data. Details: %1%" -msgstr "" - -#: src/gui/query_handler.cpp:797 src/gui/query_handler.cpp:800 -msgid "Failed to update the masterlist. Details: %1%" -msgstr "" - -#: src/gui/query_handler.cpp:839 -msgid "Loading plugin contents..." -msgstr "" - -#: src/gui/query_handler.cpp:843 -msgid "Sorting load order..." -msgstr "" - -#: src/gui/query_handler.cpp:900 -msgid "Failed to sort plugins. Details: %1%" -msgstr "" - -#: src/gui/query_handler.cpp:931 +#: src/gui/query/metadata_query.h:94 msgid "" "A global message contains a condition that could not be evaluated. Details: " "%1%" msgstr "" -#: src/gui/query_handler.cpp:963 src/backend/plugin/plugin_sorter.cpp:217 +#: src/gui/query/metadata_query.h:120 src/backend/plugin/plugin_sorter.cpp:217 msgid "\"%1%\" contains a condition that could not be evaluated. Details: %2%" msgstr "" +#: src/gui/query/sort_plugins_query.h:46 +msgid "Loading plugin contents..." +msgstr "" + +#: src/gui/query/sort_plugins_query.h:66 +msgid "Sorting load order..." +msgstr "" + #: src/backend/app/loot_paths.cpp:85 msgid "Failed to get %LOCALAPPDATA% path." msgstr "" @@ -831,7 +805,7 @@ msgstr "" msgid "This plugin is incompatible with \"%1%\", but both are present." msgstr "" -#: src/backend/plugin/plugin_sorter.cpp:81 +#: src/backend/plugin/plugin_sorter.cpp:82 msgid "" "Cyclic interaction detected between plugins \"%1%\" and \"%2%\". Back cycle: " "%3%" diff --git a/scripts/potomo.js b/scripts/potomo.js index 14472808..f76a03d0 100644 --- a/scripts/potomo.js +++ b/scripts/potomo.js @@ -1,4 +1,6 @@ /* Convert .po files to .mo files. */ +/* eslint-disable no-unused-vars */ + 'use strict'; const childProcess = require('child_process'); const fs = require('fs'); @@ -12,7 +14,7 @@ function getMsgfmtPath() { path.join('/', 'usr', 'bin', 'msgfmt'), ]; - for (let i = 0; i < paths.length; ++i) { + for (let i = 0; i < paths.length; i += 1) { if (helpers.fileExists(paths[i])) { return paths[i]; } diff --git a/scripts/vulcanize.js b/scripts/vulcanize.js index 650351d6..60895f7c 100755 --- a/scripts/vulcanize.js +++ b/scripts/vulcanize.js @@ -1,6 +1,8 @@ #!/usr/bin/env node // Build the UI's index.html file. Takes one argument, which is the path to the // repository's root. + +/* eslint-disable no-unused-vars */ 'use strict'; const path = require('path'); const fs = require('fs'); diff --git a/src/gui/html/js/dom.js b/src/gui/html/js/dom.js index 0b7809c6..815671ed 100644 --- a/src/gui/html/js/dom.js +++ b/src/gui/html/js/dom.js @@ -87,7 +87,7 @@ /* Also disable deletion of the game's row in the settings dialog. */ const table = document.getElementById('gameTable'); - for (let i = 0; i < table.tBodies[0].rows.length; ++i) { + for (let i = 0; i < table.tBodies[0].rows.length; i += 1) { const folderElements = table.tBodies[0].rows[i].getElementsByClassName('folder'); if (folderElements.length === 1) { table.setReadOnly(table.tBodies[0].rows[i], @@ -99,7 +99,7 @@ static updateEnabledGames(installedGames) { const gameMenuItems = document.getElementById('gameMenu').children; - for (let i = 0; i < gameMenuItems.length; ++i) { + for (let i = 0; i < gameMenuItems.length; i += 1) { DOM.enable(gameMenuItems[i], installedGames.indexOf(gameMenuItems[i].getAttribute('value')) !== -1); } diff --git a/src/gui/html/js/events.js b/src/gui/html/js/events.js index 47f6a92f..54cb8b43 100644 --- a/src/gui/html/js/events.js +++ b/src/gui/html/js/events.js @@ -1,3 +1,5 @@ +/* eslint-disable no-unused-vars */ + 'use strict'; function onSidebarFilterToggle(evt) { loot.filters[evt.target.id] = evt.target.checked; @@ -313,13 +315,15 @@ function onCloseSettingsDialog(evt) { loot.query('closeSettings', settings).then(JSON.parse).then((installedGames) => { loot.installedGames = installedGames; loot.DOM.updateEnabledGames(installedGames); - }).catch(loot.handlePromiseError).then(() => { + }).catch(loot.handlePromiseError) + .then(() => { loot.settings = settings; loot.DOM.updateSettingsDialog(loot.settings); loot.DOM.setGameMenuItems(loot.settings.games); loot.DOM.updateEnabledGames(loot.installedGames); loot.DOM.updateSelectedGame(loot.game.folder); - }).catch(loot.handlePromiseError); + }) + .catch(loot.handlePromiseError); } function onEditorOpen(evt) { /* Set the editor data. */ @@ -334,7 +338,7 @@ function onEditorOpen(evt) { /* Set up drag 'n' drop event handlers. */ const elements = document.getElementById('cardsNav').getElementsByTagName('loot-plugin-item'); - for (let i = 0; i < elements.length; ++i) { + for (let i = 0; i < elements.length; i += 1) { elements[i].draggable = true; elements[i].addEventListener('dragstart', elements[i].onDragStart); } @@ -380,7 +384,7 @@ function onEditorClose(evt) { /* Remove drag 'n' drop event handlers. */ const elements = document.getElementById('cardsNav').getElementsByTagName('loot-plugin-item'); - for (let i = 0; i < elements.length; ++i) { + for (let i = 0; i < elements.length; i += 1) { elements[i].removeAttribute('draggable'); elements[i].removeEventListener('dragstart', elements[i].onDragStart); } @@ -449,7 +453,7 @@ function onSearchEnd(evt) { function onFolderChange(evt) { loot.DOM.updateSelectedGame(evt.detail.folder); /* Enable/disable the redate plugins option. */ - let gameSettings = undefined; + let gameSettings; if (loot.settings && loot.settings.games) { gameSettings = loot.settings.games.find(game => game.folder === evt.detail.folder); } diff --git a/src/gui/html/js/filters.js b/src/gui/html/js/filters.js index 2a672465..e49c5b52 100644 --- a/src/gui/html/js/filters.js +++ b/src/gui/html/js/filters.js @@ -126,7 +126,7 @@ document.getElementById('pluginCardList').items = filteredPlugins; const pluginCards = document.getElementById('pluginCardList').children; - for (let i = 0; i < pluginCards.length; ++i) { + for (let i = 0; i < pluginCards.length; i += 1) { if (pluginCards[i].data) { pluginCards[i].updateContent(true); } diff --git a/src/gui/html/js/game.js b/src/gui/html/js/game.js index 450f4c36..f5c4c319 100644 --- a/src/gui/html/js/game.js +++ b/src/gui/html/js/game.js @@ -53,9 +53,9 @@ oldTotal = this._globalMessages.length; this._globalMessages.forEach((message) => { if (message.type === 'warn') { - ++oldWarns; + oldWarns += 1; } else if (message.type === 'error') { - ++oldErrs; + oldErrs += 1; } }); } @@ -65,9 +65,9 @@ globalMessages.forEach((message) => { if (message.type === 'warn') { - ++newWarns; + newWarns += 1; } else if (message.type === 'error') { - ++newErrs; + newErrs += 1; } }); } @@ -134,27 +134,27 @@ totalMessageNo = this.globalMessages.length; this.globalMessages.forEach((message) => { if (message.type === 'warn') { - ++warnMessageNo; + warnMessageNo += 1; } else if (message.type === 'error') { - ++errorMessageNo; + errorMessageNo += 1; } }); } plugins.forEach((plugin) => { if (plugin.isActive) { - ++activePluginNo; + activePluginNo += 1; } if (plugin.isDirty) { - ++dirtyPluginNo; + dirtyPluginNo += 1; } if (plugin.messages) { totalMessageNo += plugin.messages.length; plugin.messages.forEach((message) => { if (message.type === 'warn') { - ++warnMessageNo; + warnMessageNo += 1; } else if (message.type === 'error') { - ++errorMessageNo; + errorMessageNo += 1; } }); } @@ -183,18 +183,18 @@ let dirtyChange = 0; if (plugin.isActive) { - ++activeChange; + activeChange += 1; } if (plugin.isDirty) { - ++dirtyChange; + dirtyChange += 1; } if (plugin.messages) { totalChange += plugin.messages.length; plugin.messages.forEach((message) => { if (message.type === 'warn') { - ++warnChange; + warnChange += 1; } else if (message.type === 'error') { - ++errorChange; + errorChange += 1; } }); } @@ -222,18 +222,18 @@ let dirtyChange = 0; if (this._plugins[index].isActive) { - --activeChange; + activeChange -= 1; } if (this._plugins[index].isDirty) { - --dirtyChange; + dirtyChange -= 1; } if (this._plugins[index].messages) { totalChange -= this._plugins[index].messages.length; this._plugins[index].messages.forEach((message) => { if (message.type === 'warn') { - --warnChange; + warnChange -= 1; } else if (message.type === 'error') { - --errorChange; + errorChange -= 1; } }); } diff --git a/src/gui/html/js/plugin.js b/src/gui/html/js/plugin.js index 42a40b58..b3315b85 100644 --- a/src/gui/html/js/plugin.js +++ b/src/gui/html/js/plugin.js @@ -102,7 +102,7 @@ const tagsRemoved = []; if (this._tags) { - for (let i = 0; i < this._tags.length; ++i) { + for (let i = 0; i < this._tags.length; i += 1) { if (this._tags[i].name[0] === '-') { tagsRemoved.push(this._tags[i].name.substr(1)); } else { @@ -112,12 +112,12 @@ } /* Now make sure that the same tag doesn't appear in both arrays. Prefer the removed list. */ - for (let i = 0; i < tagsAdded.length; ++i) { - for (let j = 0; j < tagsRemoved.length; ++j) { + for (let i = 0; i < tagsAdded.length; i += 1) { + for (let j = 0; j < tagsRemoved.length; j += 1) { if (tagsRemoved[j].toLowerCase() === tagsAdded[i].toLowerCase()) { /* Remove tag from the tagsAdded array. */ tagsAdded.splice(i, 1); - --i; + i -= 1; } } } @@ -149,7 +149,7 @@ return true; } - for (let i = 0; i < this.messages.length; ++i) { + for (let i = 0; i < this.messages.length; i += 1) { if (this.messages[i].text.toLowerCase().indexOf(needle) !== -1) { return true; } @@ -208,7 +208,9 @@ } static tagFromRowData(rowData) { - if (rowData.condition === undefined || rowData.name === undefined || rowData.type === undefined) { + if (rowData.condition === undefined + || rowData.name === undefined + || rowData.type === undefined) { throw new TypeError('Row data members are undefined'); } const tag = { @@ -284,9 +286,9 @@ this._messages.forEach((message) => { if (message.type === 'warn') { - ++oldWarns; + oldWarns += 1; } else if (message.type === 'error') { - ++oldErrs; + oldErrs += 1; } }); @@ -294,9 +296,9 @@ messages.forEach((message) => { if (message.type === 'warn') { - ++newWarns; + newWarns += 1; } else if (message.type === 'error') { - ++newErrs; + newErrs += 1; } }); diff --git a/src/gui/html/js/translator.js b/src/gui/html/js/translator.js index 63f210cb..44021996 100644 --- a/src/gui/html/js/translator.js +++ b/src/gui/html/js/translator.js @@ -71,7 +71,6 @@ if (this.jed === undefined) { return text; } - const func = this.jed.translate(text); - return func.fetch.apply(func, substitutions); + return this.jed.translate(text).fetch(...substitutions); } })); diff --git a/src/tests/gui/html/js/mock_dom.js b/src/tests/gui/html/js/mock_dom.js index 864fdbb9..d857ff74 100644 --- a/src/tests/gui/html/js/mock_dom.js +++ b/src/tests/gui/html/js/mock_dom.js @@ -13,11 +13,3 @@ loot.DOM = { this.elementEnabledStates.set(elementId, enableElement); }, }; - -function getShown(elementId) { - return loot.DOM.elementShownStates.get(elementId); -} - -function getEnabled(elementId) { - return loot.DOM.elementEnabledStates.get(elementId); -} diff --git a/src/tests/gui/html/js/test_filters.js b/src/tests/gui/html/js/test_filters.js index a7f7bdc2..8d81f164 100644 --- a/src/tests/gui/html/js/test_filters.js +++ b/src/tests/gui/html/js/test_filters.js @@ -3,7 +3,7 @@ describe('Filters', () => { /* Mock the Translator class. */ class Translator { - translate(text) { + translate(text) { // eslint-disable-line class-methods-use-this return text; } } @@ -68,7 +68,7 @@ describe('Filters', () => { return this._messages; } - containsText(text) { + containsText(text) { // eslint-disable-line class-methods-use-this return text === 'found text'; } } diff --git a/src/tests/gui/html/js/test_game.js b/src/tests/gui/html/js/test_game.js index 93335755..64e46c21 100644 --- a/src/tests/gui/html/js/test_game.js +++ b/src/tests/gui/html/js/test_game.js @@ -3,7 +3,7 @@ describe('Game', () => { /* Mock the Translator class. */ class Translator { - translate(text) { + translate(text) { // eslint-disable-line class-methods-use-this return text; } } diff --git a/src/tests/gui/html/js/test_query.js b/src/tests/gui/html/js/test_query.js index 3859100b..15dfc5c2 100644 --- a/src/tests/gui/html/js/test_query.js +++ b/src/tests/gui/html/js/test_query.js @@ -18,22 +18,22 @@ describe('query()', () => { loot.query('test').should.be.a.Promise(); // eslint-disable-line new-cap }); - it('should succeed if a request name is passed', () => { - return loot.query('test').should.be.fulfilledWith('{"name":"test","args":[]}'); - }); + it('should succeed if a request name is passed', () => + loot.query('test').should.be.fulfilledWith('{"name":"test","args":[]}') + ); - it('should succeed if a request name and arguments are passed', () => { - return loot.query('test', 1, false, ['a']).should.be.fulfilledWith(JSON.stringify({ + it('should succeed if a request name and arguments are passed', () => + loot.query('test', 1, false, ['a']).should.be.fulfilledWith(JSON.stringify({ name: 'test', args: [ 1, false, ['a'], ], - })); - }); + })) + ); - it('should fail with an Error object when an error occurs', () => { - return loot.query('fail').should.be.rejectedWith(Error, { message: 'Error code: -1; {"name":"fail","args":[]}' }); - }); + it('should fail with an Error object when an error occurs', () => + loot.query('fail').should.be.rejectedWith(Error, { message: 'Error code: -1; {"name":"fail","args":[]}' }) + ); }); diff --git a/src/tests/gui/html/js/test_state.js b/src/tests/gui/html/js/test_state.js index 7f53075c..ca8b8fc9 100644 --- a/src/tests/gui/html/js/test_state.js +++ b/src/tests/gui/html/js/test_state.js @@ -1,5 +1,13 @@ 'use strict'; +function getShown(elementId) { + return loot.DOM.elementShownStates.get(elementId); +} + +function getEnabled(elementId) { + return loot.DOM.elementEnabledStates.get(elementId); +} + beforeEach(() => { loot.DOM.elementShownStates.clear(); loot.DOM.elementEnabledStates.clear(); diff --git a/src/tests/gui/html/js/test_translator.js b/src/tests/gui/html/js/test_translator.js index 461b8694..ca865cdf 100644 --- a/src/tests/gui/html/js/test_translator.js +++ b/src/tests/gui/html/js/test_translator.js @@ -41,33 +41,33 @@ describe('Translator', () => { l10n.translate('foo').should.equal('foo'); }); - it('should return an empty string if nothing is passed', () => { - return l10n.load().then(() => { + it('should return an empty string if nothing is passed', () => + l10n.load().then(() => { l10n.translate().should.equal(''); - }); - }); + }) + ); - it('should return the input string if the current locale is "en"', () => { - return l10n.load().then(() => { + it('should return the input string if the current locale is "en"', () => + l10n.load().then(() => { l10n.translate('foo').should.equal('foo'); - }); - }); + }) + ); it('should return the translated string if locale data has been loaded', () => { /* Since loading data doesn't work in the browser, hack it by setting some data manually. */ l10n.jed = new window.Jed({ - 'locale_data': { - 'messages': { + locale_data: { + messages: { '': { - 'domain': 'messages', - 'lang': 'en', - 'plural_forms': 'nplurals=2; plural=(n != 1);', + domain: 'messages', + lang: 'en', + plural_forms: 'nplurals=2; plural=(n != 1);', }, - 'foo': ['bar'], + foo: ['bar'], }, }, - 'domain': 'messages', + domain: 'messages', }); l10n.translate('foo').should.equal('bar'); @@ -77,17 +77,17 @@ describe('Translator', () => { /* Since loading data doesn't work in the browser, hack it by setting some data manually. */ l10n.jed = new window.Jed({ - 'locale_data': { - 'messages': { + locale_data: { + messages: { '': { - 'domain': 'messages', - 'lang': 'en', - 'plural_forms': 'nplurals=2; plural=(n != 1);', + domain: 'messages', + lang: 'en', + plural_forms: 'nplurals=2; plural=(n != 1);', }, 'foo %1$s %2$s': ['%2$s is bar'], }, }, - 'domain': 'messages', + domain: 'messages', }); l10n.translate('foo %1$s %2$s', 'is not', 'bar').should.equal('bar is bar');