Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update eslint spacing rules #366

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@
}
],
"no-implicit-globals": "error",
"no-multi-spaces": "error",
"no-trailing-spaces": "error",
"no-whitespace-before-property": "error",
"object-curly-spacing": [
Expand Down Expand Up @@ -221,6 +222,12 @@
"error",
"never"
],
"space-infix-ops": [
"error",
{
"int32Hint": false
}
],
"space-unary-ops": "error",
"spaced-comment": [
"error",
Expand Down Expand Up @@ -515,7 +522,10 @@
"files": [
"*.json"
],
"parser": "jsonc-eslint-parser"
"parser": "jsonc-eslint-parser",
"rules": {
"no-multi-spaces": "off"
}
},
{
"files": [
Expand Down
2 changes: 1 addition & 1 deletion dev/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export function getArgs(args, argMap) {
* @param {?(fileName: string) => boolean} predicate
* @returns {string[]}
*/
export function getAllFiles(baseDirectory, predicate=null) {
export function getAllFiles(baseDirectory, predicate = null) {
const results = [];
const directories = [baseDirectory];
while (directories.length > 0) {
Expand Down
8 changes: 6 additions & 2 deletions ext/js/app/frontend.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ export class Frontend {
parentPopupId,
parentFrameId,
useProxyPopup,
canUseWindowPopup=true,
canUseWindowPopup = true,
allowRootFramePopupProxy,
childrenSupported=true,
childrenSupported = true,
hotkeyHandler
}) {
/** @type {import('frontend').PageType} */
Expand Down Expand Up @@ -106,6 +106,7 @@ export class Frontend {
/** @type {?import('settings').OptionsContext} */
this._optionsContextOverride = null;

/* eslint-disable no-multi-spaces */
/** @type {import('core').MessageHandlerMap} */
this._runtimeMessageHandlers = new Map(/** @type {import('core').MessageHandlerArray} */ ([
['Frontend.requestReadyBroadcast', {async: false, handler: this._onMessageRequestFrontendReadyBroadcast.bind(this)}],
Expand All @@ -117,6 +118,7 @@ export class Frontend {
['scanSelectedText', this._onActionScanSelectedText.bind(this)],
['scanTextAtCaret', this._onActionScanTextAtCaret.bind(this)]
]);
/* eslint-enable no-multi-spaces */
}

/**
Expand Down Expand Up @@ -174,13 +176,15 @@ export class Frontend {
this._textScanner.on('clear', this._onTextScannerClear.bind(this));
this._textScanner.on('searched', this._onSearched.bind(this));

/* eslint-disable no-multi-spaces */
yomitan.crossFrame.registerHandlers([
['Frontend.closePopup', {async: false, handler: this._onApiClosePopup.bind(this)}],
['Frontend.copySelection', {async: false, handler: this._onApiCopySelection.bind(this)}],
['Frontend.getSelectionText', {async: false, handler: this._onApiGetSelectionText.bind(this)}],
['Frontend.getPopupInfo', {async: false, handler: this._onApiGetPopupInfo.bind(this)}],
['Frontend.getPageInfo', {async: false, handler: this._onApiGetPageInfo.bind(this)}]
]);
/* eslint-enable no-multi-spaces */

this._prepareSiteSpecific();
this._updateContentScale();
Expand Down
14 changes: 8 additions & 6 deletions ext/js/app/popup-factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export class PopupFactory {
*/
prepare() {
this._frameOffsetForwarder.prepare();
/* eslint-disable no-multi-spaces */
yomitan.crossFrame.registerHandlers([
['PopupFactory.getOrCreatePopup', {async: true, handler: this._onApiGetOrCreatePopup.bind(this)}],
['PopupFactory.setOptionsContext', {async: true, handler: this._onApiSetOptionsContext.bind(this)}],
Expand All @@ -64,6 +65,7 @@ export class PopupFactory {
['PopupFactory.getFrameSize', {async: true, handler: this._onApiGetFrameSize.bind(this)}],
['PopupFactory.setFrameSize', {async: true, handler: this._onApiSetFrameSize.bind(this)}]
]);
/* eslint-enable no-multi-spaces */
}

/**
Expand All @@ -72,12 +74,12 @@ export class PopupFactory {
* @returns {Promise<import('popup').PopupAny>}
*/
async getOrCreatePopup({
frameId=null,
id=null,
parentPopupId=null,
depth=null,
popupWindow=false,
childrenSupported=false
frameId = null,
id = null,
parentPopupId = null,
depth = null,
popupWindow = false,
childrenSupported = false
}) {
// Find by existing id
if (id !== null) {
Expand Down
2 changes: 1 addition & 1 deletion ext/js/app/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -718,7 +718,7 @@ export class Popup extends EventDispatcher {
* @param {string} action
* @param {import('core').SerializableObject} params
*/
_invokeWindow(action, params={}) {
_invokeWindow(action, params = {}) {
const contentWindow = this._frame.contentWindow;
if (this._frameClient === null || !this._frameClient.isConnected() || contentWindow === null) { return; }

Expand Down
14 changes: 8 additions & 6 deletions ext/js/background/backend.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ export class Backend {
/** @type {PermissionsUtil} */
this._permissionsUtil = new PermissionsUtil();

/* eslint-disable no-multi-spaces */
/** @type {import('backend').MessageHandlerMap} */
this._messageHandlers = new Map(/** @type {import('backend').MessageHandlerMapInit} */ ([
['requestBackendReadySignal', {async: false, contentScript: true, handler: this._onApiRequestBackendReadySignal.bind(this)}],
Expand Down Expand Up @@ -193,6 +194,7 @@ export class Backend {
['loadExtensionScripts', {async: true, contentScript: true, handler: this._onApiLoadExtensionScripts.bind(this)}],
['openCrossFramePort', {async: false, contentScript: true, handler: this._onApiOpenCrossFramePort.bind(this)}]
]));
/* eslint-enable no-multi-spaces */
/** @type {import('backend').MessageHandlerWithProgressMap} */
this._messageHandlersWithProgress = new Map(/** @type {import('backend').MessageHandlerWithProgressMapInit} */ ([
// Empty
Expand All @@ -201,10 +203,10 @@ export class Backend {
/** @type {Map<string, (params?: import('core').SerializableObject) => void>} */
this._commandHandlers = new Map(/** @type {[name: string, handler: (params?: import('core').SerializableObject) => void][]} */ ([
['toggleTextScanning', this._onCommandToggleTextScanning.bind(this)],
['openInfoPage', this._onCommandOpenInfoPage.bind(this)],
['openSettingsPage', this._onCommandOpenSettingsPage.bind(this)],
['openSearchPage', this._onCommandOpenSearchPage.bind(this)],
['openPopupWindow', this._onCommandOpenPopupWindow.bind(this)]
['openInfoPage', this._onCommandOpenInfoPage.bind(this)],
['openSettingsPage', this._onCommandOpenSettingsPage.bind(this)],
['openSearchPage', this._onCommandOpenSearchPage.bind(this)],
['openPopupWindow', this._onCommandOpenPopupWindow.bind(this)]
]));
}

Expand Down Expand Up @@ -805,7 +807,7 @@ export class Backend {
}

/** @type {import('api').Handler<import('api').GetOrCreateSearchPopupDetails, import('api').GetOrCreateSearchPopupResult>} */
async _onApiGetOrCreateSearchPopup({focus=false, text}) {
async _onApiGetOrCreateSearchPopup({focus = false, text}) {
const {tab, created} = await this._getOrCreateSearchPopup();
if (focus === true || (focus === 'ifCreated' && created)) {
await this._focusTab(tab);
Expand Down Expand Up @@ -1979,7 +1981,7 @@ export class Backend {
* @param {?number} [timeout=null]
* @returns {Promise<void>}
*/
_waitUntilTabFrameIsReady(tabId, frameId, timeout=null) {
_waitUntilTabFrameIsReady(tabId, frameId, timeout = null) {
return new Promise((resolve, reject) => {
/** @type {?import('core').Timeout} */
let timer = null;
Expand Down
2 changes: 2 additions & 0 deletions ext/js/background/offscreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export class Offscreen {
richContentPasteTargetSelector: '#clipboard-rich-content-paste-target'
});

/* eslint-disable no-multi-spaces */
/** @type {import('offscreen').MessageHandlerMap} */
const messageHandlers = new Map([
['clipboardGetTextOffscreen', {async: true, handler: this._getTextHandler.bind(this)}],
Expand All @@ -65,6 +66,7 @@ export class Offscreen {
['getTermFrequenciesOffscreen', {async: true, handler: this._getTermFrequenciesHandler.bind(this)}],
['clearDatabaseCachesOffscreen', {async: false, handler: this._clearDatabaseCachesHandler.bind(this)}]
]);
/* eslint-enable no-multi-spaces */
/** @type {import('offscreen').MessageHandlerMap<string>} */
this._messageHandlers = messageHandlers;

Expand Down
10 changes: 5 additions & 5 deletions ext/js/background/profile-conditions-util.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ export class ProfileConditionsUtil {
'popupLevel',
{
operators: new Map(/** @type {import('profile-conditions-util').OperatorMapArray} */ ([
['equal', this._createSchemaPopupLevelEqual.bind(this)],
['notEqual', this._createSchemaPopupLevelNotEqual.bind(this)],
['lessThan', this._createSchemaPopupLevelLessThan.bind(this)],
['greaterThan', this._createSchemaPopupLevelGreaterThan.bind(this)],
['lessThanOrEqual', this._createSchemaPopupLevelLessThanOrEqual.bind(this)],
['equal', this._createSchemaPopupLevelEqual.bind(this)],
['notEqual', this._createSchemaPopupLevelNotEqual.bind(this)],
['lessThan', this._createSchemaPopupLevelLessThan.bind(this)],
['greaterThan', this._createSchemaPopupLevelGreaterThan.bind(this)],
['lessThanOrEqual', this._createSchemaPopupLevelLessThanOrEqual.bind(this)],
['greaterThanOrEqual', this._createSchemaPopupLevelGreaterThanOrEqual.bind(this)]
]))
}
Expand Down
2 changes: 1 addition & 1 deletion ext/js/comm/anki-connect.js
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ export class AnkiConnect {
* @param {?string[]} actions A list of actions to check for
* @returns {Promise<import('anki').ApiReflectResult>} Information about the APIs.
*/
async apiReflect(scopes, actions=null) {
async apiReflect(scopes, actions = null) {
const result = await this._invoke('apiReflect', {scopes, actions});
if (!(typeof result === 'object' && result !== null)) {
throw this._createUnexpectedResultError('object', result);
Expand Down
4 changes: 2 additions & 2 deletions ext/js/comm/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ export class API {
* @param {number} [timeout]
* @returns {Promise<TReturn>}
*/
_invokeWithProgress(action, params, onProgress0, timeout=5000) {
_invokeWithProgress(action, params, onProgress0, timeout = 5000) {
return new Promise((resolve, reject) => {
/** @type {?chrome.runtime.Port} */
let port = null;
Expand Down Expand Up @@ -554,7 +554,7 @@ export class API {
* @param {import('core').SerializableObject} [params]
* @returns {Promise<TReturn>}
*/
_invoke(action, params={}) {
_invoke(action, params = {}) {
const data = {action, params};
return new Promise((resolve, reject) => {
try {
Expand Down
2 changes: 1 addition & 1 deletion ext/js/comm/clipboard-reader.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export class ClipboardReader {
* Creates a new instances of a clipboard reader.
* @param {{document: ?Document, pasteTargetSelector: ?string, richContentPasteTargetSelector: ?string}} details Details about how to set up the instance.
*/
constructor({document=null, pasteTargetSelector=null, richContentPasteTargetSelector=null}) {
constructor({document = null, pasteTargetSelector = null, richContentPasteTargetSelector = null}) {
/** @type {?Document} */
this._document = document;
/** @type {?import('environment').Browser} */
Expand Down
2 changes: 1 addition & 1 deletion ext/js/comm/frame-ancestry-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export class FrameAncestryHandler {
* @param {number} [timeout]
* @returns {Promise<number[]>}
*/
_getFrameAncestryInfo(timeout=5000) {
_getFrameAncestryInfo(timeout = 5000) {
return new Promise((resolve, reject) => {
const targetWindow = window.parent;
if (window === targetWindow) {
Expand Down
2 changes: 1 addition & 1 deletion ext/js/comm/frame-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export class FrameClient {
* @param {import('frame-client').SetupFrameFunction} setupFrame
* @param {number} [timeout]
*/
async connect(frame, targetOrigin, hostFrameId, setupFrame, timeout=10000) {
async connect(frame, targetOrigin, hostFrameId, setupFrame, timeout = 10000) {
const {secret, token, frameId} = await this._connectInternal(frame, targetOrigin, hostFrameId, setupFrame, timeout);
this._secret = secret;
this._token = token;
Expand Down
8 changes: 4 additions & 4 deletions ext/js/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,7 @@ export class DynamicProperty extends EventDispatcher {
* @returns {import('core').TokenString} A string token which can be passed to the clearOverride function
* to remove the override.
*/
setOverride(value, priority=0) {
setOverride(value, priority = 0) {
const overridesCount = this._overrides.length;
let i = 0;
for (; i < overridesCount; ++i) {
Expand Down Expand Up @@ -670,7 +670,7 @@ export class Logger extends EventDispatcher {
* Other values will be logged at a non-error level.
* @param {?import('log').LogContext} [context] An optional context object for the error which should typically include a `url` field.
*/
log(error, level, context=null) {
log(error, level, context = null) {
if (typeof context !== 'object' || context === null) {
context = {url: location.href};
}
Expand Down Expand Up @@ -745,7 +745,7 @@ export class Logger extends EventDispatcher {
* @param {unknown} error The error to log. This is typically an `Error` or `Error`-like object.
* @param {?import('log').LogContext} context An optional context object for the error which should typically include a `url` field.
*/
warn(error, context=null) {
warn(error, context = null) {
this.log(error, 'warn', context);
}

Expand All @@ -754,7 +754,7 @@ export class Logger extends EventDispatcher {
* @param {unknown} error The error to log. This is typically an `Error` or `Error`-like object.
* @param {?import('log').LogContext} context An optional context object for the error which should typically include a `url` field.
*/
error(error, context=null) {
error(error, context = null) {
this.log(error, 'error', context);
}
}
Expand Down
24 changes: 12 additions & 12 deletions ext/js/data/anki-note-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@ export class AnkiNoteBuilder {
deckName,
modelName,
fields,
tags=[],
requirements=[],
checkForDuplicates=true,
duplicateScope='collection',
duplicateScopeCheckAllModels=false,
resultOutputMode='split',
glossaryLayoutMode='default',
compactTags=false,
mediaOptions=null
tags = [],
requirements = [],
checkForDuplicates = true,
duplicateScope = 'collection',
duplicateScopeCheckAllModels = false,
resultOutputMode = 'split',
glossaryLayoutMode = 'default',
compactTags = false,
mediaOptions = null
}) {
let duplicateScopeDeckName = null;
let duplicateScopeCheckChildren = false;
Expand Down Expand Up @@ -130,9 +130,9 @@ export class AnkiNoteBuilder {
dictionaryEntry,
mode,
context,
resultOutputMode='split',
glossaryLayoutMode='default',
compactTags=false,
resultOutputMode = 'split',
glossaryLayoutMode = 'default',
compactTags = false,
marker
}) {
const commonData = this._createData(dictionaryEntry, mode, context, resultOutputMode, glossaryLayoutMode, compactTags, void 0);
Expand Down
2 changes: 1 addition & 1 deletion ext/js/data/database.js
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ export class Database {
* @param {?(completedCount: number, totalCount: number) => void} onProgress
* @returns {Promise<void>}
*/
bulkDelete(objectStoreName, indexName, query, filterKeys=null, onProgress=null) {
bulkDelete(objectStoreName, indexName, query, filterKeys = null, onProgress = null) {
return new Promise((resolve, reject) => {
const transaction = this._readWriteTransaction([objectStoreName], resolve, reject);
const objectStore = transaction.objectStore(objectStoreName);
Expand Down
6 changes: 5 additions & 1 deletion ext/js/data/options-util.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export class OptionsUtil {
* @param {?number} [targetVersion]
* @returns {Promise<import('settings').Options>}
*/
async update(optionsInput, targetVersion=null) {
async update(optionsInput, targetVersion = null) {
// Invalid options
let options = /** @type {{[key: string]: unknown}} */ (
typeof optionsInput === 'object' && optionsInput !== null && !Array.isArray(optionsInput) ?
Expand Down Expand Up @@ -530,6 +530,7 @@ export class OptionsUtil {
* @returns {import('options-util').ModernUpdate[]}
*/
_getVersionUpdates(targetVersion) {
/* eslint-disable no-multi-spaces */
const result = [
{async: false, update: this._updateVersion1.bind(this)},
{async: false, update: this._updateVersion2.bind(this)},
Expand All @@ -553,6 +554,7 @@ export class OptionsUtil {
{async: false, update: this._updateVersion20.bind(this)},
{async: true, update: this._updateVersion21.bind(this)}
];
/* eslint-enable no-multi-spaces */
if (typeof targetVersion === 'number' && targetVersion < result.length) {
result.splice(targetVersion);
}
Expand Down Expand Up @@ -818,6 +820,7 @@ export class OptionsUtil {
};
delete profile.options.anki.sentenceExt;
profile.options.general.popupActionBarLocation = 'top';
/* eslint-disable no-multi-spaces */
profile.options.inputs = {
hotkeys: [
{action: 'close', key: 'Escape', modifiers: [], scopes: ['popup'], enabled: true},
Expand All @@ -838,6 +841,7 @@ export class OptionsUtil {
{action: 'copyHostSelection', key: 'KeyC', modifiers: ['ctrl'], scopes: ['popup'], enabled: true}
]
};
/* eslint-enable no-multi-spaces */
profile.options.anki.suspendNewCards = false;
profile.options.popupWindow = {
width: profile.options.general.popupWidth,
Expand Down
Loading
Loading