Rules
no-barrel-import
no-barrel-import
Severity: warn
Rule ID:Good:Detected patterns:
Rule ID:
react-doctor/no-barrel-importDetects imports from barrel/index files. Barrel files can prevent tree-shaking and include unnecessary code in your bundle.Why it’s bad:- Bundlers may include entire barrel file
- Tree-shaking often fails with barrel exports
- Slower build times
/index, /index.js, /index.ts, /index.tsx, /index.mjsno-full-lodash-import
no-full-lodash-import
Severity: warn
Rule ID:Good:
Rule ID:
react-doctor/no-full-lodash-importPrevents importing the entire lodash library. The full lodash library is ~70kb minified, but you typically only need a few functions.Bad:With proper tree-shaking configuration,
lodash-es can be imported directly. But lodash (CommonJS) always requires per-function imports.no-moment
no-moment
Severity: warn
Rule ID:Good:Bundle sizes:
Rule ID:
react-doctor/no-momentSuggests using date-fns or dayjs instead of moment.js. Moment.js is 300kb+ minified and no longer maintained.Bad:- moment.js: ~300kb
- date-fns: ~13kb (with tree-shaking)
- dayjs: ~2kb
prefer-dynamic-import
prefer-dynamic-import
Severity: warn
Rule ID:Good:
Rule ID:
react-doctor/prefer-dynamic-importRecommends code splitting for heavy libraries using React.lazy() or next/dynamic.Heavy libraries detected:- @monaco-editor/react
- recharts
- @react-pdf/renderer
- react-quill
- @codemirror/view
- chart.js
- draft-js
use-lazy-motion
use-lazy-motion
Severity: warn
Rule ID:Good:Bundle savings:
Rule ID:
react-doctor/use-lazy-motionEnforces using LazyMotion with the m export instead of the full motion export from framer-motion. This saves ~30kb in bundle size.Bad:- Full
motion: ~60kb LazyMotion+domAnimation: ~30kb- Savings: ~30kb (50%)
no-undeferred-third-party
no-undeferred-third-party
Severity: warn
Rule ID:Good:defer vs async:
Rule ID:
react-doctor/no-undeferred-third-partyRequires defer or async attributes on third-party <script> tags. Synchronous scripts block the browser’s first paint.Bad:defer: Script executes after HTML parsing, in orderasync: Script executes as soon as downloaded, out of order- Use
deferfor scripts that depend on DOM or other scripts - Use
asyncfor independent scripts like analytics
Bundle Analysis Tools
Use these tools to analyze your bundle:Best Practices
Import Strategy
- Direct imports for tree-shakeable libraries
- Dynamic imports for heavy components
- Avoid barrel files in your own code
- Per-function imports for lodash and similar utilities
Code Splitting
- Split routes/pages by default
- Lazy load heavy components (editors, charts, maps)
- Lazy load rarely-used features
- Use Suspense boundaries strategically
Related Rules
- Performance Rules - Runtime performance
- Next.js Rules - Next.js-specific optimizations