-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: [a11y-input-has-name-attribute]Inputにreact-hook-formのregisterが指定されている場合はエラーにならないようにする #490
base: master
Are you sure you want to change the base?
Conversation
fabb54b
to
3eddb5a
Compare
|
||
if (nodeName.match(TARGET_TAG_NAME_REGEX)) { | ||
const nameAttr = node.attributes.find(findNameAttr) | ||
const nameAttr = attributes.find(findNameAttr) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ロジック自体は大丈夫そうですが、attributesに対するチェックを最適化すると良いかも。
今の方法だと複数回attributesに対して操作が走る可能性があります。
let nameAttr = null
let hasSpreadAttr = false
let hasReactHookFormRegisterSpreadAttr = false
let hasRadioInput = false
attributes.forEach((attr) => {
if (a.type === 'JSXSpreadAttribute') {
hasSpreadAttr = true
if (hasReactHookFormRegisterSpreadAttr == false && a.argument?.callee?.name === 'register') {
hasReactHookFormRegisterSpreadAttr = true
}
} else {
switch (a.name?.name) {
case 'name': {
nameAttr = a
break
}
case 'type': {
if (a.value.value === 'radio') {
hasRadioInput = true
}
break
}
}
}
})
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
この方法ならattributesに対する検査は1loopだけで済むので高速化できます
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@AtsushiM 添付のコードにあるhasSpreadAttr
やhasRadioInput
にはbooleanを代入するだけでどこでも使われていないようなのですが、どういった意味があるのでしょうか?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@yamakeeeeeeeeen
以下の箇所で都度someをしている箇所を置き換える想定です。
https://github.com/kufu/tamatebako/pull/490/files#diff-9bc6cdcc4ece3aff163a028a8962d667e77b90463af87f220e4464d8e4f9e3bbR90
https://github.com/kufu/tamatebako/pull/490/files#diff-9bc6cdcc4ece3aff163a028a8962d667e77b90463af87f220e4464d8e4f9e3bbR99
現在のロジックではattributes配列に対して、最大3回ループする可能性があり、処理が重いので1oopですべての計算を済ませてしまえば軽くなるよね!という感じの対応です
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
もともと nameAttr
を生成するためにattributesを一度はループする必要があるので、そのついでに他の計算もしてしまおう、という発想です
やりたいこと
<Input {...register('name')} />
やったこと