@param {*} node
(node)
| 39 | |
| 40 | /** @param {*} node */ |
| 41 | function checkProps(node) { |
| 42 | if (!node.properties) { |
| 43 | return; |
| 44 | } |
| 45 | node.properties.forEach((prop) => { |
| 46 | if (!prop.key) { |
| 47 | return; |
| 48 | } |
| 49 | if (prop.computed) { |
| 50 | return; |
| 51 | } |
| 52 | const property = prop.key.name || prop.key.value; |
| 53 | |
| 54 | if (property?.toLowerCase?.() === 'tabindex') { |
| 55 | context.report({ |
| 56 | node: prop, |
| 57 | message: |
| 58 | '`tabindex` and `tabIndex` should be supported equally.' + |
| 59 | ' Instead of destructuring, use:' + |
| 60 | `\n\timport {tabindexFromProps} from '#preact/utils';` + |
| 61 | `\n\t<... tabindex={tabindexFromProps(rest)}>`, |
| 62 | }); |
| 63 | return; |
| 64 | } |
| 65 | |
| 66 | let preferred = ATTRIBUTES_REACT_TO_PREACT[property]; |
| 67 | let message = `Prefer \`${preferred}\` property access to \`${property}\`.`; |
| 68 | |
| 69 | if (preactNames.has(property)) { |
| 70 | preferred = property; |
| 71 | message = `Preact-style prop names \`${preferred}\` should be wrapped with \`${propNameFn}()\``; |
| 72 | } |
| 73 | |
| 74 | if (preferred) { |
| 75 | context.report({ |
| 76 | node: prop, |
| 77 | message, |
| 78 | fix(fixer) { |
| 79 | const fixes = []; |
| 80 | if (!addedImportDecl) { |
| 81 | addedImportDecl = true; |
| 82 | fixes.push( |
| 83 | lastImportDecl |
| 84 | ? fixer.insertTextAfter(lastImportDecl, importDecl) |
| 85 | : fixer.insertTextBefore(program.body[0], importDecl) |
| 86 | ); |
| 87 | } |
| 88 | const computed = `[${propNameFn}('${preferred}')]`; |
| 89 | fixes.push( |
| 90 | !prop.key.value |
| 91 | ? fixer.insertTextBefore(prop, `${computed}: `) |
| 92 | : fixer.replaceText(prop.key, computed) |
| 93 | ); |
| 94 | return fixes; |
| 95 | }, |
| 96 | }); |
| 97 | } |
| 98 | }); |
no test coverage detected