Skip to content

Commit

Permalink
fix: eslint issues
Browse files Browse the repository at this point in the history
  • Loading branch information
holtwick committed Dec 15, 2023
1 parent f2f5a0d commit 83331eb
Show file tree
Hide file tree
Showing 19 changed files with 418 additions and 282 deletions.
2 changes: 1 addition & 1 deletion eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import antfu from '@antfu/eslint-config'

export default antfu({
ignores: ["dist","**/dist/**","node_modules","**/node_modules/**","build","**/build/**","tmp","**/tmp/**","demos","**/demos/**","coverage","**/coverage/**","_archive","**/_archive/**","*.spec.*","**/*.spec.*/**","vitest.config.ts","**/vitest.config.ts/**","*.md","**/*.md/**","*.yml","**/*.yml/**"]
ignores: ['dist', '**/dist/**', 'node_modules', '**/node_modules/**', 'build', '**/build/**', 'tmp', '**/tmp/**', 'demos', '**/demos/**', 'coverage', '**/coverage/**', '_archive', '**/_archive/**', '*.spec.*', '**/*.spec.*/**', 'vitest.config.ts', '**/vitest.config.ts/**', '*.md', '**/*.md/**', '*.yml', '**/*.yml/**'],
})
6 changes: 4 additions & 2 deletions examples/auto-jsx/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
/* eslint-disable no-console */
'use strict'
exports.__esModule = true
const dom = (<ol className="projects">
const dom = (
<ol className="projects">
<li>hostic</li>
<li>hostic-dom</li>
</ol>)
</ol>
)
console.log(dom)
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,4 @@
"vite": "^5.0.9",
"vitest": "^1.0.4"
}
}
}
140 changes: 128 additions & 12 deletions src/encoding-he.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
/* eslint-disable ts/ban-ts-comment */
// @ts-nocheck

import { hasOwn } from './utils'
Expand Down Expand Up @@ -3822,17 +3822,133 @@ const decodeMapNumeric = {
159: '\u0178',
}
const invalidReferenceCodePoints = [
1, 2, 3, 4, 5, 6, 7, 8, 11, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
25, 26, 27, 28, 29, 30, 31, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136,
137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151,
152, 153, 154, 155, 156, 157, 158, 159, 64976, 64977, 64978, 64979, 64980,
64981, 64982, 64983, 64984, 64985, 64986, 64987, 64988, 64989, 64990, 64991,
64992, 64993, 64994, 64995, 64996, 64997, 64998, 64999, 65000, 65001, 65002,
65003, 65004, 65005, 65006, 65007, 65534, 65535, 131070, 131071, 196606,
196607, 262142, 262143, 327678, 327679, 393214, 393215, 458750, 458751,
524286, 524287, 589822, 589823, 655358, 655359, 720894, 720895, 786430,
786431, 851966, 851967, 917502, 917503, 983038, 983039, 1048574, 1048575,
1114110, 1114111,
1,
2,
3,
4,
5,
6,
7,
8,
11,
13,
14,
15,
16,
17,
18,
19,
20,
21,
22,
23,
24,
25,
26,
27,
28,
29,
30,
31,
127,
128,
129,
130,
131,
132,
133,
134,
135,
136,
137,
138,
139,
140,
141,
142,
143,
144,
145,
146,
147,
148,
149,
150,
151,
152,
153,
154,
155,
156,
157,
158,
159,
64976,
64977,
64978,
64979,
64980,
64981,
64982,
64983,
64984,
64985,
64986,
64987,
64988,
64989,
64990,
64991,
64992,
64993,
64994,
64995,
64996,
64997,
64998,
64999,
65000,
65001,
65002,
65003,
65004,
65005,
65006,
65007,
65534,
65535,
131070,
131071,
196606,
196607,
262142,
262143,
327678,
327679,
393214,
393215,
458750,
458751,
524286,
524287,
589822,
589823,
655358,
655359,
720894,
720895,
786430,
786431,
851966,
851967,
917502,
917503,
983038,
983039,
1048574,
1048575,
1114110,
1114111,
]

/* -------------------------------------------------------------------------- */
Expand Down
10 changes: 5 additions & 5 deletions src/encoding.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { escapeHTML } from "."
import { escapeHTML } from '.'

describe("encoding", () => {
it("should encoding", () => {
expect(escapeHTML("</")).toEqual("&lt;/")
expect(escapeHTML("<and> &")).toEqual("&lt;and&gt; &amp;")
describe('encoding', () => {
it('should encoding', () => {
expect(escapeHTML('</')).toEqual('&lt;/')
expect(escapeHTML('<and> &')).toEqual('&lt;and&gt; &amp;')
})
})
26 changes: 13 additions & 13 deletions src/h.spec.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
// (C)opyright 2021-07-20 Dirk Holtwick, holtwick.it. All rights reserved.

import { hArgumentParser } from "./h"
import { hArgumentParser } from './h'

describe("h", () => {
it("should flatten", () => {
let values = hArgumentParser("div", ["a", ["b", ["c", "d"], "e"]])
describe('h', () => {
it('should flatten', () => {
const values = hArgumentParser('div', ['a', ['b', ['c', 'd'], 'e']])
expect(values).toEqual({
attrs: {},
children: ["a", "b", "c", "d", "e"],
tag: "div",
children: ['a', 'b', 'c', 'd', 'e'],
tag: 'div',
})
})

it("should handle attrs", () => {
let values = hArgumentParser(
"div",
it('should handle attrs', () => {
const values = hArgumentParser(
'div',
{
attrs: {
a: 1,
Expand All @@ -23,8 +23,8 @@ describe("h", () => {
c: 3,
d: 4,
},
"a",
"b"
'a',
'b',
)
expect(values).toEqual({
attrs: {
Expand All @@ -33,8 +33,8 @@ describe("h", () => {
c: 3,
d: 4,
},
children: ["a", "b"],
tag: "div",
children: ['a', 'b'],
tag: 'div',
})
})
})
36 changes: 18 additions & 18 deletions src/html.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,46 +1,46 @@
// Copyright (c) 2020 Dirk Holtwick. All rights reserved. https://holtwick.de/copyright
/** @jsx h */

import { html as h, CDATA } from "./html"
import { CDATA, html as h } from './html'

describe("HTML", () => {
it("should generate a string", () => {
let s = h("a", { href: "example.com" }, "Welcome & Hello &amp; Ciao")
describe('hTML', () => {
it('should generate a string', () => {
const s = h('a', { href: 'example.com' }, 'Welcome & Hello &amp; Ciao')
expect(s).toEqual(
'<a href="example.com">Welcome &amp; Hello &amp;amp; Ciao</a>'
'<a href="example.com">Welcome &amp; Hello &amp;amp; Ciao</a>',
) // the second & is correct, because plain string should be unescaped
})

it("should nest", () => {
let s = h("a", { href: "example.com" }, h("hr"), h("b", {}, "Welcome"))
it('should nest', () => {
const s = h('a', { href: 'example.com' }, h('hr'), h('b', {}, 'Welcome'))
expect(s).toEqual('<a href="example.com"><hr><b>Welcome</b></a>')
})

it("should use JSX", () => {
let spread = {
title: "Hello",
id: "greeting",
it('should use JSX', () => {
const spread = {
title: 'Hello',
id: 'greeting',
}
let s = (
const s = (
<a href="example.com" x="x" hidden={false} {...spread}>
<hr myCaseSensitiveAttribute="1" />
{null && "This is invisible"}
{null && 'This is invisible'}
<b>Welcome</b>
</a>
)

expect(s).toEqual(
'<a href="example.com" x="x" title="Hello" id="greeting"><hr myCaseSensitiveAttribute="1"><b>Welcome</b></a>'
'<a href="example.com" x="x" title="Hello" id="greeting"><hr myCaseSensitiveAttribute="1"><b>Welcome</b></a>',
)
})

it("should keep cdata", () => {
let s = <cdata>{"<b>Do not escape! & </b>"}</cdata>
it('should keep cdata', () => {
const s = <cdata>{'<b>Do not escape! & </b>'}</cdata>
expect(s).toMatchInlineSnapshot(`"<![CDATA[<b>Do not escape! & </b>]]>"`)

let s2 = <div>{CDATA("<b>Do not escape! & </b>")}</div>
const s2 = <div>{CDATA('<b>Do not escape! & </b>')}</div>
expect(s2).toMatchInlineSnapshot(
`"<div><![CDATA[<b>Do not escape! & </b>]]></div>"`
`"<div><![CDATA[<b>Do not escape! & </b>]]></div>"`,
)
})
})
4 changes: 2 additions & 2 deletions src/html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ export function markup(
const hasChildren = !(
(typeof children === 'string' && children === '')
|| (Array.isArray(children)
&& (children.length === 0
|| (children.length === 1 && children[0] === '')))
&& (children.length === 0
|| (children.length === 1 && children[0] === '')))
|| children == null
)

Expand Down
31 changes: 16 additions & 15 deletions src/htmlparser.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { createHTMLDocument, parseHTML, VHTMLDocument, VTextNode } from "."
import type { VHTMLDocument } from '.'
import { VTextNode, createHTMLDocument, parseHTML } from '.'

describe("htmlparser", () => {
it("should parse without errors", async () => {
describe('htmlparser', () => {
it('should parse without errors', async () => {
const sample = `<!DOCTYPE html>
<html lang="de">
<head>
Expand All @@ -13,35 +14,35 @@ describe("htmlparser", () => {
</code></pre>
</body>
</html>`
let dom = parseHTML(sample) as VHTMLDocument
const dom = parseHTML(sample) as VHTMLDocument
expect(dom != null).toBe(true)
expect(dom.render()).toEqual(sample)
expect(dom.head != null).toBe(true)
})

it("should escape correctly", () => {
let dom = createHTMLDocument()
dom.body?.appendChild("</")
dom.body?.appendChild(new VTextNode("</"))
it('should escape correctly', () => {
const dom = createHTMLDocument()
dom.body?.appendChild('</')
dom.body?.appendChild(new VTextNode('</'))
expect(dom.body?.firstChild?._text).toMatchInlineSnapshot(`"</"`)
expect(dom.body?.textContent).toMatchInlineSnapshot(`"</</"`)
expect(dom.body?.innerHTML).toMatchInlineSnapshot(`"&lt;/&lt;/"`)
expect(dom.body?.outerHTML).toMatchInlineSnapshot(
`"<body>&lt;/&lt;/</body>"`
`"<body>&lt;/&lt;/</body>"`,
)
expect(dom.render()).toMatchInlineSnapshot(
`"<!DOCTYPE html><html><head><title></title></head><body>&lt;/&lt;/</body></html>"`
`"<!DOCTYPE html><html><head><title></title></head><body>&lt;/&lt;/</body></html>"`,
)
})

it("should handle entities correctly", () => {
it('should handle entities correctly', () => {
// https://github.com/holtwick/zeed-dom/issues/3
let dom = parseHTML("<p>Let&#x27;s go</p>") as VHTMLDocument
const dom = parseHTML('<p>Let&#x27;s go</p>') as VHTMLDocument
expect(dom.textContent).toMatchInlineSnapshot(`"Let's go"`)
expect(dom.render()).toMatchInlineSnapshot(`"<p>Let&apos;s go</p>"`)
})

it("should ignore escape for script etc.", () => {
it('should ignore escape for script etc.', () => {
const html = `<script>
var x = 1 & 4
window.addEventListener('load', function () {
Expand All @@ -51,7 +52,7 @@ $('body')
.attr('data-target', '#outline')
})
</script>`
let dom = parseHTML(html) as VHTMLDocument
const dom = parseHTML(html) as VHTMLDocument
expect(dom.textContent).toMatchInlineSnapshot(`
"
var x = 1 & 4
Expand Down Expand Up @@ -108,7 +109,7 @@ $('body')
`)
})

it("should not recurse on bad fragment", () => {
it('should not recurse on bad fragment', () => {
const tests = [
'<',
'<<',
Expand Down
Loading

0 comments on commit 83331eb

Please sign in to comment.