diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..eae23ff --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,43 @@ +{ + // Enable the ESlint flat config support + "eslint.experimental.useFlatConfig": true, + + // Disable the default formatter, use eslint instead + "prettier.enable": false, + "editor.formatOnSave": false, + + // Auto fix + "editor.codeActionsOnSave": { + "source.fixAll.eslint": "explicit", + "source.organizeImports": "never" + }, + + // Silent the stylistic rules in you IDE, but still auto fix them + "eslint.rules.customizations": [ + { "rule": "style/*", "severity": "off" }, + { "rule": "format/*", "severity": "off" }, + { "rule": "*-indent", "severity": "off" }, + { "rule": "*-spacing", "severity": "off" }, + { "rule": "*-spaces", "severity": "off" }, + { "rule": "*-order", "severity": "off" }, + { "rule": "*-dangle", "severity": "off" }, + { "rule": "*-newline", "severity": "off" }, + { "rule": "*quotes", "severity": "off" }, + { "rule": "*semi", "severity": "off" } + ], + + // Enable eslint for all supported languages + "eslint.validate": [ + "javascript", + "javascriptreact", + "typescript", + "typescriptreact", + "vue", + "html", + "markdown", + "json", + "jsonc", + "yaml", + "toml" + ] +} diff --git a/eslint.config.js b/eslint.config.js new file mode 100644 index 0000000..c7530fc --- /dev/null +++ b/eslint.config.js @@ -0,0 +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/**'], +}) diff --git a/examples/auto-jsx/index.js b/examples/auto-jsx/index.js index 5fb5501..0a02729 100644 --- a/examples/auto-jsx/index.js +++ b/examples/auto-jsx/index.js @@ -1,8 +1,10 @@ /* eslint-disable no-console */ 'use strict' exports.__esModule = true -const dom = (
Let's go
") as VHTMLDocument + const dom = parseHTML('Let's go
') as VHTMLDocument expect(dom.textContent).toMatchInlineSnapshot(`"Let's go"`) expect(dom.render()).toMatchInlineSnapshot(`"Let's go
"`) }) - it("should ignore escape for script etc.", () => { + it('should ignore escape for script etc.', () => { const html = `` - let dom = parseHTML(html) as VHTMLDocument + const dom = parseHTML(html) as VHTMLDocument expect(dom.textContent).toMatchInlineSnapshot(` " var x = 1 & 4 @@ -108,7 +109,7 @@ $('body') `) }) - it("should not recurse on bad fragment", () => { + it('should not recurse on bad fragment', () => { const tests = [ '<', '<<', diff --git a/src/manipulate.spec.ts b/src/manipulate.spec.ts index 1961a06..b8fb340 100644 --- a/src/manipulate.spec.ts +++ b/src/manipulate.spec.ts @@ -1,31 +1,37 @@ // Copyright (c) 2020 Dirk Holtwick. All rights reserved. https://holtwick.de/copyright -import { handleHTML } from "./manipulate" +import { handleHTML } from './manipulate' -describe("manipulate", () => { - - it("should manipulate html", () => { +describe('manipulate', () => { + it('should manipulate html', () => { const html = ` + +- This is a sample. And a link example. + This is a + {' '} + sample + . And a link + {' '} + example + .
- Some lines
line
line{" "}
+ Some lines
+ {' '}
+
+ {' '}
+ line
+ {' '}
+
+ {' '}
+ line
+ {' '}
-Do nothing
This is a sample. And a link example.
Some lines
line
line
' + 'Do nothing
This is a sample. And a link example.
Some lines
line
line
', ) tidyDOM(document) diff --git a/src/utils.spec.ts b/src/utils.spec.ts index c0c0bb1..838b0cd 100644 --- a/src/utils.spec.ts +++ b/src/utils.spec.ts @@ -1,20 +1,20 @@ // (C)opyright 2021-07-20 Dirk Holtwick, holtwick.it. All rights reserved. -import { removeBodyContainer } from "./utils" -import { createHTMLDocument } from "./vdom" +import { removeBodyContainer } from './utils' +import { createHTMLDocument } from './vdom' -describe("Utils", () => { - it("should remove doc stuff", () => { - let doc = createHTMLDocument() - doc.body?.appendChild(["Hello ", "world"]) - doc.title = "Hello Title" +describe('utils', () => { + it('should remove doc stuff', () => { + const doc = createHTMLDocument() + doc.body?.appendChild(['Hello ', 'world']) + doc.title = 'Hello Title' expect(doc.render()).toMatchInlineSnapshot( - `"Do nothing
Some
') }) - it("should convert styles key to camel case", () => { - let document = new VDocument() - let frag = new VDocumentFragment() - let p = document.createElement("p") - p.setAttribute("style", "text-align: center; background-color: red;") + it('should convert styles key to camel case', () => { + const document = new VDocument() + const frag = new VDocumentFragment() + const p = document.createElement('p') + p.setAttribute('style', 'text-align: center; background-color: red;') frag.appendChild(p) - let html = frag.render() - expect(p.style.textAlign).toBe("center") - expect(p.style.backgroundColor).toBe("red") + const html = frag.render() + expect(p.style.textAlign).toBe('center') + expect(p.style.backgroundColor).toBe('red') expect(html).toBe( - '' + '', ) }) - it("should have functional factory", () => { - let doc = createHTMLDocument() + it('should have functional factory', () => { + const doc = createHTMLDocument() doc.body?.replaceChildren( - h("p", { class: "lorem" }, "Hello ", h("b", { id: "foo" }, "World")), - h("hr") + h('p', { class: 'lorem' }, 'Hello ', h('b', { id: 'foo' }, 'World')), + h('hr'), ) - let r = doc.body + const r = doc.body expect(r).not.toBeNull() - if (!r) return + if (!r) + return expect(r.render()).toBe( - 'Hello World
Hello World
Hello World
' + expect(r.getElementById('foo')?.outerHTML).toEqual('World') + expect(r.getElementsByClassName('lorem')[0].outerHTML).toEqual( + 'Hello World
', ) - expect(r.matches("body")).toBe(true) - expect(r.matches("b")).toBe(false) + expect(r.matches('body')).toBe(true) + expect(r.matches('b')).toBe(false) - expect(r.querySelector("b")?.outerHTML).toEqual('World') - expect(r.querySelector("#foo")?.outerHTML).toEqual('World') - expect(r.querySelector(".lorem")?.outerHTML).toEqual( - 'Hello World
' + expect(r.querySelector('b')?.outerHTML).toEqual('World') + expect(r.querySelector('#foo')?.outerHTML).toEqual('World') + expect(r.querySelector('.lorem')?.outerHTML).toEqual( + 'Hello World
', ) - r.querySelector("#foo")?.replaceWith("Surprise") + r.querySelector('#foo')?.replaceWith('Surprise') expect(r.render()).toBe( - 'Hello Surprise
Hello Surprise
Hallo
Hallo
Hallo
Hallo
Hallo
Hallo
Hallo