|
1
|
--- |
|
2
|
sidebar_label: "widget-zone-must-be-string-literal" |
|
3
|
--- |
|
4
|
|
|
5
|
export const metadata = { |
|
6
|
title: `widget-zone-must-be-string-literal - ESLint plugin rules`, |
|
7
|
} |
|
8
|
|
|
9
|
# {metadata.title} |
|
10
|
|
|
11
|
This rule requires the `zone` property in `defineWidgetConfig` to be a string literal or an array of string literals. |
|
12
|
|
|
13
|
## Severity |
|
14
|
|
|
15
|
`error`. This rule is enabled in the [recommended](../../page.mdx#recommended) preset. |
|
16
|
|
|
17
|
## What it Targets |
|
18
|
|
|
19
|
This rule targets files in your project's `src/admin/widgets` directory. It reports a `zone` property whose value isn't a string literal, an array of string literals, or a template literal without expressions. |
|
20
|
|
|
21
|
The following code is reported by the rule: |
|
22
|
|
|
23
|
```tsx title="src/admin/widgets/product-widget.tsx" |
|
24
|
import { defineWidgetConfig } from "@medusajs/admin-sdk" |
|
25
|
|
|
26
|
const ZONE = "product.details" |
|
27
|
|
|
28
|
export const config = defineWidgetConfig({ |
|
29
|
zone: ZONE, |
|
30
|
}) |
|
31
|
``` |
|
32
|
|
|
33
|
Instead, use a string literal: |
|
34
|
|
|
35
|
```tsx title="src/admin/widgets/product-widget.tsx" |
|
36
|
import { defineWidgetConfig } from "@medusajs/admin-sdk" |
|
37
|
|
|
38
|
export const config = defineWidgetConfig({ |
|
39
|
zone: "product.details", |
|
40
|
}) |
|
41
|
``` |
|
42
|
|
|
43
|
## Why it's Important |
|
44
|
|
|
45
|
Medusa statically analyzes widget files to determine the zones a widget is injected into. A dynamic `zone` value can't be resolved at build time, so the widget may not render in the expected location. |
|
46
|
|
|
47
|
Learn more in the [Admin Development Constraints documentation](!docs!/learn/fundamentals/admin/constraints). |
|
48
|
|
|
49
|
## Fixable |
|
50
|
|
|
51
|
This rule is auto-fixable. Run the linter with the `--fix` option to apply the fix automatically. |