The no-vanilla rule prevents usage of vanilla @emotion/css in React applications, encouraging the use of @emotion/react instead.
Detects and reports usage of @emotion/css package imports in React contexts.
/**
* Rule for preventing vanilla emotion usage in React applications
* Reports @emotion/css imports as violations
*/
interface NoVanillaRuleConfig {
name: "no-vanilla";
fixable: false; // Only reports, no auto-fix
schema: never[]; // No configuration options
messages: {
vanillaEmotion: string;
};
}The rule:
{
"rules": {
"@emotion/no-vanilla": "error"
}
}Incorrect code for this rule:
import { css } from '@emotion/css';
const styles = css`
color: hotpink;
background: white;
`;Correct code for this rule:
import { css } from '@emotion/react';
const styles = css`
color: hotpink;
background: white;
`;In React applications, prefer @emotion/react:
Avoid:
import { css } from '@emotion/css';
function MyComponent() {
return <div className={css`color: red;`}>Hello</div>;
}Prefer:
import { css } from '@emotion/react';
function MyComponent() {
return <div css={css`color: red;`}>Hello</div>;
}This rule is part of the Emotion 10 to 11 migration guidelines. Use with other migration rules:
{
"rules": {
"@emotion/jsx-import": "error",
"@emotion/no-vanilla": "error",
"@emotion/import-from-emotion": "error",
"@emotion/styled-import": "error"
}
}The rule enforces these benefits:
Disable this rule if:
Instead of @emotion/css, consider:
@emotion/react for React applications@emotion/styled for styled components