MCPcopy
hub / github.com/vercel/next.js / JSXOpeningElement

Function JSXOpeningElement

packages/eslint-plugin-next/src/rules/no-img-element.ts:28–53  ·  view source on GitHub ↗
(node)

Source from the content-addressed store, hash-verified

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})

Callers

nothing calls this directly

Calls 2

reportMethod · 0.80
testMethod · 0.65

Tested by

no test coverage detected