Skip to content

Commit fd85608

Browse files
authored
Merge pull request #125 from github/st-update-method-name-checker
Update method name checker to clear message
2 parents 6c86d59 + 8a4c9c1 commit fd85608

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)