Skip to content

Commit cb22cce

Browse files
authored
run npm run format
1 parent e06d840 commit cb22cce

File tree

3 files changed

+47
-46
lines changed

3 files changed

+47
-46
lines changed

learn/components/naming-your-components.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ There are some specific rules that you must adhere to to make a valid tag name:
1616
- It _can_ contain underscores, and numbers.
1717
- It _can_ contain characters from different alphabets, such as `é`, `ð`, `ö`, ``.
1818

19-
An invalid name will cause a `DOMException` to be thrown when you set up your custom element.
19+
An invalid name will cause a `DOMException` to be thrown when you set up your custom element.
2020

2121
Try typing a tag name below to see if it's a valid custom element tag:
2222

@@ -59,8 +59,7 @@ DOMException: CustomElementRegistry.define: 'annotation-xml' is not a valid cust
5959

6060
## Tips on naming element
6161

62-
While none of the following is prescriptive, here are some tips and tricks on how to pick a good name for your
63-
elements:
62+
While none of the following is prescriptive, here are some tips and tricks on how to pick a good name for your elements:
6463

6564
### Avoid splitting compound words
6665

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"start": "eleventy --serve",
1919
"check": "prettier --check . && npm run spell",
2020
"spell": "mdspell --en-us --report **/*.md *.md",
21-
"format": "prettier --fix ."
21+
"format": "prettier --write ."
2222
},
2323
"stylelint": {
2424
"extends": "stylelint-config-standard"

script/tag-name-input.js

Lines changed: 44 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,52 @@
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"
22

33
const validChar = new RegExp(`^${PCENChar}$`)
44

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+
}
1112

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`)
3122
}
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(", ")}`)
3935
}
40-
}
4136

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
4249
}
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

Comments
 (0)