From 35a6555f816ecbd3469a754e89005aa7e6096610 Mon Sep 17 00:00:00 2001 From: Patrick M Date: Sun, 13 Nov 2022 19:39:03 +0100 Subject: [PATCH] docs(website): added checkbox to toggle linter in playground (#3699) Fixes https://github.com/rome/tools/issues/3010 --- .../playground/components/SettingsPane.tsx | 19 +++++++++++++++++++ website/src/playground/types.ts | 3 +++ website/src/playground/utils.ts | 3 +++ website/src/playground/workers/romeWorker.ts | 15 ++++++++++++--- 4 files changed, 37 insertions(+), 3 deletions(-) diff --git a/website/src/playground/components/SettingsPane.tsx b/website/src/playground/components/SettingsPane.tsx index 11a0f91b1c1..022c785ef6d 100644 --- a/website/src/playground/components/SettingsPane.tsx +++ b/website/src/playground/components/SettingsPane.tsx @@ -33,6 +33,7 @@ export default function SettingsPane({ typescript: isTypeScript, jsx: isJsx, enabledNurseryRules, + enabledLinting, }, }: Props) { const setIsTypeScript = createSetter(setPlaygroundState, "typescript"); @@ -51,6 +52,7 @@ export default function SettingsPane({ setPlaygroundState, "enabledNurseryRules", ); + const setEnabledLinting = createSetter(setPlaygroundState, "enabledLinting"); const [isCollapsed, setIsCollapsed] = useState(isCollapsedStore.getBoolean()); @@ -88,6 +90,8 @@ export default function SettingsPane({ void; + enabledLinting: boolean; + setEnabledLinting: (value: boolean) => void; }) { return ( <>

Linter

+
+ setEnabledLinting(e.target.checked)} + /> + +
setEnabledNurseryRules(e.target.checked)} /> diff --git a/website/src/playground/types.ts b/website/src/playground/types.ts index d3fc267fe57..24aba12f19e 100644 --- a/website/src/playground/types.ts +++ b/website/src/playground/types.ts @@ -50,6 +50,7 @@ export interface PlaygroundState { jsx: boolean; cursorPosition: number; enabledNurseryRules: boolean; + enabledLinting: boolean; } // change `lineWidth` and `indentWidth` to string type, just to fits our `usePlaygroundState` fallback usage @@ -70,6 +71,7 @@ export const defaultRomeConfig: RomeConfiguration = { jsx: true, cursorPosition: 0, enabledNurseryRules: true, + enabledLinting: true, }; export interface PlaygroundProps { @@ -92,6 +94,7 @@ export type PlaygroundSettings = Pick< | "typescript" | "jsx" | "enabledNurseryRules" + | "enabledLinting" >; export type Tree = ReturnType; diff --git a/website/src/playground/utils.ts b/website/src/playground/utils.ts index 692212f3cbe..890ab97cfbf 100644 --- a/website/src/playground/utils.ts +++ b/website/src/playground/utils.ts @@ -145,6 +145,9 @@ export function usePlaygroundState( enabledNurseryRules: searchParams.get("enabledNurseryRules") === "true" || defaultRomeConfig.enabledNurseryRules, + enabledLinting: + searchParams.get("enabledLinting") === "true" || + defaultRomeConfig.enabledLinting, }); const [playgroundState, setPlaygroundState] = useState( initState(initialSearchParams), diff --git a/website/src/playground/workers/romeWorker.ts b/website/src/playground/workers/romeWorker.ts index 4ecbd5a3ca1..e45a313bb0c 100644 --- a/website/src/playground/workers/romeWorker.ts +++ b/website/src/playground/workers/romeWorker.ts @@ -2,6 +2,7 @@ import init, { Configuration, DiagnosticPrinter, RomePath, + RuleCategories, Workspace, } from "@rometools/wasm-web"; import { @@ -83,6 +84,7 @@ self.addEventListener("message", async (e) => { sourceType, cursorPosition, enabledNurseryRules, + enabledLinting, trailingComma, } = playgroundState; @@ -95,7 +97,7 @@ self.addEventListener("message", async (e) => { indentSize: indentWidth, }, linter: { - enabled: true, + enabled: enabledLinting, }, javascript: { formatter: { @@ -110,7 +112,7 @@ self.addEventListener("message", async (e) => { }; if (enabledNurseryRules) { configuration.linter = { - enabled: true, + enabled: enabledLinting, rules: { nursery: { noConstAssign: "error", @@ -160,9 +162,16 @@ self.addEventListener("message", async (e) => { path, }); + const categories: RuleCategories = []; + if (configuration.formatter?.enabled) { + categories.push("Syntax"); + } + if (configuration.linter?.enabled) { + categories.push("Lint"); + } const diagnostics = workspace.pullDiagnostics({ path, - categories: ["Syntax", "Lint"], + categories: categories, max_diagnostics: Number.MAX_SAFE_INTEGER, });