From fc88516abfd4e28008d3655808da1a5c9f194457 Mon Sep 17 00:00:00 2001 From: Danilo Woznica Date: Wed, 18 May 2022 18:51:43 +0100 Subject: [PATCH] [Beta] Adds eslint integration on Sandpack (#4665) * added sandpack linter and installed latest sandpacl * integrate eslint into Sandpack * Format the linting errors, disable preview on lint error, have only two react hooks * fixes build * split eslint-integration * fix tooltip text color, error rename to 'Lint Error', show single lint error * NIT * Just enable it * Delete eslint.md Co-authored-by: Strek Co-authored-by: dan --- beta/package.json | 2 +- .../components/MDX/Sandpack/CustomPreset.tsx | 6 +- beta/src/components/MDX/Sandpack/Error.tsx | 22 +++++ beta/src/components/MDX/Sandpack/Preview.tsx | 18 +++- .../MDX/Sandpack/eslint-integration.tsx | 85 +++++++++++++++++++ beta/src/components/MDX/Sandpack/utils.ts | 28 ++++++ beta/src/styles/sandpack.css | 13 +++ beta/yarn.lock | 55 +++--------- 8 files changed, 181 insertions(+), 48 deletions(-) create mode 100644 beta/src/components/MDX/Sandpack/eslint-integration.tsx diff --git a/beta/package.json b/beta/package.json index 59857cf5..d2fe90cb 100644 --- a/beta/package.json +++ b/beta/package.json @@ -22,7 +22,7 @@ "check-all": "npm-run-all prettier lint:fix tsc" }, "dependencies": { - "@codesandbox/sandpack-react": "v0.14.3-experimental.1", + "@codesandbox/sandpack-react": "v0.19.8-experimental.0", "@docsearch/css": "3.0.0-alpha.41", "@docsearch/react": "3.0.0-alpha.41", "@headlessui/react": "^1.3.0", diff --git a/beta/src/components/MDX/Sandpack/CustomPreset.tsx b/beta/src/components/MDX/Sandpack/CustomPreset.tsx index eae75221..a7b401b4 100644 --- a/beta/src/components/MDX/Sandpack/CustomPreset.tsx +++ b/beta/src/components/MDX/Sandpack/CustomPreset.tsx @@ -1,7 +1,6 @@ /* * Copyright (c) Facebook, Inc. and its affiliates. */ - import React from 'react'; // @ts-ignore import {flushSync} from 'react-dom'; @@ -13,13 +12,13 @@ import { SandpackReactDevTools, } from '@codesandbox/sandpack-react'; import scrollIntoView from 'scroll-into-view-if-needed'; - import cn from 'classnames'; import {IconChevron} from 'components/Icon/IconChevron'; import {NavigationBar} from './NavigationBar'; import {Preview} from './Preview'; import {CustomTheme} from './Themes'; +import {useSandpackLint} from './utils'; export function CustomPreset({ isSingleFile, @@ -32,6 +31,7 @@ export function CustomPreset({ devToolsLoaded: boolean; onDevToolsLoad: () => void; }) { + const {lintErrors, onLint} = useSandpackLint(); const lineCountRef = React.useRef<{[key: string]: number}>({}); const containerRef = React.useRef(null); const {sandpack} = useSandpack(); @@ -64,10 +64,12 @@ export function CustomPreset({ showInlineErrors showTabs={false} showRunButton={false} + extensions={[onLint]} /> {isExpandable && (