-
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add astro/no-set-html-directive rule (#5)
* Add astro/no-set-html-directive rule * Upadte site * update * update doc
- Loading branch information
Showing
36 changed files
with
505 additions
and
134 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,35 @@ | ||
import { visit } from "unist-util-visit" | ||
import path from "path" | ||
|
||
export default () => { | ||
return (tree) => { | ||
visit(tree, "link", (node) => { | ||
node.url = node.url.replace(/\.md$/u, "/") | ||
export default (options = {}) => { | ||
const base = | ||
// eslint-disable-next-line no-process-env -- ignore | ||
(process?.env?.NODE_ENV === "production" ? options.base : "") || "" | ||
return (tree, file) => { | ||
const srcDir = path.resolve( | ||
file.cwd, | ||
options.srcDir ? options.srcDir : "./src", | ||
) | ||
const pagesDir = path.join(srcDir, "pages") | ||
let markdownPath | ||
visit(tree, "html", (node, _i, parent) => { | ||
if (node.value.startsWith("<!-- markdownPath:")) { | ||
markdownPath = node.value.slice(18, -3).trim() | ||
parent.children.splice(parent.children.indexOf(node), 1) | ||
} | ||
}) | ||
if (markdownPath) { | ||
visit(tree, "link", (node) => { | ||
if (node.url.startsWith(".")) { | ||
const linkPath = path.resolve(path.dirname(markdownPath), node.url) | ||
const relativeLinkPath = path.relative(pagesDir, linkPath) | ||
const absoluteLinkPath = path.join(base, relativeLinkPath) | ||
node.url = `/${absoluteLinkPath | ||
.replace(/^\//u, "") | ||
.replace(/\.md$/u, "/")}` | ||
} | ||
}) | ||
} | ||
return tree | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
<script> | ||
import { onMount } from "svelte" | ||
import ESLintEditor from "./eslint/ESLintEditor.svelte" | ||
import { loadMonacoEditor } from "./eslint/scripts/monaco-loader.mjs" | ||
import { | ||
createLinter, | ||
preprocess, | ||
postprocess, | ||
} from "./eslint/scripts/linter.mjs" | ||
const linter = loadMonacoEditor() | ||
.then(async () => { | ||
const parser = await import("@typescript-eslint/parser") | ||
if (typeof window !== "undefined") { | ||
window.require.define("@typescript-eslint/parser", parser) | ||
} | ||
return window.waitSetupForAstroCompilerWasm | ||
}) | ||
.then(() => { | ||
return createLinter() | ||
}) | ||
let code = "" | ||
export let rules = {} | ||
export let fix = false | ||
let time = "" | ||
let options = { | ||
filename: "example.astro", | ||
preprocess, | ||
postprocess, | ||
} | ||
let showDiff = fix | ||
function onLintedResult(evt) { | ||
time = `${evt.detail.time}ms` | ||
} | ||
let slotRoot | ||
onMount(() => { | ||
code = slotRoot.textContent.trim() | ||
}) | ||
$: blockHeight = `${Math.max( | ||
120, | ||
20 * (1 + code.split("\n").length) + 100, | ||
)}px` | ||
</script> | ||
|
||
<div class="eslint-code-block-default-content" bind:this={slotRoot}> | ||
<slot /> | ||
</div> | ||
|
||
<div class="eslint-code-block-root" style:height={blockHeight}> | ||
<ESLintEditor | ||
{linter} | ||
bind:code | ||
config={{ | ||
parser: "astro-auto-eslint-parser", | ||
parserOptions: { | ||
ecmaVersion: 2020, | ||
sourceType: "module", | ||
parser: "@typescript-eslint/parser", | ||
}, | ||
rules, | ||
env: { | ||
browser: true, | ||
es2021: true, | ||
}, | ||
}} | ||
{options} | ||
on:result={onLintedResult} | ||
showDiff={showDiff && fix} | ||
/> | ||
<div class="eslint-code-block-tools"> | ||
{#if fix} | ||
<label> | ||
<input bind:checked={showDiff} type="checkbox" /> | ||
Show Diff | ||
</label> | ||
{/if} | ||
<span style:margin-left="16px">{time}</span> | ||
</div> | ||
</div> | ||
|
||
<style> | ||
.eslint-code-block-default-content { | ||
display: none; | ||
} | ||
.eslint-code-block-root { | ||
height: 300px; | ||
} | ||
.eslint-code-block-tools { | ||
text-align: end; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
import ESLintCodeBlock from './ESLintCodeBlock.svelte' | ||
--- | ||
<ESLintCodeBlock client:only="svelte" > | ||
<slot></slot> | ||
</ESLintCodeBlock> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
--- | ||
import ESLintPlayground from './ESLintPlayground.svelte' | ||
--- | ||
<ESLintPlayground client:only /> | ||
<ESLintPlayground client:only="svelte" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.