chore: Fix lint error on main
Fixes the lint error that a function has too many arguments on main.
MODIFY
website/playground/README.md
website/playground/README.md
@@ -21,3 +21,12 @@ Then, if you want to run in development
pnpm install # if you haven't ran this yet
pnpm start
```
+
+
+## Tips
+1. You could add this option in `./cargo.toml`
+```toml
+[package.metadata.wasm-pack.profile.release]
+wasm-opt = false
+```
+this could accelerate your wasm compiler time during development, but don't forget to remove it when you make a pull request.
\ No newline at end of file

MODIFY
website/playground/src/App.tsx
website/playground/src/App.tsx
import "react-tabs/style/react-tabs.css";
-import init, { run } from "../pkg/rome_playground";
+import init, { PlaygroundFormatOptions, run } from "../pkg/rome_playground";
import { useEffect, useState } from "react";
import { IndentStyle, TreeStyle } from "./types";
import { formatWithPrettier, usePlaygroundState, useWindowSize } from "./utils";
@@ -50,9 +50,11 @@ function App() {
const romeOutput = run(
code,
+ new PlaygroundFormatOptions(
lineWidth,
indentStyle === IndentStyle.Space ? indentWidth : undefined,
quoteStyle,
+ ),
isTypeScript,
isJsx,
sourceType,

MODIFY
website/playground/src/LineWidthInput.tsx
website/playground/src/LineWidthInput.tsx
interface Props { lineWidth: number; setLineWidth: (lineWidth: number) => void }
-
export default function LineWidthInput({ lineWidth, setLineWidth }: Props) {
return (
<div className="w-[300px] p-5 flex items-end">

MODIFY
website/playground/src/lib.rs
website/playground/src/lib.rs
@@ -111,13 +111,33 @@ fn clean_up_json(json: serde_json::Value) -> serde_json::Value {
s => s,
}
}
+#[wasm_bindgen]
+pub struct PlaygroundFormatOptions {
+ line_width: u16,
+ indent_width: Option<u8>, // If None, we use tabs
+ quote_style: String,
+}
#[wasm_bindgen]
-pub fn run(
- code: String,
+impl PlaygroundFormatOptions {
+ #[wasm_bindgen(constructor)]
+ pub fn new(
line_width: u16,
indent_width: Option<u8>, // If None, we use tabs
quote_style: String,
+ ) -> Self {
+ Self {
+ line_width,
+ indent_width,
+ quote_style,
+ }
+ }
+}
+
+#[wasm_bindgen]
+pub fn run(
+ code: String,
+ options: PlaygroundFormatOptions,
is_typescript: bool,
is_jsx: bool,
source_type: String,
@@ -145,7 +165,7 @@ pub fn run(
let parse = parse(&code, main_file_id, source_type);
let syntax = parse.syntax();
- let indent_style = if let Some(width) = indent_width {
+ let indent_style = if let Some(width) = options.indent_width {
IndentStyle::Space(width)
} else {
IndentStyle::Tab
@@ -153,8 +173,8 @@ pub fn run(
let options = FormatOptions {
indent_style,
- line_width: line_width.try_into().unwrap_or_default(),
- quote_style: quote_style.parse().unwrap_or_default(),
+ line_width: options.line_width.try_into().unwrap_or_default(),
+ quote_style: options.quote_style.parse().unwrap_or_default(),
};
let (cst, ast) = if output_json {

chore: Fix lint error on main (#2584)

Fixes the lint error that a function has too many arguments on main.