|
1
|
--- |
|
2
|
sidebar_label: "data-model-table-name-snake-case" |
|
3
|
--- |
|
4
|
|
|
5
|
export const metadata = { |
|
6
|
title: `data-model-table-name-snake-case - ESLint plugin rules`, |
|
7
|
} |
|
8
|
|
|
9
|
# {metadata.title} |
|
10
|
|
|
11
|
This rule requires that the name passed to `model.define(name, ...)` is snake_case. |
|
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 data model files in your project's `src/modules` directory. It reports the name passed to `model.define(name, ...)` when it isn't snake_case (lowercase letters, digits, and underscores, starting with a letter). |
|
20
|
|
|
21
|
The following code is reported by the rule: |
|
22
|
|
|
23
|
```ts title="src/modules/blog/models/post.ts" |
|
24
|
import { model } from "@medusajs/framework/utils" |
|
25
|
|
|
26
|
export const Post = model.define("blogPost", { |
|
27
|
id: model.id().primaryKey(), |
|
28
|
}) |
|
29
|
``` |
|
30
|
|
|
31
|
Instead, use a snake_case name: |
|
32
|
|
|
33
|
```ts title="src/modules/blog/models/post.ts" |
|
34
|
import { model } from "@medusajs/framework/utils" |
|
35
|
|
|
36
|
export const Post = model.define("blog_post", { |
|
37
|
id: model.id().primaryKey(), |
|
38
|
}) |
|
39
|
``` |
|
40
|
|
|
41
|
## Why it's Important |
|
42
|
|
|
43
|
The data model name is used to derive the database table name. A consistent snake_case name keeps table names predictable and aligned with Medusa's database conventions. |
|
44
|
|
|
45
|
Learn more in the [Data Models documentation](!docs!/learn/fundamentals/data-models). |
|
46
|
|
|
47
|
## Fixable |
|
48
|
|
|
49
|
This rule is auto-fixable. Run the linter with the `--fix` option to apply the fix automatically. |
|
50
|
|
|
51
|
## Turn it Off |
|
52
|
|
|
53
|
To turn off this rule, set it to `off` in your ESLint configuration: |
|
54
|
|
|
55
|
```ts title="eslint.config.ts" |
|
56
|
import { defineConfig } from "eslint/config" |
|
57
|
import medusa from "@medusajs/eslint-plugin" |
|
58
|
|
|
59
|
export default defineConfig([ |
|
60
|
...medusa.configs.recommended, |
|
61
|
{ |
|
62
|
rules: { |
|
63
|
"@medusajs/data-model-table-name-snake-case": "off", |
|
64
|
}, |
|
65
|
}, |
|
66
|
]) |
|
67
|
``` |
|
68
|
|
|
69
|
Or disable it for a single line using an inline comment: |
|
70
|
|
|
71
|
```ts |
|
72
|
// eslint-disable-next-line @medusajs/data-model-table-name-snake-case |
|
73
|
export const Post = model.define("blogPost", {}) |
|
74
|
``` |