Skip to content

Commit

Permalink
fix: wrong xo config resolved
Browse files Browse the repository at this point in the history
  • Loading branch information
JounQin committed Nov 20, 2023
1 parent 7d7e851 commit ad81888
Show file tree
Hide file tree
Showing 42 changed files with 253 additions and 142 deletions.
33 changes: 25 additions & 8 deletions example/viewscreen/lib/outside.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ window.addEventListener(
*
* @param {MessageEvent<FromViewscreenMessage>} event
*/
function (event) {
(event) => {
// eslint-disable-next-line unicorn/prefer-switch
if (event.data.type === 'resize') {
// We use unique names, but not bad to handle arrays.
Expand All @@ -39,7 +39,10 @@ window.addEventListener(
}
} else if (event.data.type === 'resolve') {
const viewscreen = viewscreens.get(event.data.id)
if (!viewscreen) throw new Error('Expected viewscreen')
if (!viewscreen) {
throw new Error('Expected viewscreen')
}

// Note: this never happens.
// When `reject` is added to the DOM, it replaces the frame, which
// offloads it, so `resolve` will never happen.
Expand All @@ -48,9 +51,15 @@ window.addEventListener(
}
} else if (event.data.type === 'reject') {
const viewscreen = viewscreens.get(event.data.id)
if (!viewscreen) throw new Error('Expected viewscreen')
if (!viewscreen) {
throw new Error('Expected viewscreen')
}

const body = viewscreen.reject.querySelector('.flash-body')
if (!body) throw new Error('Expected body')
if (!body) {
throw new Error('Expected body')
}

body.textContent = event.data.value
if (viewscreen.resolve.parentElement) {
viewscreen.resolve.replaceWith(viewscreen.reject)
Expand All @@ -66,12 +75,17 @@ const prefix = 'language-'

for (const node of nodes) {
const className = Array.from(node.classList).find((d) => d.startsWith(prefix))
if (!className) continue
if (!className) {
continue
}

const name = className.slice(prefix.length)

const specifier = hasOwn.call(types, name) ? types[name] : undefined

if (!specifier) continue
if (!specifier) {
continue
}

const value = node.textContent || ''
const id = crypto.randomUUID()
Expand All @@ -92,9 +106,12 @@ for (const node of nodes) {
// Hide for now.
iframe.setAttribute('style', 'opacity:0')

iframe.addEventListener('load', function () {
iframe.addEventListener('load', () => {
const otherWindow = iframe.contentWindow
if (!otherWindow) throw new Error('Expected `contentWindow`')
if (!otherWindow) {
throw new Error('Expected `contentWindow`')
}

/** @type {ToViewscreenMessage} */
const message = {type: 'content', id, value}
iframe.setAttribute('style', '')
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"create-gfm-fixtures": "^1.0.0",
"hastscript": "^7.0.0",
"jsdom": "^21.0.0",
"patch-package": "^8.0.0",
"prettier": "^2.0.0",
"rehype-parse": "^8.0.0",
"rehype-raw": "^6.0.0",
Expand All @@ -54,9 +55,10 @@
"semver": "^7.0.0",
"type-coverage": "^2.0.0",
"typescript": "^5.0.0",
"xo": "^0.54.0"
"xo": "^0.56.0"
},
"scripts": {
"prepare": "patch-package",
"prepack": "npm run build && npm run format",
"build": "tsc --build --clean && tsc --build && type-coverage",
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix",
Expand Down
1 change: 1 addition & 0 deletions packages/break/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
* [Security](#security)
* [Related](#related)
* [Contribute](#contribute)
* [Notice](#notice)
* [License](#license)

## What is this?
Expand Down
32 changes: 16 additions & 16 deletions packages/break/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ test('remarkGithubBreak', async () => {
)
})

test('fixtures', async function () {
test('fixtures', async () => {
const base = new URL('fixtures/', import.meta.url)

await createGfmFixtures(base, {
Expand Down Expand Up @@ -78,41 +78,41 @@ test('fixtures', async function () {
// CommonMark doesn’t seem to do that.
.replace(/(alt="im)\n(age")/, '$1 $2')
// GitHub drops HTML comments.
.replace(/<!--[\s\S]*?-->/g, '')
.replaceAll(/<!--[\s\S]*?-->/g, '')
// Elements that GH drops the tags of.
.replace(/<\/?article>/g, '')
.replaceAll(/<\/?article>/g, '')
// GitHub uses weird code.
// To do: `create-github-fixtures` should support this.
.replace(
/<pre><code class="language-markdown">a\nb\.\n<\/code><\/pre>/g,
.replaceAll(
'<pre><code class="language-markdown">a\nb.\n</code></pre>',
'<div class="highlight highlight-source-gfm"><pre>a\nb.</pre></div>'
)
// Elements that GitHub cleans (To do: implemment tagfilter somewhere?)
.replace(/<(\/?script>)/g, '&#x3C;$1')
.replaceAll(/<(\/?script>)/g, '&#x3C;$1')
// To do: `remark-rehype` should change the order.
.replace(/checked disabled/g, 'disabled checked')
.replace(
/class="sr-only" id="footnote-label"/g,
.replaceAll('checked disabled', 'disabled checked')
.replaceAll(
'class="sr-only" id="footnote-label"',
'id="footnote-label" class="sr-only"'
)
// To do: `remark-rehype` should implement new labels.
.replace(
/class="data-footnote-backref" aria-label="Back to content"/g,
.replaceAll(
'class="data-footnote-backref" aria-label="Back to content"',
'aria-label="Back to reference 1" class="data-footnote-backref"'
)
// To do: `create-github-fixtures` should remove this on `ol`s too.
.replace(/ class="contains-task-list"/g, '')
.replaceAll(' class="contains-task-list"', '')
// To do: `create-github-fixtures` should support this.
.replace(/ class="task-list-item"/g, '')
.replaceAll(' class="task-list-item"', '')

expected = expected
// To do: add to `create-gfm-fixtures`.
// GH adds `notranslate`, this should be (optionally) removed by `crate-gfm-fixtures`.
.replace(/ class="notranslate"/g, '')
.replaceAll(' class="notranslate"', '')
// To do: `create-github-fixtures` should remove this on `ol`s too.
.replace(/ class="contains-task-list"/g, '')
.replaceAll(' class="contains-task-list"', '')
// To do: `create-github-fixtures` should support this.
.replace(/ class="task-list-item"/g, '')
.replaceAll(' class="task-list-item"', '')

assert.equal(actual, expected, name)
}
Expand Down
2 changes: 1 addition & 1 deletion packages/color/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export default function rehypeGithubColor(options) {
const behavior = config.behavior || 'append'

return function (tree) {
visit(tree, 'element', function (node, index, parent) {
visit(tree, 'element', (node, index, parent) => {
if (
node.tagName === 'code' &&
node.properties &&
Expand Down
1 change: 1 addition & 0 deletions packages/color/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
* [Security](#security)
* [Related](#related)
* [Contribute](#contribute)
* [Notice](#notice)
* [License](#license)

## What is this?
Expand Down
4 changes: 2 additions & 2 deletions packages/color/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ test('rehypeGithubColor', async () => {
)
})

test('fixtures', async function () {
test('fixtures', async () => {
const base = new URL('fixtures/', import.meta.url)

await createGfmFixtures(base, {
Expand Down Expand Up @@ -134,7 +134,7 @@ test('fixtures', async function () {

// To do: add to `create-gfm-fixtures`.
// GH adds `notranslate`, this should be (optionally) removed by `crate-gfm-fixtures`.
expected = expected.replace(/ class="notranslate"/g, '')
expected = expected.replaceAll(' class="notranslate"', '')

assert.equal(actual, expected, name)
}
Expand Down
2 changes: 1 addition & 1 deletion packages/dir/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export default function rehypeGithubDir(options) {
const include = config.include || defaultInclude

return function (tree) {
visit(tree, 'element', function (node) {
visit(tree, 'element', (node) => {
if (
node.type === 'element' &&
include.includes(node.tagName) &&
Expand Down
1 change: 1 addition & 0 deletions packages/dir/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
* [Security](#security)
* [Related](#related)
* [Contribute](#contribute)
* [Notice](#notice)
* [License](#license)

## What is this?
Expand Down
36 changes: 18 additions & 18 deletions packages/dir/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ test('rehypeGithubDir', async () => {
)
})

test('fixtures', async function () {
test('fixtures', async () => {
const base = new URL('fixtures/', import.meta.url)

await createGfmFixtures(base, {keep: {dir: true}})
Expand Down Expand Up @@ -55,60 +55,60 @@ test('fixtures', async function () {
// To do: add to `create-gfm-fixtures`.
// GH adds `notranslate`, this should be (optionally) removed by `crate-gfm-fixtures`.
expected = expected
.replace(/ class="notranslate"/g, '')
.replaceAll(' class="notranslate"', '')
// To do: `create-github-fixtures` should remove this on `ol`s too.
.replace(/ class="contains-task-list"/g, '')
.replaceAll(' class="contains-task-list"', '')
// To do: `create-github-fixtures` should support this.
.replace(/ class="task-list-item"/g, '')
.replaceAll(' class="task-list-item"', '')

if (name === 'markdown') {
// There’s something weird about line endings. Perhaps related to `rehype-raw`?
// To do: investigate.
actual = actual.replace(
actual = actual.replaceAll(
/\n*(<\/?(?:table|thead|tbody|tr|th|td)>)\n*/g,
'$1'
)
expected = expected.replace(
expected = expected.replaceAll(
/\n*(<\/?(?:table|thead|tbody|tr|th|td)>)\n*/g,
'$1'
)
}

actual = actual
// To do: `create-github-fixtures` should remove this on `ol`s too.
.replace(/ class="contains-task-list"/g, '')
.replaceAll(' class="contains-task-list"', '')
// To do: `create-github-fixtures` should support this.
.replace(/ class="task-list-item"/g, '')
.replaceAll(' class="task-list-item"', '')
// To do: `remark-rehype` should change the order.
.replace(/checked disabled/g, 'disabled checked')
.replace(
/class="sr-only" id="footnote-label"/g,
.replaceAll('checked disabled', 'disabled checked')
.replaceAll(
'class="sr-only" id="footnote-label"',
'id="footnote-label" class="sr-only"'
)
// To do: `remark-rehype` should implement new labels.
.replace(
/class="data-footnote-backref" aria-label="Back to content"/g,
.replaceAll(
'class="data-footnote-backref" aria-label="Back to content"',
'aria-label="Back to reference 1" class="data-footnote-backref"'
)
// GitHub uses weird code.
// To do: `create-github-fixtures` should support this.
.replace(
/<pre><code class="language-markdown">a\nb\.\n<\/code><\/pre>/g,
.replaceAll(
'<pre><code class="language-markdown">a\nb.\n</code></pre>',
'<div class="highlight highlight-source-gfm" dir="auto"><pre>a\nb.</pre></div>'
)

if (name === 'html') {
// Elements that GH drops the tags of.
// To do: improve `rehype-sanitize`?
actual = actual
.replace(
.replaceAll(
/<\/?(?:a|abbr|acronym|address|applet|article|aside|audio|bdi|bdo|big|blink|button|canvas|center|cite|content|data|datalist|dfn|dialog|dir|element|fieldset|figcaption|figure|font|footer|form|header|hgroup|label|legend|listing|main|map|mark|marquee|math|menu|meter|multicol|nav|nobr|noscript|object|optgroup|option|output|progress|rb|rbc|rtc|search|select|shadow|slot|small|spacer|svg|template|time|u)>/g,
''
)
// Elements that GitHub drops entirely
.replace(/<video>.*?<\/video>/g, '')
.replaceAll(/<video>.*?<\/video>/g, '')
// Elements that GitHub cleans (To do: implemment tagfilter somewhere?)
.replace(
.replaceAll(
/<(\/?(?:iframe|noembed|noframes|plaintext|script|style|textarea|title|xmp)>)/g,
'&#x3C;$1'
)
Expand Down
11 changes: 8 additions & 3 deletions packages/emoji/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,15 @@ export function defaultBuild(info, value) {
for (const cpString of info.emoji) {
const codePoint = cpString.codePointAt(0)
/* c8 ignore next */
if (codePoint === undefined) throw new Error('Cannot happen')
if (codePoint === undefined) {
throw new Error('Cannot happen')
}

codePoints.push(codePoint.toString(16).padStart(4, '0'))
}

// See: <https://github.com/github/gemoji/blob/55bb37a/lib/emoji/character.rb#L84>
const hexName = codePoints.join('-').replace(/-(fe0f|200d)\b/g, '')
const hexName = codePoints.join('-').replaceAll(/-(fe0f|200d)\b/g, '')

return {
type: 'element',
Expand Down Expand Up @@ -205,7 +208,9 @@ export default function rehypeGithubEmoji(options) {
)

/* c8 ignore next */
if (!info) throw new Error('Cannot happen')
if (!info) {
throw new Error('Cannot happen')
}

return build(info, $0)
}
Expand Down
1 change: 1 addition & 0 deletions packages/emoji/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
* [Security](#security)
* [Related](#related)
* [Contribute](#contribute)
* [Notice](#notice)
* [License](#license)

## What is this?
Expand Down
10 changes: 5 additions & 5 deletions packages/emoji/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ test('rehypeGithubEmoji', async () => {
)

assert.throws(
function () {
() => {
String(
unified()
.use(rehypeParse, {fragment: true})
Expand Down Expand Up @@ -107,7 +107,7 @@ test('rehypeGithubEmoji', async () => {
)
})

test('fixtures', async function () {
test('fixtures', async () => {
const base = new URL('fixtures/', import.meta.url)

await createGfmFixtures(base, {
Expand Down Expand Up @@ -145,14 +145,14 @@ test('fixtures', async function () {
if (name === 'html') {
// Elements that GH drops the tags of.
actual = actual
.replace(
.replaceAll(
/<\/?(?:a|abbr|acronym|address|applet|article|aside|audio|bdi|bdo|big|blink|button|canvas|center|cite|content|data|datalist|dfn|dialog|dir|element|fieldset|figcaption|figure|font|footer|form|header|hgroup|label|legend|listing|main|map|mark|marquee|math|menu|meter|multicol|nav|nobr|noscript|object|optgroup|option|output|progress|rb|rbc|rtc|search|select|shadow|slot|small|spacer|svg|template|time|u)>/g,
''
)
// Elements that GitHub drops entirely
.replace(/<video>.*?<\/video>/g, '')
.replaceAll(/<video>.*?<\/video>/g, '')
// Elements that GitHub cleans (To do: implemment tagfilter somewhere?)
.replace(
.replaceAll(
/<(\/?(?:iframe|noembed|noframes|plaintext|script|style|textarea|title|xmp)>)/g,
'&#x3C;$1'
)
Expand Down
2 changes: 1 addition & 1 deletion packages/heading/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export default function rehypeGithubHeading(options) {
const slugger = new GithubSlugger()

return function (tree) {
visit(tree, 'element', function (node) {
visit(tree, 'element', (node) => {
if (node.type === 'element' && node.properties) {
// Do not enter the footnote section.
if (
Expand Down
1 change: 1 addition & 0 deletions packages/heading/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
* [Security](#security)
* [Related](#related)
* [Contribute](#contribute)
* [Notice](#notice)
* [License](#license)

## What is this?
Expand Down
Loading

0 comments on commit ad81888

Please sign in to comment.