You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
letmut diagnostic = OxcDiagnostic::warn("Using `<img>` could result in slower LCP and higher bandwidth.")
13
+
.with_help("Consider using `<Image />` from `next/image` or a custom image loader to automatically optimize images.\nSee https://nextjs.org/docs/messages/no-img-element")
14
+
.with_label(span.label("Use `<Image />` from `next/image` instead."));
15
+
ifletSome(src_span) = src_span {
16
+
diagnostic = diagnostic.and_label(src_span.label("Use a static image import instead."));
17
+
}
18
+
diagnostic
12
19
}
13
20
14
21
#[derive(Debug,Default,Clone)]
@@ -17,16 +24,45 @@ pub struct NoImgElement;
17
24
declare_oxc_lint!(
18
25
/// ### What it does
19
26
///
27
+
/// Prevent the usage of `<img>` element due to slower
28
+
/// [LCP](https://nextjs.org/learn/seo/lcp) and higher bandwidth.
20
29
///
21
30
/// ### Why is this bad?
22
31
///
32
+
/// `<img>` elements are not optimized for performance and can result in
33
+
/// slower LCP and higher bandwidth. Using [`<Image />`](https://nextjs.org/docs/pages/api-reference/components/image)
34
+
/// from `next/image` will automatically optimize images and serve them as
35
+
/// static assets.
23
36
///
24
37
/// ### Example
38
+
///
39
+
/// Examples of **incorrect** code for this rule:
40
+
/// ```javascript
41
+
/// export function MyComponent() {
42
+
/// return (
43
+
/// <div>
44
+
/// <img src="/test.png" alt="Test picture" />
45
+
/// </div>
46
+
/// );
47
+
/// }
48
+
/// ```
49
+
///
50
+
/// Examples of **correct** code for this rule:
25
51
/// ```javascript
52
+
/// import Image from "next/image";
53
+
/// import testImage from "./test.png"
54
+
/// export function MyComponent() {
55
+
/// return (
56
+
/// <div>
57
+
/// <Image src={testImage} alt="Test picture" />
58
+
/// </div>
59
+
/// );
60
+
/// }
26
61
/// ```
27
62
NoImgElement,
28
63
nextjs,
29
-
correctness
64
+
correctness,
65
+
pending // TODO: add `import Image from "next/image"` (if missing), then change `<img />` to `<Image />`
30
66
);
31
67
32
68
implRuleforNoImgElement{
@@ -39,18 +75,16 @@ impl Rule for NoImgElement {
39
75
return;
40
76
};
41
77
42
-
if jsx_opening_element_name.name.as_str() != "img"{
0 commit comments