1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-06-27 23:28:38 +02:00

Tools: Apply rule @typescript-eslint/type-annotation-spacing

This commit is contained in:
Laurent Cozic
2020-11-12 19:13:28 +00:00
parent 62feb7ff60
commit d20694e52c
291 changed files with 2205 additions and 2203 deletions

View File

@ -13,10 +13,10 @@ const builtinModules = require('builtin-modules');
export default class Global {
private joplin_: Joplin;
private requireWhiteList_:string[] = null;
private requireWhiteList_: string[] = null;
// private consoleWrapper_:any = null;
constructor(logger:Logger, implementation:any, plugin: Plugin, store: any) {
constructor(logger: Logger, implementation: any, plugin: Plugin, store: any) {
this.joplin_ = new Joplin(logger, implementation.joplin, plugin, store);
// this.consoleWrapper_ = this.createConsoleWrapper(plugin.id);
}
@ -41,7 +41,7 @@ export default class Global {
return this.joplin_;
}
private requireWhiteList():string[] {
private requireWhiteList(): string[] {
if (!this.requireWhiteList_) {
this.requireWhiteList_ = builtinModules.slice();
this.requireWhiteList_.push('fs-extra');
@ -53,7 +53,7 @@ export default class Global {
// return this.consoleWrapper_;
// }
require(filePath:string):any {
require(filePath: string): any {
if (!this.requireWhiteList().includes(filePath)) throw new Error(`Path not allowed: ${filePath}`);
return require(filePath);
}
@ -61,7 +61,7 @@ export default class Global {
// To get webpack to work with Node module we need to set the parameter `target: "node"`, however
// when setting this, the code generated by webpack will try to access the `process` global variable,
// which won't be defined in the sandbox. So here we simply forward the variable, which makes it all work.
get process():any {
get process(): any {
return process;
}

View File

@ -23,7 +23,7 @@ export default class Joplin {
private interop_: JoplinInterop = null;
private settings_: JoplinSettings = null;
constructor(logger:Logger, implementation:any, plugin: Plugin, store: any) {
constructor(logger: Logger, implementation: any, plugin: Plugin, store: any) {
this.data_ = new JoplinData();
this.plugins_ = new JoplinPlugins(logger, plugin);
this.workspace_ = new JoplinWorkspace(implementation.workspace, store);

View File

@ -43,7 +43,7 @@ export default class JoplinCommands {
* await joplin.commands.execute('newFolder', "SOME_FOLDER_ID");
* ```
*/
async execute(commandName: string, ...args:any[]):Promise<any | void> {
async execute(commandName: string, ...args: any[]): Promise<any | void> {
return CommandService.instance().execute(commandName, ...args);
}
@ -63,16 +63,16 @@ export default class JoplinCommands {
* });
* ```
*/
async register(command:Command) {
const declaration:CommandDeclaration = {
async register(command: Command) {
const declaration: CommandDeclaration = {
name: command.name,
label: command.label,
};
if ('iconName' in command) declaration.iconName = command.iconName;
const runtime:CommandRuntime = {
execute: (_context:CommandContext, ...args:any[]) => {
const runtime: CommandRuntime = {
execute: (_context: CommandContext, ...args: any[]) => {
return command.execute(...args);
},
};

View File

@ -40,14 +40,14 @@ import { Path } from './types';
export default class JoplinData {
private api_: any = new Api();
private pathSegmentRegex_:RegExp;
private pathSegmentRegex_: RegExp;
private serializeApiBody(body: any) {
if (typeof body !== 'string') { return JSON.stringify(body); }
return body;
}
private pathToString(path:Path):string {
private pathToString(path: Path): string {
if (!this.pathSegmentRegex_) {
this.pathSegmentRegex_ = /^([a-z0-9]+)$/;
}

View File

@ -16,8 +16,8 @@ import { ExportModule, ImportModule } from './types';
*/
export default class JoplinInterop {
async registerExportModule(module:ExportModule) {
const internalModule:Module = {
async registerExportModule(module: ExportModule) {
const internalModule: Module = {
...module,
type: ModuleType.Exporter,
isCustom: true,
@ -27,8 +27,8 @@ export default class JoplinInterop {
return InteropService.instance().registerModule(internalModule);
}
async registerImportModule(module:ImportModule) {
const internalModule:Module = {
async registerImportModule(module: ImportModule) {
const internalModule: Module = {
...module,
type: ModuleType.Importer,
isCustom: true,

View File

@ -10,7 +10,7 @@ export default class JoplinPlugins {
private logger: Logger;
private plugin: Plugin;
public constructor(logger:Logger, plugin:Plugin) {
public constructor(logger: Logger, plugin: Plugin) {
this.logger = logger;
this.plugin = plugin;
}
@ -36,11 +36,11 @@ export default class JoplinPlugins {
// We don't use `await` when calling onStart because the plugin might be awaiting
// in that call too (for example, when opening a dialog on startup) so we don't
// want to get stuck here.
script.onStart({}).catch((error:any) => {
script.onStart({}).catch((error: any) => {
// For some reason, error thrown from the executed script do not have the type "Error"
// but are instead plain object. So recreate the Error object here so that it can
// be handled correctly by loggers, etc.
const newError:Error = new Error(error.message);
const newError: Error = new Error(error.message);
newError.stack = error.stack;
this.logger.error(`In plugin ${this.plugin.id}:`, newError);
}).then(() => {
@ -63,7 +63,7 @@ export default class JoplinPlugins {
* @param id A unique ID for the content script.
* @param scriptPath Must be a path relative to the plugin main script. For example, if your file content_script.js is next to your index.ts file, you would set `scriptPath` to `"./content_script.js`.
*/
async registerContentScript(type:ContentScriptType, id:string, scriptPath:string) {
async registerContentScript(type: ContentScriptType, id: string, scriptPath: string) {
return this.plugin.registerContentScript(type, id, scriptPath);
}
}

View File

@ -12,7 +12,7 @@ import { SettingItem, SettingSection } from './types';
* [View the demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/settings)
*/
export default class JoplinSettings {
private plugin_:Plugin = null;
private plugin_: Plugin = null;
constructor(plugin: Plugin) {
this.plugin_ = plugin;
@ -20,7 +20,7 @@ export default class JoplinSettings {
// Ensures that the plugin settings and sections are within their own namespace, to prevent them from
// overwriting other plugin settings or the default settings.
private namespacedKey(key:string):string {
private namespacedKey(key: string): string {
return `plugin-${this.plugin_.id}.${key}`;
}
@ -30,14 +30,14 @@ export default class JoplinSettings {
* The setting value however will be preserved from one launch to the next so there is no risk that it will be lost even if for some
* reason the plugin fails to start at some point.
*/
async registerSetting(key:string, settingItem:SettingItem) {
const internalSettingItem:InternalSettingItem = {
async registerSetting(key: string, settingItem: SettingItem) {
const internalSettingItem: InternalSettingItem = {
key: key,
value: settingItem.value,
type: settingItem.type,
public: settingItem.public,
label: () => settingItem.label,
description: (_appType:string) => settingItem.description,
description: (_appType: string) => settingItem.description,
};
if ('isEnum' in settingItem) internalSettingItem.isEnum = settingItem.isEnum;
@ -56,21 +56,21 @@ export default class JoplinSettings {
/**
* Registers a new setting section. Like for registerSetting, it is dynamic and needs to be done every time the plugin starts.
*/
async registerSection(name:string, section:SettingSection) {
async registerSection(name: string, section: SettingSection) {
return Setting.registerSection(this.namespacedKey(name), section);
}
/**
* Gets a setting value (only applies to setting you registered from your plugin)
*/
async value(key:string):Promise<any> {
async value(key: string): Promise<any> {
return Setting.value(this.namespacedKey(key));
}
/**
* Sets a setting value (only applies to setting you registered from your plugin)
*/
async setValue(key:string, value:any) {
async setValue(key: string, value: any) {
return Setting.setValue(this.namespacedKey(key), value);
}
@ -81,7 +81,7 @@ export default class JoplinSettings {
*
* https://github.com/laurent22/joplin/blob/3539a452a359162c461d2849829d2d42973eab50/packages/app-mobile/lib/models/Setting.ts#L142
*/
async globalValue(key:string):Promise<any> {
async globalValue(key: string): Promise<any> {
return Setting.value(key);
}
}

View File

@ -16,40 +16,40 @@ export default class JoplinViews {
private store: any;
private plugin: Plugin;
private dialogs_:JoplinViewsDialogs = null;
private panels_:JoplinViewsPanels = null;
private menuItems_:JoplinViewsMenuItems = null;
private menus_:JoplinViewsMenus = null;
private toolbarButtons_:JoplinViewsToolbarButtons = null;
private implementation_:any = null;
private dialogs_: JoplinViewsDialogs = null;
private panels_: JoplinViewsPanels = null;
private menuItems_: JoplinViewsMenuItems = null;
private menus_: JoplinViewsMenus = null;
private toolbarButtons_: JoplinViewsToolbarButtons = null;
private implementation_: any = null;
constructor(implementation:any, plugin: Plugin, store: any) {
constructor(implementation: any, plugin: Plugin, store: any) {
this.store = store;
this.plugin = plugin;
this.implementation_ = implementation;
}
public get dialogs():JoplinViewsDialogs {
public get dialogs(): JoplinViewsDialogs {
if (!this.dialogs_) this.dialogs_ = new JoplinViewsDialogs(this.implementation_.dialogs, this.plugin, this.store);
return this.dialogs_;
}
public get panels():JoplinViewsPanels {
public get panels(): JoplinViewsPanels {
if (!this.panels_) this.panels_ = new JoplinViewsPanels(this.plugin, this.store);
return this.panels_;
}
public get menuItems():JoplinViewsMenuItems {
public get menuItems(): JoplinViewsMenuItems {
if (!this.menuItems_) this.menuItems_ = new JoplinViewsMenuItems(this.plugin, this.store);
return this.menuItems_;
}
public get menus():JoplinViewsMenus {
public get menus(): JoplinViewsMenus {
if (!this.menus_) this.menus_ = new JoplinViewsMenus(this.plugin, this.store);
return this.menus_;
}
public get toolbarButtons():JoplinViewsToolbarButtons {
public get toolbarButtons(): JoplinViewsToolbarButtons {
if (!this.toolbarButtons_) this.toolbarButtons_ = new JoplinViewsToolbarButtons(this.plugin, this.store);
return this.toolbarButtons_;
}

View File

@ -14,22 +14,22 @@ export default class JoplinViewsDialogs {
private store: any;
private plugin: Plugin;
private implementation_:any;
private implementation_: any;
constructor(implementation:any, plugin: Plugin, store: any) {
constructor(implementation: any, plugin: Plugin, store: any) {
this.store = store;
this.plugin = plugin;
this.implementation_ = implementation;
}
private controller(handle:ViewHandle):WebviewController {
private controller(handle: ViewHandle): WebviewController {
return this.plugin.viewController(handle) as WebviewController;
}
/**
* Creates a new dialog
*/
async create():Promise<ViewHandle> {
async create(): Promise<ViewHandle> {
const handle = createViewHandle(this.plugin);
const controller = new WebviewController(handle, this.plugin.id, this.store, this.plugin.baseDir);
controller.containerType = ContainerType.Dialog;
@ -40,28 +40,28 @@ export default class JoplinViewsDialogs {
/**
* Displays a message box with OK/Cancel buttons. Returns the button index that was clicked - "0" for OK and "1" for "Cancel"
*/
async showMessageBox(message:string):Promise<number> {
async showMessageBox(message: string): Promise<number> {
return this.implementation_.showMessageBox(message);
}
/**
* Sets the dialog HTML content
*/
async setHtml(handle:ViewHandle, html:string) {
async setHtml(handle: ViewHandle, html: string) {
return this.controller(handle).html = html;
}
/**
* Sets the dialog buttons.
*/
async setButtons(handle:ViewHandle, buttons:ButtonSpec[]) {
async setButtons(handle: ViewHandle, buttons: ButtonSpec[]) {
return this.controller(handle).buttons = buttons;
}
/**
* Opens the dialog
*/
async open(handle:ViewHandle):Promise<ButtonId> {
async open(handle: ViewHandle): Promise<ButtonId> {
return this.controller(handle).open();
}

View File

@ -22,7 +22,7 @@ export default class JoplinViewsMenuItems {
/**
* Creates a new menu item and associate it with the given command. You can specify under which menu the item should appear using the `location` parameter.
*/
async create(commandName:string, location:MenuItemLocation = MenuItemLocation.Tools, options:CreateMenuItemOptions = null) {
async create(commandName: string, location: MenuItemLocation = MenuItemLocation.Tools, options: CreateMenuItemOptions = null) {
const handle = createViewHandle(this.plugin);
const controller = new MenuItemController(handle, this.plugin.id, this.store, commandName, location);
this.plugin.addViewController(controller);

View File

@ -19,7 +19,7 @@ export default class JoplinViewsMenus {
this.plugin = plugin;
}
private registerCommandAccelerators(menuItems:MenuItem[]) {
private registerCommandAccelerators(menuItems: MenuItem[]) {
for (const menuItem of menuItems) {
if (menuItem.accelerator) {
KeymapService.instance().registerCommandAccelerator(menuItem.commandName, menuItem.accelerator);
@ -35,7 +35,7 @@ export default class JoplinViewsMenus {
* Creates a new menu from the provided menu items and place it at the given location. As of now, it is only possible to place the
* menu as a sub-menu of the application build-in menus.
*/
public async create(label:string, menuItems:MenuItem[], location:MenuItemLocation = MenuItemLocation.Tools) {
public async create(label: string, menuItems: MenuItem[], location: MenuItemLocation = MenuItemLocation.Tools) {
const handle = createViewHandle(this.plugin);
const controller = new MenuController(handle, this.plugin.id, this.store, label, menuItems, location);
this.plugin.addViewController(controller);

View File

@ -19,14 +19,14 @@ export default class JoplinViewsPanels {
this.plugin = plugin;
}
private controller(handle:ViewHandle):WebviewController {
private controller(handle: ViewHandle): WebviewController {
return this.plugin.viewController(handle) as WebviewController;
}
/**
* Creates a new panel
*/
async create():Promise<ViewHandle> {
async create(): Promise<ViewHandle> {
const handle = createViewHandle(this.plugin);
const controller = new WebviewController(handle, this.plugin.id, this.store, this.plugin.baseDir);
this.plugin.addViewController(controller);
@ -36,21 +36,21 @@ export default class JoplinViewsPanels {
/**
* Sets the panel webview HTML
*/
async setHtml(handle:ViewHandle, html:string) {
async setHtml(handle: ViewHandle, html: string) {
return this.controller(handle).html = html;
}
/**
* Adds and loads a new JS or CSS files into the panel.
*/
async addScript(handle:ViewHandle, scriptPath:string) {
async addScript(handle: ViewHandle, scriptPath: string) {
return this.controller(handle).addScript(scriptPath);
}
/**
* Called when a message is sent from the webview (using postMessage).
*/
async onMessage(handle:ViewHandle, callback:Function) {
async onMessage(handle: ViewHandle, callback: Function) {
return this.controller(handle).onMessage(callback);
}

View File

@ -21,7 +21,7 @@ export default class JoplinViewsToolbarButtons {
/**
* Creates a new toolbar button and associate it with the given command.
*/
async create(commandName:string, location:ToolbarButtonLocation) {
async create(commandName: string, location: ToolbarButtonLocation) {
const handle = createViewHandle(this.plugin);
const controller = new ToolbarButtonController(handle, this.plugin.id, this.store, commandName, location);
this.plugin.addViewController(controller);

View File

@ -17,7 +17,7 @@ export default class JoplinWorkspace {
private store: any;
// private implementation_:any;
constructor(_implementation:any, store: any) {
constructor(_implementation: any, store: any) {
this.store = store;
// this.implementation_ = implementation;
}
@ -39,21 +39,21 @@ export default class JoplinWorkspace {
/**
* Called when an alarm associated with a to-do is triggered.
*/
async onNoteAlarmTrigger(callback:Function) {
async onNoteAlarmTrigger(callback: Function) {
eventManager.on('noteAlarmTrigger', callback);
}
/**
* Called when the synchronisation process has finished.
*/
async onSyncComplete(callback:Function) {
async onSyncComplete(callback: Function) {
eventManager.on('syncComplete', callback);
}
/**
* Gets the currently selected note
*/
async selectedNote():Promise<any> {
async selectedNote(): Promise<any> {
const noteIds = this.store.getState().selectedNoteIds;
if (noteIds.length !== 1) { return null; }
return Note.load(noteIds[0]);
@ -62,7 +62,7 @@ export default class JoplinWorkspace {
/**
* Gets the IDs of the selected notes (can be zero, one, or many). Use the data API to retrieve information about these notes.
*/
async selectedNoteIds():Promise<string[]> {
async selectedNoteIds(): Promise<string[]> {
return this.store.getState().selectedNoteIds.slice();
}
}

View File

@ -24,7 +24,7 @@ export interface Command {
/**
* Code to be ran when the command is executed. It may return a result.
*/
execute(...args:any[]):Promise<any | void>
execute(...args: any[]): Promise<any | void>
/**
* Defines whether the command should be enabled or disabled, which in turns affects
@ -99,22 +99,22 @@ export interface ExportModule {
/**
* Called when the export process starts.
*/
onInit(context:ExportContext): Promise<void>;
onInit(context: ExportContext): Promise<void>;
/**
* Called when an item needs to be processed. An "item" can be any Joplin object, such as a note, a folder, a notebook, etc.
*/
onProcessItem(context:ExportContext, itemType:number, item:any):Promise<void>;
onProcessItem(context: ExportContext, itemType: number, item: any): Promise<void>;
/**
* Called when a resource file needs to be exported.
*/
onProcessResource(context:ExportContext, resource:any, filePath:string):Promise<void>;
onProcessResource(context: ExportContext, resource: any, filePath: string): Promise<void>;
/**
* Called when the export process is done.
*/
onClose(context:ExportContext):Promise<void>;
onClose(context: ExportContext): Promise<void>;
}
export interface ImportModule {
@ -153,16 +153,16 @@ export interface ImportModule {
/**
* Called when the import process starts. There is only one event handler within which you should import the complete data.
*/
onExec(context:ImportContext): Promise<void>;
onExec(context: ImportContext): Promise<void>;
}
export interface ExportOptions {
format?: string,
path?:string,
path?: string,
sourceFolderIds?: string[],
sourceNoteIds?: string[],
modulePath?:string,
target?:FileSystemItem,
modulePath?: string,
target?: FileSystemItem,
}
export interface ExportContext {
@ -186,7 +186,7 @@ export interface ImportContext {
// =================================================================
export interface Script {
onStart?(event:any):Promise<void>,
onStart?(event: any): Promise<void>,
}
// =================================================================
@ -237,7 +237,7 @@ export interface MenuItem {
export interface ButtonSpec {
id: ButtonId,
title?: string,
onClick?():void,
onClick?(): void,
}
export type ButtonId = string;
@ -280,13 +280,13 @@ export interface SettingItem {
value: any,
type: SettingItemType,
public: boolean,
label:string,
label: string,
description?:string,
description?: string,
isEnum?: boolean,
section?: string,
options?:any,
appTypes?:string[],
options?: any,
appTypes?: string[],
secure?: boolean,
advanced?: boolean,
minimum?: number,