Skip to content

Commit

Permalink
docs: add basic playground
Browse files Browse the repository at this point in the history
  • Loading branch information
azat-io committed Nov 30, 2024
1 parent 9800e26 commit bea3a1b
Show file tree
Hide file tree
Showing 9 changed files with 222 additions and 20 deletions.
2 changes: 2 additions & 0 deletions .cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@
"astro",
"astrojs",
"azat",
"bithero",
"browserslistrc",
"changelogen",
"changelogithub",
"culori",
"execa",
"grotesk",
"joshuakgoldberg",
Expand Down
40 changes: 24 additions & 16 deletions astro.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { transformerNotationDiff } from '@shikijs/transformers'
import { monaco } from '@bithero/monaco-editor-vite-plugin'
import rehypeExternalLinks from 'rehype-external-links'
import { browserslistToTargets } from 'lightningcss'
import svelteSvg from '@poppanator/sveltekit-svg'
Expand All @@ -19,6 +20,29 @@ let dirname = fileURLToPath(path.dirname(import.meta.url))
let site = 'https://perfectionist.dev'

export default defineConfig({
vite: {
css: {
lightningcss: {
targets: browserslistToTargets(
browserslist(null, {
config: path.join(dirname, './.browserslistrc'),
}),
),
},
transformer: 'lightningcss',
},
plugins: [
// @ts-ignore
svelteSvg(),
// @ts-ignore
monaco({
languages: ['typescript'],
}),
],
ssr: {
noExternal: ['monaco-editor'],
},
},
integrations: [
compress({
JavaScript: true,
Expand Down Expand Up @@ -54,22 +78,6 @@ export default defineConfig({
},
remarkPlugins: [remarkSectionize, remarkHeadings],
},
vite: {
css: {
lightningcss: {
targets: browserslistToTargets(
browserslist(null, {
config: path.join(dirname, './.browserslistrc'),
}),
),
},
transformer: 'lightningcss',
},
plugins: [
// @ts-ignore
svelteSvg(),
],
},
prefetch: {
defaultStrategy: 'viewport',
prefetchAll: true,
Expand Down
111 changes: 111 additions & 0 deletions docs/components/Editor/Editor.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
<script lang="ts">
import * as monaco from 'monaco-editor'
import { formatHex } from 'culori'
import { onMount } from 'svelte'
import { colorTheme } from '../../utils/shiki-theme'
import Button from '../Button.svelte'
let editor: monaco.editor.IStandaloneCodeEditor | null = null
let toRgb = (color: string): string => {
if (!color) {
return color
}
let hex = formatHex(color)
if (!hex) {
throw new Error(`Could not convert ${JSON.stringify(color)} to RGB`)
}
return hex
}
let resolveCssVariable = (variable: string): string => {
if (!variable) {
return variable
}
let styles = getComputedStyle(document.documentElement)
let cleanVariable = variable.replace(/^var\(/u, '').replace(/\)$/u, '')
return styles.getPropertyValue(cleanVariable).trim()
}
let defineMonacoTheme = (themeName: string): void => {
monaco.editor.defineTheme(themeName, {
rules: colorTheme.tokenColors
?.flatMap(token =>
(Array.isArray(token.scope) ? token.scope : [token.scope]).map(
scope => ({
foreground: toRgb(
resolveCssVariable(
token.settings.foreground ??
colorTheme.colors!['editor.foreground']!,
),
),
fontStyle: token.settings.fontStyle ?? 'normal',
token: scope,
}),
),
)
.filter(
({ foreground }) => !!foreground,
) as monaco.editor.ITokenThemeRule[],
colors: Object.fromEntries(
Object.entries(colorTheme.colors!)
.map(([key, value]) => [key, toRgb(resolveCssVariable(value))])
.filter(([_, value]) => !!value),
),
base: 'vs-dark',
inherit: false,
})
}
onMount(() => {
let container: HTMLElement | null = document.querySelector('.monaco')
if (container) {
defineMonacoTheme('css-variables')
monaco.languages.typescript.typescriptDefaults.setDiagnosticsOptions({
noSemanticValidation: true,
noSyntaxValidation: true,
})
editor = monaco.editor.create(container, {
minimap: {
enabled: false,
},
// @ts-ignore
'bracketPairColorization.enabled': false,
fontFamily: 'var(--font-family-code)',
language: 'typescript',
matchBrackets: 'never',
automaticLayout: true,
value: 'const a = 3',
lineHeight: 1.7,
fontSize: 15,
})
monaco.editor.setTheme('css-variables')
editor.onDidChangeModelContent(() => {})
}
})
</script>

<div class="wrapper">
<Button color="primary" content="Fix ESLint problems" />
<div class="monaco" />
</div>

<style>
.wrapper {
display: flex;
flex-direction: column;
gap: var(--space-l);
}
.monaco {
inline-size: 100%;
block-size: 600px;
overflow: hidden;
border-radius: var(--border-radius);
}
</style>
3 changes: 3 additions & 0 deletions docs/components/Navigation.astro
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ import Icon from './Icon.astro'
<li class="item item-text">
<a href="/rules" class="link">Rules</a>
</li>
<li class="item item-text">
<a href="/playground" class="link">Playground</a>
</li>
<li>
<hr class="hr" />
</li>
Expand Down
14 changes: 10 additions & 4 deletions docs/layouts/Content.astro
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@ interface Props {
name: string
}[]
keywords?: undefined | string[]
showFooter?: boolean
description: string
editLink?: string
title: string
}
let {
showFooter = true,
keywords = [],
description,
path = [],
Expand All @@ -48,10 +50,14 @@ let {
<main class="main">
<slot />
</main>
<ContentFooter>
<ContentEditLink url={editLink} />
<ContentAdditionalPages />
</ContentFooter>
{
showFooter && (
<ContentFooter>
<ContentEditLink url={editLink} />
<ContentAdditionalPages />
</ContentFooter>
)
}
</Container>
<TableOfContents {headings} />
</div>
Expand Down
31 changes: 31 additions & 0 deletions docs/pages/playground.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
import Editor from '../components/Editor/Editor.svelte'
import ContentLayout from '../layouts/Content.astro'
---

<ContentLayout
keywords={[
'eslint',
'eslint rules',
'eslint plugin',
'coding standards',
'code quality',
'linting rules',
'javascript linting',
'code consistency',
'eslint setup',
'codebase maintenance',
]}
description="Explore our extensive list of ESLint Plugin Perfectionist rules to enforce coding standards and improve code quality. Learn how each rule can help you maintain a consistent and error-free codebase."
path={[
{
href: '/playground',
name: 'Playground',
},
]}
title="Playground"
showFooter={false}
>
<h1>Playground</h1>
<Editor client:only="svelte" />
</ContentLayout>
Empty file added docs/utils/eslint-worker.ts
Empty file.
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,14 @@
"@astrojs/svelte": "^6.0.2",
"@azat-io/eslint-config": "^2.3.0",
"@azat-io/stylelint-config": "^0.1.1",
"@bithero/monaco-editor-vite-plugin": "^1.0.2",
"@commitlint/cli": "^19.6.0",
"@commitlint/config-conventional": "^19.6.0",
"@nanostores/persistent": "^0.10.2",
"@playform/compress": "^0.1.6",
"@poppanator/sveltekit-svg": "5.0.0",
"@shikijs/transformers": "^1.24.0",
"@types/culori": "^2.1.1",
"@types/mdast": "^4.0.4",
"@types/node": "^22.10.1",
"@types/unist": "^3.0.3",
Expand All @@ -81,11 +83,13 @@
"changelogithub": "^0.13.11",
"clean-publish": "^5.1.0",
"cspell": "^8.16.1",
"culori": "^4.0.1",
"eslint": "^9.15.0",
"eslint-plugin-eslint-plugin": "^6.3.2",
"execa": "^9.5.1",
"keyux": "^0.10.0",
"lightningcss": "^1.28.2",
"monaco-editor": "^0.52.0",
"nanostores": "^0.11.3",
"postcss-html": "^1.7.0",
"prettier": "^3.4.1",
Expand Down
Loading

0 comments on commit bea3a1b

Please sign in to comment.