Skip to content

Commit 8a4c9c1

Browse files
committed
Update method name checker to clear message
Currently, if the user fills out the form and then empties the field, they still see the "This is a good name" message. That message should go away if the input is empty.
1 parent 1c07831 commit 8a4c9c1

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

docs/_guide/anti-patterns.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,14 +142,18 @@ When naming a method, you should avoid naming it something that already exists o
142142
const goodEl = document.querySelector('.js-methodname-shadow-good-input')
143143
const badEl = document.querySelector('.js-methodname-shadow-bad-input')
144144
const warnEl = document.querySelector('.js-methodname-shadow-warn-input')
145+
if (name === '') {
146+
goodEl.hidden = true
147+
return
148+
}
145149
let warning = warnings[name]
146150
if (name !== name.toLowerCase() && name.toLowerCase() in HTMLElement.prototype) {
147151
warning = `it is too similar to \`${name.toLowerCase()}\` which already exists`
148152
} else if (name.startsWith('on') && !(name in HTMLElement.prototype)) {
149153
warning = 'starting with `on` suggests a coupling between the event and the method (see below)'
150154
}
151155
goodEl.hidden = warning || (name in HTMLElement.prototype)
152-
warnEl.hidden = !warning
156+
warnEl.hidden = !warning
153157
badEl.hidden = warning || !(name in HTMLElement.prototype)
154158
if (warning) {
155159
warnEl.querySelector('span').textContent = warning

0 commit comments

Comments
 (0)