chore: adjust prettier config, .gitignore and use taplo to format toml files (#1728)

* chore: adjust prettier config, .gitignore and use taplo to format toml files

This brings the plugins-workspace repository to the same code style of the main tauri repo

* format toml

* ignore examples gen dir

* add .vscode/extensions.json

* remove packageManager field

* fmt

* fix audit

* taplo ignore permissions autogenerated files

* remove create dummy dist

* fix prettier workflow

* install fmt in prettier workflow

---------

Co-authored-by: Lucas Nogueira <lucas@tauri.app>
This commit is contained in:
Amr Bashir
2024-09-04 14:54:23 +03:00
committed by GitHub
parent 72c2ce82c1
commit cf4d7d4e6c
227 changed files with 2534 additions and 2505 deletions
+49 -49
View File
@@ -2,13 +2,13 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT
import { invoke } from "@tauri-apps/api/core";
import { listen, type UnlistenFn, type Event } from "@tauri-apps/api/event";
import { invoke } from '@tauri-apps/api/core'
import { listen, type UnlistenFn, type Event } from '@tauri-apps/api/event'
export interface LogOptions {
file?: string;
line?: number;
keyValues?: Record<string, string | undefined>;
file?: string
line?: number
keyValues?: Record<string, string | undefined>
}
enum LogLevel {
@@ -41,35 +41,35 @@ enum LogLevel {
*
* Designates very serious errors.
*/
Error,
Error
}
async function log(
level: LogLevel,
message: string,
options?: LogOptions,
options?: LogOptions
): Promise<void> {
const traces = new Error().stack?.split("\n").map((line) => line.split("@"));
const traces = new Error().stack?.split('\n').map((line) => line.split('@'))
const filtered = traces?.filter(([name, location]) => {
return name.length > 0 && location !== "[native code]";
});
return name.length > 0 && location !== '[native code]'
})
const { file, line, keyValues } = options ?? {};
const { file, line, keyValues } = options ?? {}
let location = filtered?.[0]?.filter((v) => v.length > 0).join("@");
if (location === "Error") {
location = "webview::unknown";
let location = filtered?.[0]?.filter((v) => v.length > 0).join('@')
if (location === 'Error') {
location = 'webview::unknown'
}
await invoke("plugin:log|log", {
await invoke('plugin:log|log', {
level,
message,
location,
file,
line,
keyValues,
});
keyValues
})
}
/**
@@ -90,9 +90,9 @@ async function log(
*/
export async function error(
message: string,
options?: LogOptions,
options?: LogOptions
): Promise<void> {
await log(LogLevel.Error, message, options);
await log(LogLevel.Error, message, options)
}
/**
@@ -112,9 +112,9 @@ export async function error(
*/
export async function warn(
message: string,
options?: LogOptions,
options?: LogOptions
): Promise<void> {
await log(LogLevel.Warn, message, options);
await log(LogLevel.Warn, message, options)
}
/**
@@ -134,9 +134,9 @@ export async function warn(
*/
export async function info(
message: string,
options?: LogOptions,
options?: LogOptions
): Promise<void> {
await log(LogLevel.Info, message, options);
await log(LogLevel.Info, message, options)
}
/**
@@ -156,9 +156,9 @@ export async function info(
*/
export async function debug(
message: string,
options?: LogOptions,
options?: LogOptions
): Promise<void> {
await log(LogLevel.Debug, message, options);
await log(LogLevel.Debug, message, options)
}
/**
@@ -178,17 +178,17 @@ export async function debug(
*/
export async function trace(
message: string,
options?: LogOptions,
options?: LogOptions
): Promise<void> {
await log(LogLevel.Trace, message, options);
await log(LogLevel.Trace, message, options)
}
interface RecordPayload {
level: LogLevel;
message: string;
level: LogLevel
message: string
}
type LoggerFn = (fn: RecordPayload) => void;
type LoggerFn = (fn: RecordPayload) => void
/**
* Attaches a listener for the log, and calls the passed function for each log entry.
@@ -197,19 +197,19 @@ type LoggerFn = (fn: RecordPayload) => void;
* @returns a function to cancel the listener.
*/
export async function attachLogger(fn: LoggerFn): Promise<UnlistenFn> {
return await listen("log://log", (event: Event<RecordPayload>) => {
const { level } = event.payload;
let { message } = event.payload;
return await listen('log://log', (event: Event<RecordPayload>) => {
const { level } = event.payload
let { message } = event.payload
// Strip ANSI escape codes
message = message.replace(
// TODO: Investigate security/detect-unsafe-regex
// eslint-disable-next-line no-control-regex, security/detect-unsafe-regex
/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g,
"",
);
fn({ message, level });
});
''
)
fn({ message, level })
})
}
/**
@@ -221,23 +221,23 @@ export async function attachConsole(): Promise<UnlistenFn> {
return await attachLogger(({ level, message }: RecordPayload) => {
switch (level) {
case LogLevel.Trace:
console.log(message);
break;
console.log(message)
break
case LogLevel.Debug:
console.debug(message);
break;
console.debug(message)
break
case LogLevel.Info:
console.info(message);
break;
console.info(message)
break
case LogLevel.Warn:
console.warn(message);
break;
console.warn(message)
break
case LogLevel.Error:
console.error(message);
break;
console.error(message)
break
default:
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
throw new Error(`unknown log level ${level}`);
throw new Error(`unknown log level ${level}`)
}
});
})
}