🚨 Format code
This commit is contained in:
@@ -78,7 +78,7 @@ _69: () => {
|
||||
_70: () => {
|
||||
return typeof process != "undefined" &&
|
||||
Object.prototype.toString.call(process) == "[object process]" &&
|
||||
process.platform == "win32"
|
||||
process.platform == "win32";
|
||||
},
|
||||
_85: s => JSON.stringify(s),
|
||||
_86: s => printToConsole(s),
|
||||
@@ -126,7 +126,7 @@ _157: Function.prototype.call.bind(DataView.prototype.setFloat32),
|
||||
_158: Function.prototype.call.bind(DataView.prototype.getFloat64),
|
||||
_159: Function.prototype.call.bind(DataView.prototype.setFloat64),
|
||||
_165: x0 => format = x0,
|
||||
_166: f => finalizeWrapper(f, function(x0,x1,x2) { return dartInstance.exports._166(f,arguments.length,x0,x1,x2) }),
|
||||
_166: f => finalizeWrapper(f, function(x0,x1,x2) { return dartInstance.exports._166(f,arguments.length,x0,x1,x2); }),
|
||||
_184: (c) =>
|
||||
queueMicrotask(() => dartInstance.exports.$invokeCallback(c)),
|
||||
_187: (s, m) => {
|
||||
@@ -337,14 +337,14 @@ _272: (x0,x1) => x0.lastIndex = x1
|
||||
});
|
||||
|
||||
return dartInstance;
|
||||
}
|
||||
};
|
||||
|
||||
// Call the main function for the instantiated module
|
||||
// `moduleInstance` is the instantiated dart2wasm module
|
||||
// `args` are any arguments that should be passed into the main function.
|
||||
export const invoke = (moduleInstance, ...args) => {
|
||||
moduleInstance.exports.$invokeMain(args);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
export let format;
|
||||
@@ -1,5 +1,5 @@
|
||||
import type { Plugin, SupportLanguage, Parser, Printer, SupportOption } from 'prettier'
|
||||
import dockerfileInit, { format } from './docker_fmt_vite.js'
|
||||
import type { Plugin, SupportLanguage, Parser, Printer, SupportOption } from 'prettier';
|
||||
import dockerfileInit, { format } from './docker_fmt_vite.js';
|
||||
|
||||
// Language configuration for Dockerfile
|
||||
const languages: SupportLanguage[] = [
|
||||
@@ -11,7 +11,7 @@ const languages: SupportLanguage[] = [
|
||||
linguistLanguageId: 99,
|
||||
vscodeLanguageIds: ['dockerfile'],
|
||||
},
|
||||
]
|
||||
];
|
||||
|
||||
// Parser configuration
|
||||
const parsers: Record<string, Parser<any>> = {
|
||||
@@ -19,69 +19,60 @@ const parsers: Record<string, Parser<any>> = {
|
||||
parse: (text: string) => {
|
||||
// For Dockerfile, we don't need complex parsing, just return the text
|
||||
// The formatting will be handled by the print function
|
||||
return { type: 'dockerfile', value: text }
|
||||
return { type: 'dockerfile', value: text };
|
||||
},
|
||||
astFormat: 'dockerfile',
|
||||
locStart: () => 0,
|
||||
locEnd: () => 0,
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
// Printer configuration
|
||||
const printers: Record<string, Printer<any>> = {
|
||||
dockerfile: {
|
||||
// @ts-expect-error -- Support async printer like shell plugin
|
||||
async print(path: any, options: any) {
|
||||
await ensureInitialized()
|
||||
const text = path.getValue().value || path.getValue()
|
||||
await ensureInitialized();
|
||||
const text = path.getValue().value || path.getValue();
|
||||
|
||||
try {
|
||||
const formatted = format(text, {
|
||||
indent: options.tabWidth || 2,
|
||||
trailingNewline: true,
|
||||
spaceRedirects: options.spaceRedirects !== false,
|
||||
})
|
||||
return formatted
|
||||
});
|
||||
return formatted;
|
||||
} catch (error) {
|
||||
console.warn('Dockerfile formatting error:', error)
|
||||
return text
|
||||
console.warn('Dockerfile formatting error:', error);
|
||||
return text;
|
||||
}
|
||||
},
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
// WASM initialization
|
||||
let isInitialized = false
|
||||
let initPromise: Promise<void> | null = null
|
||||
let isInitialized = false;
|
||||
let initPromise: Promise<void> | null = null;
|
||||
|
||||
async function ensureInitialized(): Promise<void> {
|
||||
if (isInitialized) {
|
||||
return Promise.resolve()
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
if (!initPromise) {
|
||||
initPromise = (async () => {
|
||||
try {
|
||||
await dockerfileInit()
|
||||
isInitialized = true
|
||||
await dockerfileInit();
|
||||
isInitialized = true;
|
||||
} catch (error) {
|
||||
console.warn('Failed to initialize Dockerfile WASM module:', error)
|
||||
initPromise = null
|
||||
throw error
|
||||
console.warn('Failed to initialize Dockerfile WASM module:', error);
|
||||
initPromise = null;
|
||||
throw error;
|
||||
}
|
||||
})()
|
||||
})();
|
||||
}
|
||||
|
||||
return initPromise
|
||||
}
|
||||
|
||||
// Configuration mapping function
|
||||
function mapOptionsToConfig(options: any) {
|
||||
return {
|
||||
indent: options.tabWidth || 2,
|
||||
trailingNewline: options.insertFinalNewline !== false,
|
||||
spaceRedirects: options.spaceRedirects !== false,
|
||||
}
|
||||
return initPromise;
|
||||
}
|
||||
|
||||
// Plugin options
|
||||
@@ -92,7 +83,7 @@ const options: Record<string, SupportOption> = {
|
||||
default: true,
|
||||
description: 'Add spaces around redirect operators',
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
// Plugin definition
|
||||
const plugin: Plugin = {
|
||||
@@ -105,7 +96,7 @@ const plugin: Plugin = {
|
||||
useTabs: false,
|
||||
spaceRedirects: true,
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
export default plugin
|
||||
export { languages, parsers, printers, options }
|
||||
export default plugin;
|
||||
export { languages, parsers, printers, options };
|
||||
@@ -60,7 +60,7 @@ function initGofmt(): Promise<void> {
|
||||
// Printer configuration
|
||||
const goPrinter: Printer<string> = {
|
||||
// @ts-expect-error -- Support async printer like shell plugin
|
||||
async print(path, options) {
|
||||
async print(path, _options) {
|
||||
try {
|
||||
// Wait for initialization to complete
|
||||
await initGofmt();
|
||||
|
||||
@@ -39,7 +39,7 @@ const groovyPrinter: Printer<string> = {
|
||||
return groovyBeautify(path.node, {
|
||||
width: options.printWidth || 80,
|
||||
}).trim();
|
||||
} catch (error) {
|
||||
} catch (_error) {
|
||||
return path.node;
|
||||
}
|
||||
},
|
||||
|
||||
@@ -58,7 +58,7 @@ type ModifierNode = JavaNonTerminal & {
|
||||
annotation?: AnnotationCstNode[];
|
||||
};
|
||||
};
|
||||
type IsTuple<T> = T extends [] ? true : T extends [infer First, ...infer Remain] ? IsTuple<Remain> : false;
|
||||
type IsTuple<T> = T extends [] ? true : T extends [infer _First, ...infer Remain] ? IsTuple<Remain> : false;
|
||||
type IndexProperties<T extends {
|
||||
length: number;
|
||||
}> = IsTuple<T> extends true ? Exclude<Partial<T>["length"], T["length"]> : number;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
|
||||
export function format(input: string, filename: string, config?: Config): string;
|
||||
|
||||
interface LayoutConfig {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
|
||||
export const memory: WebAssembly.Memory;
|
||||
export const format: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
|
||||
export const __wbindgen_export_0: (a: number, b: number) => number;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
|
||||
export function format(input: string, path?: string, config?: Config): string;
|
||||
|
||||
export interface Config {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
|
||||
export const memory: WebAssembly.Memory;
|
||||
export const format: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
|
||||
export const __wbindgen_export_0: (a: number, b: number) => number;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
|
||||
export function format(input: string, config?: Config | null): string;
|
||||
|
||||
export interface Config {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
|
||||
export const memory: WebAssembly.Memory;
|
||||
export const format: (a: number, b: number, c: number, d: number) => void;
|
||||
export const __wbindgen_export_0: (a: number, b: number) => number;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import _fs from 'node:fs'
|
||||
import _fs from 'node:fs';
|
||||
|
||||
declare global {
|
||||
namespace globalThis {
|
||||
var fs: typeof _fs
|
||||
let fs: typeof _fs;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
|
||||
export function format(input: string, filename: string, config?: Config): string;
|
||||
|
||||
interface LayoutConfig {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
|
||||
export const memory: WebAssembly.Memory;
|
||||
export const format: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
|
||||
export const __wbindgen_export_0: (a: number, b: number) => number;
|
||||
|
||||
@@ -23,7 +23,6 @@ import type {
|
||||
TomlDocument,
|
||||
TomlExpression,
|
||||
TomlKeyVal,
|
||||
TomlComment,
|
||||
TomlContext
|
||||
} from './types';
|
||||
|
||||
@@ -221,11 +220,11 @@ class TomlBeautifierVisitor extends BaseTomlCstVisitor {
|
||||
} else {
|
||||
return this.visit(actualValueNode);
|
||||
}
|
||||
} catch (error) {
|
||||
} catch (_error) {
|
||||
// 如果getSingle失败,尝试直接处理children
|
||||
if (ctx.children) {
|
||||
// 处理不同类型的值
|
||||
for (const [childKey, childNodes] of Object.entries(ctx.children)) {
|
||||
for (const [_childKey, childNodes] of Object.entries(ctx.children)) {
|
||||
if (Array.isArray(childNodes) && childNodes.length > 0) {
|
||||
const firstChild = childNodes[0];
|
||||
|
||||
@@ -385,14 +384,14 @@ class TomlBeautifierVisitor extends BaseTomlCstVisitor {
|
||||
/**
|
||||
* Visit newline (should not be called)
|
||||
*/
|
||||
nl(ctx: any): never {
|
||||
nl(_ctx: any): never {
|
||||
throw new Error('Should not get here!');
|
||||
}
|
||||
|
||||
/**
|
||||
* Visit comment newline (no-op)
|
||||
*/
|
||||
commentNewline(ctx: any): void {
|
||||
commentNewline(_ctx: any): void {
|
||||
// No operation needed
|
||||
}
|
||||
}
|
||||
@@ -407,7 +406,7 @@ const beautifierVisitor = new TomlBeautifierVisitor();
|
||||
* @param print - Print function (unused in this implementation)
|
||||
* @returns Formatted document
|
||||
*/
|
||||
export function print(path: AstPath<TomlCstNode>, options?: any, print?: any): Doc {
|
||||
export function print(path: AstPath<TomlCstNode>, _options?: any, _print?: any): Doc {
|
||||
const cst = path.node as TomlDocument;
|
||||
return beautifierVisitor.visit(cst);
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
* This plugin provides support for formatting multiple web languages using the web_fmt WASM implementation.
|
||||
* web_fmt is a comprehensive formatter for web development supporting HTML, CSS, JavaScript, and JSON.
|
||||
*/
|
||||
import type { Plugin, Parser, Printer, ParserOptions } from 'prettier';
|
||||
import type { Plugin, Parser, Printer } from 'prettier';
|
||||
|
||||
// Import the web_fmt WASM module
|
||||
import webInit, { format } from './web_fmt_vite.js';
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
|
||||
export function format_json(src: string, config?: JsonConfig): string;
|
||||
export function format_markup(src: string, filename: string, config?: MarkupConfig): string;
|
||||
export function format_script(src: string, filename: string, config?: ScriptConfig): string;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
|
||||
export const memory: WebAssembly.Memory;
|
||||
export const format_json: (a: number, b: number, c: number, d: number) => void;
|
||||
export const format_markup: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
|
||||
|
||||
Reference in New Issue
Block a user