1 ---
2 sidebar_label: "link-uses-linkable-properties"
3 ---
4
5 export const metadata = {
6 title: `link-uses-linkable-properties - ESLint plugin rules`,
7 }
8
9 # {metadata.title}
10
11 This rule requires arguments to `defineLink` to be of the form `Module.linkable.<dataModel>` or an object with a `linkable: Module.linkable.<dataModel>` property.
12
13 ## Severity
14
15 `warn`. 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/links` directory. It reports `defineLink` arguments that don't reference a module's `linkable` property.
20
21 The following code is reported by the rule:
22
23 ```ts title="src/links/product-post.ts"
24 import { defineLink } from "@medusajs/framework/utils"
25 import ProductModule from "@medusajs/medusa/product"
26
27 export default defineLink(ProductModule, {
28 foo: "bar",
29 })
30 ```
31
32 Instead, reference each module's `linkable` property:
33
34 ```ts title="src/links/product-post.ts"
35 import { defineLink } from "@medusajs/framework/utils"
36 import ProductModule from "@medusajs/medusa/product"
37 import BlogModule from "../modules/blog"
38
39 export default defineLink(
40 ProductModule.linkable.product,
41 BlogModule.linkable.post
42 )
43 ```
44
45 You can also pass an object with a `linkable` property to set options such as `isList`:
46
47 ```ts title="src/links/product-post.ts"
48 export default defineLink(
49 ProductModule.linkable.product,
50 { linkable: BlogModule.linkable.post, isList: true }
51 )
52 ```
53
54 When linking to a data model by its id (for example, linking to draft orders via `OrderModule.linkable.order.id`), the `.id` suffix on the linkable property is also valid:
55
56 ```ts title="src/links/vendor-draft-order.ts"
57 import { defineLink } from "@medusajs/framework/utils"
58 import MarketplaceModule from "../modules/marketplace"
59 import OrderModule from "@medusajs/medusa/order"
60
61 export default defineLink(
62 MarketplaceModule.linkable.vendor,
63 { linkable: OrderModule.linkable.order.id, isList: true }
64 )
65 ```
66
67 ## Why it's Important
68
69 A module's `linkable` property exposes the data models that can participate in a link. Referencing it ensures Medusa can resolve the linked records correctly at runtime.
70
71 Learn more in the [Module Links documentation](!docs!/learn/fundamentals/module-links).
72
73 ## Fixable
74
75 This rule isn't auto-fixable.
76
77 ## Turn it Off
78
79 To turn off this rule, set it to `off` in your ESLint configuration:
80
81 ```ts title="eslint.config.ts"
82 import { defineConfig } from "eslint/config"
83 import medusa from "@medusajs/eslint-plugin"
84
85 export default defineConfig([
86 ...medusa.configs.recommended,
87 {
88 rules: {
89 "@medusajs/link-uses-linkable-properties": "off",
90 },
91 },
92 ])
93 ```
94
95 Or disable it for a single line using an inline comment:
96
97 ```ts
98 // eslint-disable-next-line @medusajs/link-uses-linkable-properties
99 export default defineLink(ProductModule, { foo: "bar" })
100 ```