Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit a93b221

Browse files
committedMar 27, 2023
docs: add docs for prefer-ideal-image rule
Signed-off-by: Devansu <devansuyadav@gmail.com>
1 parent f76aa15 commit a93b221

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed
 

Diff for: ‎website/docs/api/misc/eslint-plugin/README.mdx

+1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ For more fine-grained control, you can also enable the plugin manually and confi
5454
| [`@docusaurus/string-literal-i18n-messages`](./string-literal-i18n-messages.mdx) | Enforce translate APIs to be called on plain text labels ||
5555
| [`@docusaurus/no-html-links`](./no-html-links.mdx) | Ensures @docusaurus/Link is used instead of `<a>` tags ||
5656
| [`@docusaurus/prefer-docusaurus-heading`](./prefer-docusaurus-heading.mdx) | Ensures @theme/Heading is used instead of `<hn>` tags for headings ||
57+
| [`@docusaurus/prefer-ideal-image`](./prefer-ideal-image.mdx) | Ensures @theme/IdealImage is used instead of `<img>` tags for embedding images | |
5758

5859
✅ = recommended
5960

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
---
2+
slug: /api/misc/@docusaurus/eslint-plugin/prefer-ideal-image
3+
---
4+
5+
# prefer-ideal-image
6+
7+
Ensure that the `<IdealImage />` component provided by [`@theme/IdealImage`](../../plugins/plugin-ideal-image.mdx) Docusaurus plugin is used instead of `<img>` tags.
8+
9+
The `@theme/IdealImage` Docusaurus plugin generates an almost ideal image (responsive, lazy-loading, and low quality placeholder).
10+
11+
## Rule Details {#details}
12+
13+
Examples of **incorrect** code for this rule:
14+
15+
```html
16+
<img src="./path/to/img.png" alt="some alt text" />
17+
18+
<img src={require('./path/to/img.png')} alt='some alt text' />
19+
20+
<img
21+
src="./path/to/img.png"
22+
srcset="./path/to/img-480w.jpg 480w, ./path/to/img-800w.png 800w"
23+
sizes="(max-width: 600px) 480px, 800px"
24+
alt="some alt text" />
25+
```
26+
27+
Examples of **correct** code for this rule:
28+
29+
```javascript
30+
import Image from '@theme/IdealImage';
31+
32+
<IdealImage img='./path/to/img.png' />
33+
34+
<IdealImage img={require('./path/to/img.png')} />
35+
36+
<IdealImage
37+
img={{
38+
src: {
39+
src: './path/to/img.png',
40+
preSrc: '',
41+
images: [{ width: 100 }]
42+
},
43+
preSrc: './path/to/placeholder.png'
44+
}}
45+
/>
46+
```

0 commit comments

Comments
 (0)
Please sign in to comment.