npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

eslint-plugin-mui-sx-order

v1.7.0

Published

Auto-sorts MUI sx/style props for clean, consistent code with ESLint

Downloads

24

Readme

🚀 ESLint Plugin to Auto-Sort MUI sx Properties

An ESLint plugin and rule with autofix that automatically sorts Material-UI (MUI) sx style properties for consistent, clean, and maintainable code. Works great with React/Next.js, Prettier, JavaScript and TypeScript.


Table of Contents


🌟 Why Use This Plugin?

Maintaining a consistent and logical order of MUI sx style properties is critical for:

  • ✅ Code readability
  • ✅ Easier debugging and maintenance
  • ✅ Team-wide styling best practices

This plugin:

  • 🔥 Automatically sorts sx properties in your React components
  • 📦 Supports nested selectors (&:hover) and responsive breakpoints (xs, sm, md)
  • ⚡ Works with ESLint and Prettier for a seamless developer experience

✨ Key Features

  • 📦 Automatic sorting (ESLint rule with autofix) of all sx properties, even nested objects
  • 🔥 Supports pseudo-classes, nested selectors, and media query keys
  • 🛠 Fully compatible with eslint --fix
  • 🚀 Supports JavaScript and TypeScript projects out of the box
  • 📦 Built with TypeScript for better type safety and maintainability
  • ⚡ Zero dependencies → ultra-fast linting

🔥 Why not just use Prettier?

Prettier is great for formatting, but it doesn’t understand the logical groups of MUI sx properties. This ESLint rule enforces a best-practice order (optimized for MUI System sx):

  1. Positioning: position, top, right, zIndex, and others.
  2. Display & Layout: display, boxSizing, visibility, and others.
  3. Flexbox: flex, flexBasis, flexDirection, and others.
  4. Grid: grid, gridArea, gridTemplate, and others.
  5. Spacing & Box Model: width, minWidth, maxWidth, and others.
  6. Typography: font, fontFamily, fontSize, and others.
  7. Background & Effects: background, backgroundColor, boxShadow, and others.
  8. Transitions & Animations: transition, animation, transform, and others.

📦 Install

Add the plugin to your project as a dev dependency:

npm i -D eslint-plugin-mui-sx-order

or with Yarn:

yarn add -D eslint-plugin-mui-sx-order

⚙️ Configuration Example

For .eslintrc.js (CommonJS format):

module.exports = {
  plugins: ['mui-sx-order'],
  rules: {
    'mui-sx-order/sort-sx-properties': 'warn',
  },
};

For .eslintrc or .eslintrc.json (JSON format):

{
  "plugins": ["mui-sx-order"],
  "rules": {
    "mui-sx-order/sort-sx-properties": "warn"
  }
}

For .eslint.config.js (ES module format):

import muiSxOrder from 'eslint-plugin-mui-sx-order';

export default {
  plugins: {
    'mui-sx-order': muiSxOrder,
  },
  rules: {
    'mui-sx-order/sort-sx-properties': 'warn',
  },
};

🛠 Usage & Auto-fix

You can automatically fix the property order using:

npx eslint --fix .

This will sort all sx properties in your project.


Before / After (Autofix)

Before (unsorted sx):

// React / MUI
<Box sx={{ padding: 2, margin: 1, backgroundColor: '#eee' }} />

After (autofix by ESLint rule):

<Box sx={{ margin: 1, padding: 2, backgroundColor: '#eee' }} />

Multiline object:

// Before
const sx = {
  backgroundColor: '#f5f5f5',
  position: 'relative',
  padding: 8,
  margin: 16,
  display: 'flex',
};

// After (eslint --fix)
const sx = {
  position: 'relative',
  display: 'flex',
  margin: 16,
  padding: 8,
  backgroundColor: '#f5f5f5',
};

Responsive and nested selectors are handled too:

const sx = {
  sm: { margin: 1, padding: 2 },
  '&:hover': { backgroundColor: '#f5f5f5' },
};

FAQ

  • Is this compatible with Prettier?
    Yes. Prettier handles formatting; this plugin enforces logical property order via an ESLint rule with autofix.

  • Will it reorder across spread props?
    No. ...spread blocks are preserved; the rule safely reorders only adjacent properties around them.

  • Does it sort nested objects and responsive breakpoints?
    Yes. Nested objects (e.g., &:hover) and responsive keys (xs, sm, md, lg, xl) are supported.

  • Does it touch non-MUI code?
    The rule targets sx/style-like objects; for createStyles, it only applies when imported from MUI packages.

  • What ESLint/Node versions are supported?
    Node.js 18+, ESLint 8+. Tested with React 18 and Next.js.

Useful links:

  • MUI System sx: https://mui.com/system/getting-started/the-sx-prop/
  • ESLint Rules and Autofix: https://eslint.org/docs/latest/extend/custom-rules

📢 Perfect for Teams & Open Source Projects

Ensure a consistent style guide for all MUI projects in your team. Great for large codebases where property order matters for readability.


🛠 Development

This plugin is built with TypeScript for better type safety and maintainability.

Prerequisites

  • Node.js >= 18
  • npm or yarn

Setup

# Install dependencies
npm install

# Build the project
npm run build

# Run tests
npm test

# Watch mode for development
npm run dev

Project Structure

src/
├── index.ts                 # Main plugin entry point
├── lib/
│   ├── types.ts            # TypeScript type definitions
│   ├── rules/
│   │   └── sort-sx-properties.ts # Main rule implementation
│   └── utils/
│       ├── preferredOrder.ts    # CSS property ordering
│       ├── propertyUtils.ts     # Utility functions
│       └── checkAndReport.ts    # Linting logic

📜 License

This project is licensed under the MIT License - see the LICENSE file for details.