| 26 | |
| 27 | return { |
| 28 | JSXOpeningElement(node) { |
| 29 | if (node.name.name !== 'img') { |
| 30 | return |
| 31 | } |
| 32 | |
| 33 | if (node.attributes.length === 0) { |
| 34 | return |
| 35 | } |
| 36 | |
| 37 | if (node.parent?.parent?.openingElement?.name?.name === 'picture') { |
| 38 | return |
| 39 | } |
| 40 | |
| 41 | // If is metadata route files, ignore |
| 42 | // e.g. opengraph-image.js, twitter-image.js, icon.js |
| 43 | if ( |
| 44 | isAppDir && |
| 45 | /\/opengraph-image|twitter-image|icon\.\w+$/.test(relativePath) |
| 46 | ) |
| 47 | return |
| 48 | |
| 49 | context.report({ |
| 50 | node, |
| 51 | message: `Using \`<img>\` could result in slower LCP and higher bandwidth. Consider using \`<Image />\` from \`next/image\` or a custom image loader to automatically optimize images. This may incur additional usage or cost from your provider. See: ${url}`, |
| 52 | }) |
| 53 | }, |
| 54 | } |
| 55 | }, |
| 56 | }) |