The styled-import rule ensures that styled components are imported from the correct @emotion/styled package instead of the legacy react-emotion package.
Validates and auto-fixes styled component imports to use the modern @emotion/styled package.
/**
* Rule for ensuring styled is imported from @emotion/styled
* Automatically fixes imports from legacy react-emotion package
*/
interface StyledImportRuleConfig {
name: "styled-import";
fixable: true;
schema: never[]; // No configuration options
messages: {
incorrectImport: string;
};
}The rule:
{
"rules": {
"@emotion/styled-import": "error"
}
}Incorrect code for this rule:
import styled from 'react-emotion';
const Button = styled.button`
background: blue;
color: white;
`;Correct code for this rule:
import styled from '@emotion/styled';
const Button = styled.button`
background: blue;
color: white;
`;The rule will automatically fix simple default imports:
Before:
import styled from 'react-emotion';After (auto-fixed):
import styled from '@emotion/styled';Note: Complex import patterns (destructured imports, namespace imports) are reported but not auto-fixed for safety reasons.
This rule is part of the Emotion 10 to 11 migration toolkit. It helps migrate from:
react-emotion → @emotion/styledUse alongside other migration rules:
{
"rules": {
"@emotion/jsx-import": "error",
"@emotion/no-vanilla": "error",
"@emotion/import-from-emotion": "error",
"@emotion/styled-import": "error"
}
}Disable this rule if: