medusa-context-on-context-param - ESLint plugin rules

This rule requires that service method parameters typed Context are decorated with @MedusaContext().

Severity#

warn. This rule is enabled in the recommended preset.

What it Targets#

This rule targets service files in your project's src/modules directory. It reports a method parameter typed Context on a service class when the parameter isn't decorated with @MedusaContext().

The following code is reported by the rule:

src/modules/blog/service.ts
1import { MedusaService } from "@medusajs/framework/utils"2import { Context } from "@medusajs/framework/types"3
4class BlogModuleService extends MedusaService({}) {5  async list(sharedContext: Context = {}) {}6}

Instead, decorate the parameter with @MedusaContext():

src/modules/blog/service.ts
1import {2  MedusaService,3  MedusaContext,4} from "@medusajs/framework/utils"5import { Context } from "@medusajs/framework/types"6
7class BlogModuleService extends MedusaService({}) {8  async list(9    @MedusaContext() sharedContext: Context = {}10  ) {}11}

Why it's Important#

The @MedusaContext() decorator injects the shared context, which carries the transaction and entity manager. Without it, the context isn't propagated and operations may run outside the intended transaction.

Learn more in the Database Operations in Service documentation.

Fixable#

This rule is auto-fixable. Run the linter with the --fix option to apply the fix automatically.

Turn it Off#

To turn off this rule, set it to off in your ESLint configuration:

eslint.config.ts
1import { defineConfig } from "eslint/config"2import medusa from "@medusajs/eslint-plugin"3
4export default defineConfig([5  ...medusa.configs.recommended,6  {7    rules: {8      "@medusajs/medusa-context-on-context-param": "off",9    },10  },11])

Or disable it for a single line using an inline comment:

Code
1// eslint-disable-next-line @medusajs/medusa-context-on-context-param2async list(sharedContext: Context = {}) {}
Was this page helpful?
Ask Bloom
For assistance in your development, use Claude Code Plugins or Docs MCP server in Cursor, VSCode, etc...FAQ
What is Medusa?
How can I create a module?
How can I create a data model?
How do I create a workflow?
How can I extend a data model in the Product Module?
Recipes
How do I build a marketplace with Medusa?
How do I build digital products with Medusa?
How do I build subscription-based purchases with Medusa?
What other recipes are available in the Medusa documentation?
Chat is cleared on refresh
Line break
⇧↵