For example, you can disable warnings for an entire file using:
disable lint rules for entire file
JavaScript
/* eslint-disable */
import { Client } from "@gadget-client/<YOUR-APP-SLUG>";
export const api = new Client({ environment: "development" });
/* eslint-disable */
import { Client } from "@gadget-client/<YOUR-APP-SLUG>";
export const api = new Client({ environment: "development" });
You can also disable lint rules per line:
disable lint rules per line
JavaScript
export const api = new Client({ environment: "development" }); // eslint-disable-line
// eslint-disable-next-line
export const api = new Client({ environment: "development" });
export const api = new Client({ environment: "development" }); // eslint-disable-line
// eslint-disable-next-line
export const api = new Client({ environment: "development" });
Errors
These rules relate to errors in your Gadget project and must be fixed.
gadget/no-action-file-imports
Importing from action files is not allowed.
To fix these errors:
call the action using your api client in the action context
create utility files for any shared functions, variables, or clients, and import from the utility file.
no-action-file-imports error
JavaScript
// error - do not import from action files
import { run as runCreateProduct } from "../models/product/actions/create";
export const run: ActionRun = async ({ api }) => {
// not allowed
await runCreateProduct();
};
// error - do not import from action files
import { run as runCreateProduct } from "../models/product/actions/create";
export const run: ActionRun = async ({ api }) => {
// not allowed
await runCreateProduct();
};
Fix this issue by calling actions with the api client included in your context param:
call actions using api client
JavaScript
export const run: ActionRun = async ({ api }) => {
// call actions using api client in action/route context param
await api.product.create();
};
export const run: ActionRun = async ({ api }) => {
// call actions using api client in action/route context param
await api.product.create();
};
Warnings
These rules relate to possible problems in your Gadget project.
gadget/no-client-static-environment-usage
Recommend dynamic environment selection when initializing Gadget API clients.
This is an example of a static environment used to set up an API client:
static setup of an API client
JavaScript
import { Client } from "@gadget-client/<YOUR-APP-SLUG>";
export const api = new Client({ environment: "Development" });
import { Client } from "@gadget-client/<YOUR-APP-SLUG>";
export const api = new Client({ environment: "Development" });
And this is how a client can be initialized dynamically:
dynamic setup of an API client
JavaScript
import { Client } from "@gadget-client/<YOUR-APP-SLUG>";
export const api = new Client({ environment: window.gadgetConfig.environment });
import { Client } from "@gadget-client/<YOUR-APP-SLUG>";
export const api = new Client({ environment: window.gadgetConfig.environment });
gadget/no-hardcoded-shopify-shops
See Accessing the Shopify API for more detailed information on when to use the shopify connection's current property.
Typically you should avoid hardcoding Shopify shops when using the shopify client in actions.