|
1 |
| -import { validTagName, reservedTags, PCENChar, builtInTagMap } from 'eslint-plugin-custom-elements/lib/tag-names.js' |
| 1 | +import { validTagName, reservedTags, PCENChar, builtInTagMap } from "eslint-plugin-custom-elements/lib/tag-names.js" |
2 | 2 |
|
3 | 3 | const validChar = new RegExp(`^${PCENChar}$`)
|
4 | 4 |
|
5 |
| -customElements.define('tag-name-input', class extends HTMLInputElement { |
6 |
| - |
7 |
| - connectedCallback() { |
8 |
| - this.addEventListener('input', this) |
9 |
| - this.handleEvent() |
10 |
| - } |
| 5 | +customElements.define( |
| 6 | + "tag-name-input", |
| 7 | + class extends HTMLInputElement { |
| 8 | + connectedCallback() { |
| 9 | + this.addEventListener("input", this) |
| 10 | + this.handleEvent() |
| 11 | + } |
11 | 12 |
|
12 |
| - handleEvent() { |
13 |
| - const {value} = this |
14 |
| - this.setCustomValidity('') |
15 |
| - let hint = '' |
16 |
| - if (value) { |
17 |
| - if (/[A-Z]/.test(value)) { |
18 |
| - this.setCustomValidity(`${value} is not valid, it cannot contain capital letters`) |
19 |
| - } else if (reservedTags.has(value)) { |
20 |
| - this.setCustomValidity(`${value} is not valid, it's a reserved tag`) |
21 |
| - } if (!(value.includes('-'))) { |
22 |
| - this.setCustomValidity(`${value} is not valid, it must include a dash (-)`) |
23 |
| - } else if (value.startsWith('-')) { |
24 |
| - this.setCustomValidity(`${value} is not valid, it must not start with a dash (-)`) |
25 |
| - } else if (!(/^[a-z]/.test(value))) { |
26 |
| - this.setCustomValidity(`${value} is not valid, it must start with a letter (a-z)`) |
27 |
| - } else if (!validTagName(value)) { |
28 |
| - const chars = new Set() |
29 |
| - for (const char of value) { |
30 |
| - if (!(validChar.test(char))) chars.add(`'${char}'`) |
| 13 | + handleEvent() { |
| 14 | + const { value } = this |
| 15 | + this.setCustomValidity("") |
| 16 | + let hint = "" |
| 17 | + if (value) { |
| 18 | + if (/[A-Z]/.test(value)) { |
| 19 | + this.setCustomValidity(`${value} is not valid, it cannot contain capital letters`) |
| 20 | + } else if (reservedTags.has(value)) { |
| 21 | + this.setCustomValidity(`${value} is not valid, it's a reserved tag`) |
31 | 22 | }
|
32 |
| - this.setCustomValidity(`${value} is not a valid tag name, cannot contain ${[...chars].join(', ')}`) |
33 |
| - } |
34 |
| - |
35 |
| - const parts = value.split(/-/g) |
36 |
| - for (const part in parts) { |
37 |
| - if (part in builtInTagMap) { |
38 |
| - hint = `${value} is similar to the built-in ${builtInTagMap[part]}` |
| 23 | + if (!value.includes("-")) { |
| 24 | + this.setCustomValidity(`${value} is not valid, it must include a dash (-)`) |
| 25 | + } else if (value.startsWith("-")) { |
| 26 | + this.setCustomValidity(`${value} is not valid, it must not start with a dash (-)`) |
| 27 | + } else if (!/^[a-z]/.test(value)) { |
| 28 | + this.setCustomValidity(`${value} is not valid, it must start with a letter (a-z)`) |
| 29 | + } else if (!validTagName(value)) { |
| 30 | + const chars = new Set() |
| 31 | + for (const char of value) { |
| 32 | + if (!validChar.test(char)) chars.add(`'${char}'`) |
| 33 | + } |
| 34 | + this.setCustomValidity(`${value} is not a valid tag name, cannot contain ${[...chars].join(", ")}`) |
39 | 35 | }
|
40 |
| - } |
41 | 36 |
|
| 37 | + const parts = value.split(/-/g) |
| 38 | + for (const part in parts) { |
| 39 | + if (part in builtInTagMap) { |
| 40 | + hint = `${value} is similar to the built-in ${builtInTagMap[part]}` |
| 41 | + } |
| 42 | + } |
| 43 | + } |
| 44 | + this.reportValidity() |
| 45 | + const errorEl = this.parentElement.querySelector(".error span") |
| 46 | + errorEl.textContent = this.validationMessage |
| 47 | + const hintEl = this.parentElement.querySelector(".hint span") |
| 48 | + hintEl.textContent = hint |
42 | 49 | }
|
43 |
| - this.reportValidity() |
44 |
| - const errorEl = this.parentElement.querySelector('.error span') |
45 |
| - errorEl.textContent = this.validationMessage |
46 |
| - const hintEl = this.parentElement.querySelector('.hint span') |
47 |
| - hintEl.textContent = hint |
48 |
| - } |
49 |
| - |
50 |
| -}, { extends: 'input' }) |
| 50 | + }, |
| 51 | + { extends: "input" } |
| 52 | +) |
0 commit comments