Update arrow-parens to always

This commit is contained in:
toasted-nutbread 2019-11-26 22:01:54 -05:00
parent 63a775ebca
commit 5a1046bc90
20 changed files with 53 additions and 53 deletions

View File

@ -8,7 +8,7 @@
"/ext/bg/js/templates.js" "/ext/bg/js/templates.js"
], ],
"rules": { "rules": {
"arrow-parens": ["error", "as-needed"], "arrow-parens": ["error", "always"],
"comma-dangle": ["error", "never"], "comma-dangle": ["error", "never"],
"curly": ["error", "all"], "curly": ["error", "all"],
"dot-notation": "error", "dot-notation": "error",

View File

@ -74,7 +74,7 @@ class AnkiConnect {
async findNoteIds(notes) { async findNoteIds(notes) {
await this.checkVersion(); await this.checkVersion();
const actions = notes.map(note => ({ const actions = notes.map((note) => ({
action: 'findNotes', action: 'findNotes',
params: { params: {
query: `deck:"${AnkiConnect.escapeQuery(note.deckName)}" ${AnkiConnect.fieldsToQuery(note.fields)}` query: `deck:"${AnkiConnect.escapeQuery(note.deckName)}" ${AnkiConnect.fieldsToQuery(note.fields)}`

View File

@ -207,7 +207,7 @@ async function apiDefinitionsAddable(definitions, modes, optionsContext) {
} }
if (cannotAdd.length > 0) { if (cannotAdd.length > 0) {
const noteIdsArray = await anki.findNoteIds(cannotAdd.map(e => e[0])); const noteIdsArray = await anki.findNoteIds(cannotAdd.map((e) => e[0]));
for (let i = 0, ii = Math.min(cannotAdd.length, noteIdsArray.length); i < ii; ++i) { for (let i = 0, ii = Math.min(cannotAdd.length, noteIdsArray.length); i < ii; ++i) {
const noteIds = noteIdsArray[i]; const noteIds = noteIdsArray[i];
if (noteIds.length > 0) { if (noteIds.length > 0) {

View File

@ -37,8 +37,8 @@ class BackendApiForwarder {
const forwardPort = chrome.tabs.connect(tabId, {name: 'frontend-api-receiver'}); const forwardPort = chrome.tabs.connect(tabId, {name: 'frontend-api-receiver'});
port.onMessage.addListener(message => forwardPort.postMessage(message)); port.onMessage.addListener((message) => forwardPort.postMessage(message));
forwardPort.onMessage.addListener(message => port.postMessage(message)); forwardPort.onMessage.addListener((message) => port.postMessage(message));
port.onDisconnect.addListener(() => forwardPort.disconnect()); port.onDisconnect.addListener(() => forwardPort.disconnect());
forwardPort.onDisconnect.addListener(() => port.disconnect()); forwardPort.onDisconnect.addListener(() => port.disconnect());
} }

View File

@ -60,7 +60,7 @@ class Backend {
this.applyOptions(); this.applyOptions();
const callback = () => this.checkLastError(chrome.runtime.lastError); const callback = () => this.checkLastError(chrome.runtime.lastError);
chrome.tabs.query({}, tabs => { chrome.tabs.query({}, (tabs) => {
for (const tab of tabs) { for (const tab of tabs) {
chrome.tabs.sendMessage(tab.id, {action: 'optionsUpdate', params: {source}}, callback); chrome.tabs.sendMessage(tab.id, {action: 'optionsUpdate', params: {source}}, callback);
} }
@ -77,8 +77,8 @@ class Backend {
const handler = handlers[action]; const handler = handlers[action];
const promise = handler(params, sender); const promise = handler(params, sender);
promise.then( promise.then(
result => callback({result}), (result) => callback({result}),
error => callback({error: errorToJson(error)}) (error) => callback({error: errorToJson(error)})
); );
} }

View File

@ -63,7 +63,7 @@ window.addEventListener('DOMContentLoaded', () => {
depth: 0, depth: 0,
url: window.location.href url: window.location.href
}; };
apiOptionsGet(optionsContext).then(options => { apiOptionsGet(optionsContext).then((options) => {
const toggle = document.querySelector('#enable-search'); const toggle = document.querySelector('#enable-search');
toggle.checked = options.general.enable; toggle.checked = options.general.enable;
toggle.addEventListener('change', () => apiCommandExec('toggle'), false); toggle.addEventListener('change', () => apiCommandExec('toggle'), false);

View File

@ -257,7 +257,7 @@ class Database {
const dbTerms = dbTransaction.objectStore('tagMeta'); const dbTerms = dbTransaction.objectStore('tagMeta');
const dbIndex = dbTerms.index('name'); const dbIndex = dbTerms.index('name');
const only = IDBKeyRange.only(name); const only = IDBKeyRange.only(name);
await Database.getAll(dbIndex, only, null, row => { await Database.getAll(dbIndex, only, null, (row) => {
if (title === row.dictionary) { if (title === row.dictionary) {
result = row; result = row;
} }
@ -273,7 +273,7 @@ class Database {
const dbTransaction = this.db.transaction(['dictionaries'], 'readonly'); const dbTransaction = this.db.transaction(['dictionaries'], 'readonly');
const dbDictionaries = dbTransaction.objectStore('dictionaries'); const dbDictionaries = dbTransaction.objectStore('dictionaries');
await Database.getAll(dbDictionaries, null, null, info => results.push(info)); await Database.getAll(dbDictionaries, null, null, (info) => results.push(info));
return results; return results;
} }
@ -308,7 +308,7 @@ class Database {
counts.push(null); counts.push(null);
const index = i; const index = i;
const query2 = IDBKeyRange.only(dictionaryNames[i]); const query2 = IDBKeyRange.only(dictionaryNames[i]);
const countPromise = Database.getCounts(targets, query2).then(v => counts[index] = v); const countPromise = Database.getCounts(targets, query2).then((v) => counts[index] = v);
countPromises.push(countPromise); countPromises.push(countPromise);
} }
await Promise.all(countPromises); await Promise.all(countPromises);
@ -346,7 +346,7 @@ class Database {
} }
}; };
const indexDataLoaded = async summary => { const indexDataLoaded = async (summary) => {
if (summary.version > 3) { if (summary.version > 3) {
throw new Error('Unsupported dictionary version'); throw new Error('Unsupported dictionary version');
} }
@ -522,13 +522,13 @@ class Database {
await indexDataLoaded(summary); await indexDataLoaded(summary);
const buildTermBankName = index => `term_bank_${index + 1}.json`; const buildTermBankName = (index) => `term_bank_${index + 1}.json`;
const buildTermMetaBankName = index => `term_meta_bank_${index + 1}.json`; const buildTermMetaBankName = (index) => `term_meta_bank_${index + 1}.json`;
const buildKanjiBankName = index => `kanji_bank_${index + 1}.json`; const buildKanjiBankName = (index) => `kanji_bank_${index + 1}.json`;
const buildKanjiMetaBankName = index => `kanji_meta_bank_${index + 1}.json`; const buildKanjiMetaBankName = (index) => `kanji_meta_bank_${index + 1}.json`;
const buildTagBankName = index => `tag_bank_${index + 1}.json`; const buildTagBankName = (index) => `tag_bank_${index + 1}.json`;
const countBanks = namer => { const countBanks = (namer) => {
let count = 0; let count = 0;
while (zip.files[namer(count)]) { while (zip.files[namer(count)]) {
++count; ++count;
@ -657,7 +657,7 @@ class Database {
const counts = {}; const counts = {};
for (const [objectStoreName, index] of targets) { for (const [objectStoreName, index] of targets) {
const n = objectStoreName; const n = objectStoreName;
const countPromise = Database.getCount(index, query).then(count => counts[n] = count); const countPromise = Database.getCount(index, query).then((count) => counts[n] = count);
countPromises.push(countPromise); countPromises.push(countPromise);
} }
return Promise.all(countPromises).then(() => counts); return Promise.all(countPromises).then(() => counts);

View File

@ -99,8 +99,8 @@ function dictTermsCompressTags(definitions) {
let lastPartOfSpeech = ''; let lastPartOfSpeech = '';
for (const definition of definitions) { for (const definition of definitions) {
const dictionary = JSON.stringify(definition.definitionTags.filter(tag => tag.category === 'dictionary').map(tag => tag.name).sort()); const dictionary = JSON.stringify(definition.definitionTags.filter((tag) => tag.category === 'dictionary').map((tag) => tag.name).sort());
const partOfSpeech = JSON.stringify(definition.definitionTags.filter(tag => tag.category === 'partOfSpeech').map(tag => tag.name).sort()); const partOfSpeech = JSON.stringify(definition.definitionTags.filter((tag) => tag.category === 'partOfSpeech').map((tag) => tag.name).sort());
const filterOutCategories = []; const filterOutCategories = [];
@ -117,7 +117,7 @@ function dictTermsCompressTags(definitions) {
lastPartOfSpeech = partOfSpeech; lastPartOfSpeech = partOfSpeech;
} }
definition.definitionTags = definition.definitionTags.filter(tag => !filterOutCategories.includes(tag.category)); definition.definitionTags = definition.definitionTags.filter((tag) => !filterOutCategories.includes(tag.category));
} }
} }
@ -231,7 +231,7 @@ function dictTermsMergeByGloss(result, definitions, appendTo, mergedIndices) {
result.reading.add(definition.reading); result.reading.add(definition.reading);
for (const tag of definition.definitionTags) { for (const tag of definition.definitionTags) {
if (!definitionsByGloss[gloss].definitionTags.find(existingTag => existingTag.name === tag.name)) { if (!definitionsByGloss[gloss].definitionTags.find((existingTag) => existingTag.name === tag.name)) {
definitionsByGloss[gloss].definitionTags.push(tag); definitionsByGloss[gloss].definitionTags.push(tag);
} }
} }
@ -246,7 +246,7 @@ function dictTermsMergeByGloss(result, definitions, appendTo, mergedIndices) {
} }
for (const tag of definition.termTags) { for (const tag of definition.termTags) {
if (!result.expressions.get(definition.expression).get(definition.reading).find(existingTag => existingTag.name === tag.name)) { if (!result.expressions.get(definition.expression).get(definition.reading).find((existingTag) => existingTag.name === tag.name)) {
result.expressions.get(definition.expression).get(definition.reading).push(tag); result.expressions.get(definition.expression).get(definition.reading).push(tag);
} }
} }

View File

@ -429,7 +429,7 @@ function optionsUpdateVersion(options, defaultProfileOptions) {
function optionsLoad() { function optionsLoad() {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
chrome.storage.local.get(['options'], store => { chrome.storage.local.get(['options'], (store) => {
const error = chrome.runtime.lastError; const error = chrome.runtime.lastError;
if (error) { if (error) {
reject(new Error(error)); reject(new Error(error));
@ -437,7 +437,7 @@ function optionsLoad() {
resolve(store.options); resolve(store.options);
} }
}); });
}).then(optionsStr => { }).then((optionsStr) => {
if (typeof optionsStr === 'string') { if (typeof optionsStr === 'string') {
const options = JSON.parse(optionsStr); const options = JSON.parse(optionsStr);
if (isObject(options)) { if (isObject(options)) {
@ -447,7 +447,7 @@ function optionsLoad() {
return {}; return {};
}).catch(() => { }).catch(() => {
return {}; return {};
}).then(options => { }).then((options) => {
return ( return (
Array.isArray(options.profiles) ? Array.isArray(options.profiles) ?
optionsUpdateVersion(options, {}) : optionsUpdateVersion(options, {}) :

View File

@ -86,7 +86,7 @@ const profileConditionsDescriptor = {
placeholder: 'Comma separated list of domains', placeholder: 'Comma separated list of domains',
defaultValue: 'example.com', defaultValue: 'example.com',
transformCache: {}, transformCache: {},
transform: (optionValue) => optionValue.split(/[,;\s]+/).map(v => v.trim().toLowerCase()).filter(v => v.length > 0), transform: (optionValue) => optionValue.split(/[,;\s]+/).map((v) => v.trim().toLowerCase()).filter((v) => v.length > 0),
transformReverse: (transformedOptionValue) => transformedOptionValue.join(', '), transformReverse: (transformedOptionValue) => transformedOptionValue.join(', '),
validateTransformed: (transformedOptionValue) => (transformedOptionValue.length > 0), validateTransformed: (transformedOptionValue) => (transformedOptionValue.length > 0),
test: ({url}, transformedOptionValue) => _profileConditionTestDomainList(url, transformedOptionValue) test: ({url}, transformedOptionValue) => _profileConditionTestDomainList(url, transformedOptionValue)

View File

@ -29,7 +29,7 @@ function requestJson(url, action, params) {
} else { } else {
xhr.send(); xhr.send();
} }
}).then(responseText => { }).then((responseText) => {
try { try {
return JSON.parse(responseText); return JSON.parse(responseText);
} }

View File

@ -107,7 +107,7 @@ class QueryParser {
} }
getParseResult() { getParseResult() {
return this.parseResults.find(r => r.id === this.selectedParser); return this.parseResults.find((r) => r.id === this.selectedParser);
} }
async setText(text) { async setText(text) {
@ -216,7 +216,7 @@ class QueryParser {
static processParseResultForDisplay(result) { static processParseResultForDisplay(result) {
return result.map((term) => { return result.map((term) => {
return term.filter(part => part.text.trim()).map((part) => { return term.filter((part) => part.text.trim()).map((part) => {
return { return {
text: Array.from(part.text), text: Array.from(part.text),
reading: part.reading, reading: part.reading,

View File

@ -62,8 +62,8 @@ class SettingsDictionaryListUI {
this.updateDictionaryOrder(); this.updateDictionaryOrder();
const titles = this.dictionaryEntries.map(e => e.dictionaryInfo.title); const titles = this.dictionaryEntries.map((e) => e.dictionaryInfo.title);
const removeKeys = Object.keys(this.optionsDictionaries).filter(key => titles.indexOf(key) < 0); const removeKeys = Object.keys(this.optionsDictionaries).filter((key) => titles.indexOf(key) < 0);
if (removeKeys.length > 0) { if (removeKeys.length > 0) {
for (const key of toIterable(removeKeys)) { for (const key of toIterable(removeKeys)) {
delete this.optionsDictionaries[key]; delete this.optionsDictionaries[key];
@ -161,7 +161,7 @@ class SettingsDictionaryListUI {
delete n.dataset.dict; delete n.dataset.dict;
$(n).modal('hide'); $(n).modal('hide');
const index = this.dictionaryEntries.findIndex(e => e.dictionaryInfo.title === title); const index = this.dictionaryEntries.findIndex((e) => e.dictionaryInfo.title === title);
if (index >= 0) { if (index >= 0) {
this.dictionaryEntries[index].deleteDictionary(); this.dictionaryEntries[index].deleteDictionary();
} }
@ -377,7 +377,7 @@ async function onDatabaseUpdated(options) {
updateMainDictionarySelect(options, dictionaries); updateMainDictionarySelect(options, dictionaries);
const {counts, total} = await utilDatabaseGetDictionaryCounts(dictionaries.map(v => v.title), true); const {counts, total} = await utilDatabaseGetDictionaryCounts(dictionaries.map((v) => v.title), true);
dictionaryUI.setCounts(counts, total); dictionaryUI.setCounts(counts, total);
} catch (e) { } catch (e) {
dictionaryErrorsShow([e]); dictionaryErrorsShow([e]);
@ -564,7 +564,7 @@ async function onDictionaryImport(e) {
dictionaryErrorsShow(null); dictionaryErrorsShow(null);
dictionarySpinnerShow(true); dictionarySpinnerShow(true);
const setProgress = percent => dictProgress.find('.progress-bar').css('width', `${percent}%`); const setProgress = (percent) => dictProgress.find('.progress-bar').css('width', `${percent}%`);
const updateProgress = (total, current) => { const updateProgress = (total, current) => {
setProgress(current / total * 100.0); setProgress(current / total * 100.0);
if (storageEstimate.mostRecent !== null && !storageUpdateStats.isUpdating) { if (storageEstimate.mostRecent !== null && !storageUpdateStats.isUpdating) {

View File

@ -147,7 +147,7 @@ function profileOptionsCreateCopyName(name, profiles, maxUniqueAttempts) {
let i = 0; let i = 0;
while (true) { while (true) {
const newName = `${prefix}${space}${index}${suffix}`; const newName = `${prefix}${space}${index}${suffix}`;
if (i++ >= maxUniqueAttempts || profiles.findIndex(profile => profile.name === newName) < 0) { if (i++ >= maxUniqueAttempts || profiles.findIndex((profile) => profile.name === newName) < 0) {
return newName; return newName;
} }
if (typeof index !== 'number') { if (typeof index !== 'number') {

View File

@ -18,7 +18,7 @@
async function getOptionsArray() { async function getOptionsArray() {
const optionsFull = await apiOptionsGetFull(); const optionsFull = await apiOptionsGetFull();
return optionsFull.profiles.map(profile => profile.options); return optionsFull.profiles.map((profile) => profile.options);
} }
async function formRead(options) { async function formRead(options) {
@ -484,12 +484,12 @@ async function ankiDeckAndModelPopulate(options) {
const deckNames = await utilAnkiGetDeckNames(); const deckNames = await utilAnkiGetDeckNames();
const ankiDeck = $('.anki-deck'); const ankiDeck = $('.anki-deck');
ankiDeck.find('option').remove(); ankiDeck.find('option').remove();
deckNames.sort().forEach(name => ankiDeck.append($('<option/>', {value: name, text: name}))); deckNames.sort().forEach((name) => ankiDeck.append($('<option/>', {value: name, text: name})));
const modelNames = await utilAnkiGetModelNames(); const modelNames = await utilAnkiGetModelNames();
const ankiModel = $('.anki-model'); const ankiModel = $('.anki-model');
ankiModel.find('option').remove(); ankiModel.find('option').remove();
modelNames.sort().forEach(name => ankiModel.append($('<option/>', {value: name, text: name}))); modelNames.sort().forEach((name) => ankiModel.append($('<option/>', {value: name, text: name})));
$('#anki-terms-deck').val(options.anki.terms.deck); $('#anki-terms-deck').val(options.anki.terms.deck);
await ankiFieldsPopulate($('#anki-terms-model').val(options.anki.terms.model), options); await ankiFieldsPopulate($('#anki-terms-model').val(options.anki.terms.model), options);
@ -690,7 +690,7 @@ async function ankiTemplatesValidate(infoNode, field, mode, showSuccessResult, i
const hasException = exceptions.length > 0; const hasException = exceptions.length > 0;
infoNode.hidden = !(showSuccessResult || hasException); infoNode.hidden = !(showSuccessResult || hasException);
infoNode.textContent = hasException ? exceptions.map(e => `${e}`).join('\n') : (showSuccessResult ? result : ''); infoNode.textContent = hasException ? exceptions.map((e) => `${e}`).join('\n') : (showSuccessResult ? result : '');
infoNode.classList.toggle('text-danger', hasException); infoNode.classList.toggle('text-danger', hasException);
if (invalidateInput) { if (invalidateInput) {
const input = document.querySelector('#field-templates'); const input = document.querySelector('#field-templates');

View File

@ -51,7 +51,7 @@ class Translator {
const definitionsBySequence = dictTermsMergeBySequence(definitions, mainDictionary); const definitionsBySequence = dictTermsMergeBySequence(definitions, mainDictionary);
const defaultDefinitions = definitionsBySequence['-1']; const defaultDefinitions = definitionsBySequence['-1'];
const sequenceList = Object.keys(definitionsBySequence).map(v => Number(v)).filter(v => v >= 0); const sequenceList = Object.keys(definitionsBySequence).map((v) => Number(v)).filter((v) => v >= 0);
const sequencedDefinitions = sequenceList.map((key) => ({ const sequencedDefinitions = sequenceList.map((key) => ({
definitions: definitionsBySequence[key], definitions: definitionsBySequence[key],
rawDefinitions: [] rawDefinitions: []
@ -124,7 +124,7 @@ class Translator {
for (const expression of result.expressions.keys()) { for (const expression of result.expressions.keys()) {
for (const reading of result.expressions.get(expression).keys()) { for (const reading of result.expressions.get(expression).keys()) {
const termTags = result.expressions.get(expression).get(reading); const termTags = result.expressions.get(expression).get(reading);
const score = termTags.map(tag => tag.score).reduce((p, v) => p + v, 0); const score = termTags.map((tag) => tag.score).reduce((p, v) => p + v, 0);
expressions.push({ expressions.push({
expression: expression, expression: expression,
reading: reading, reading: reading,
@ -173,7 +173,7 @@ class Translator {
async findTermsMerged(text, details, options) { async findTermsMerged(text, details, options) {
const dictionaries = dictEnabledSet(options); const dictionaries = dictEnabledSet(options);
const secondarySearchTitles = Object.keys(options.dictionaries).filter(dict => options.dictionaries[dict].allowSecondarySearches); const secondarySearchTitles = Object.keys(options.dictionaries).filter((dict) => options.dictionaries[dict].allowSecondarySearches);
const titles = Object.keys(dictionaries); const titles = Object.keys(dictionaries);
const [definitions, length] = await this.findTermsInternal(text, dictionaries, options.scanning.alphanumeric, details); const [definitions, length] = await this.findTermsInternal(text, dictionaries, options.scanning.alphanumeric, details);
const {sequencedDefinitions, defaultDefinitions} = await this.getSequencedDefinitions(definitions, options.general.mainDictionary); const {sequencedDefinitions, defaultDefinitions} = await this.getSequencedDefinitions(definitions, options.general.mainDictionary);
@ -320,7 +320,7 @@ class Translator {
} }
} }
return deinflections.filter(e => e.definitions.length > 0); return deinflections.filter((e) => e.definitions.length > 0);
} }
getDeinflections(text) { getDeinflections(text) {

View File

@ -41,13 +41,13 @@ function utilSetEqual(setA, setB) {
function utilSetIntersection(setA, setB) { function utilSetIntersection(setA, setB) {
return new Set( return new Set(
[...setA].filter(value => setB.has(value)) [...setA].filter((value) => setB.has(value))
); );
} }
function utilSetDifference(setA, setB) { function utilSetDifference(setA, setB) {
return new Set( return new Set(
[...setA].filter(value => !setB.has(value)) [...setA].filter((value) => !setB.has(value))
); );
} }

View File

@ -43,10 +43,10 @@ class FrontendApiReceiver {
const handler = this.handlers[action]; const handler = this.handlers[action];
handler(params).then( handler(params).then(
result => { (result) => {
this.sendResult(port, id, senderId, {result}); this.sendResult(port, id, senderId, {result});
}, },
error => { (error) => {
this.sendResult(port, id, senderId, {error: errorToJson(error)}); this.sendResult(port, id, senderId, {error: errorToJson(error)});
}); });
} }

View File

@ -28,8 +28,8 @@ class Popup {
this.childrenSupported = true; this.childrenSupported = true;
this.container = document.createElement('iframe'); this.container = document.createElement('iframe');
this.container.className = 'yomichan-float'; this.container.className = 'yomichan-float';
this.container.addEventListener('mousedown', e => e.stopPropagation()); this.container.addEventListener('mousedown', (e) => e.stopPropagation());
this.container.addEventListener('scroll', e => e.stopPropagation()); this.container.addEventListener('scroll', (e) => e.stopPropagation());
this.container.setAttribute('src', chrome.runtime.getURL('/fg/float.html')); this.container.setAttribute('src', chrome.runtime.getURL('/fg/float.html'));
this.container.style.width = '0px'; this.container.style.width = '0px';
this.container.style.height = '0px'; this.container.style.height = '0px';

View File

@ -173,5 +173,5 @@ function stringReplaceAsync(str, regex, replacer) {
return Promise.resolve(str); return Promise.resolve(str);
} }
parts.push(str.substring(index)); parts.push(str.substring(index));
return Promise.all(parts).then(v => v.join('')); return Promise.all(parts).then((v) => v.join(''));
} }