import-js / import-js/eslint-plugin-import
Newlines between custom path groups
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 5.9k
- Forks
- 1.5k
- PR merge metrics
- No merged PRs in 30d
Description
I want to define custom path groups such that there should be a new line between them.
eg. I've React, NextJs, MUI, and local folders (components, features, etc). I want to specify the rules such that React package will be on top, and NextJs and its related packages will be grouped into one, similarly, MUI and emotion packages, Redux, Redux persist, and Redux-toolkit.
**What I want**:
```
import React from "react";
import { NextPage } from "next";
import { AppProps } from "next/app";
import Head from "next/head";
import CssBaseline from "@mui/material/CssBaseline";
import { ThemeProvider } from "@mui/material/styles";
import { CacheProvider, EmotionCache } from "@emotion/react";
import { Provider } from "react-redux";
import { PersistGate } from "redux-persist/integration/react";
import { store, persistor } from "@store/index";
import createEmotionCache from "@shared/create-emotion-cache";
import { globalStyles } from "@shared/styles";
import theme from "@shared/theme";
```
**Current behavior with the below rules:**
```
import React from "react";
import { NextPage } from "next";
import { AppProps } from "next/app";
import Head from "next/head";
import CssBaseline from "@mui/material/CssBaseline";
import { ThemeProvider } from "@mui/material/styles";
import { CacheProvider, EmotionCache } from "@emotion/react";
import { Provider } from "react-redux";
import { PersistGate } from "redux-persist/integration/react";
import { store, persistor } from "@store/index";
import createEmotionCache from "@shared/create-emotion-cache";
import { globalStyles } from "@shared/styles";
import theme from "@shared/theme";
```
**Eslintrc.json**
```
"import/order": [
"error",
{
"pathGroupsExcludedImportTypes": ["react"],
"newlines-between": "always",
"alphabetize": {
"order": "asc",
"caseInsensitive": true
},
"groups": ["builtin", "external", "internal", "parent", "sibling", "index", "object"],
"pathGroups": [
{
"pattern": "react",
"group": "external",
"position": "before"
},
{
"pattern": "next",
"group": "external",
"position": "before"
},
{
"pattern": "**/next/**",
"group": "external",
"position": "before"
},
{
"pattern": "**/@mui/**",
"group": "external",
"position": "before"
},
{
"pattern": "**/@emotion/**",
"group": "external",
"position": "before"
},
{
"pattern": "react-redux",
"group": "external",
"position": "before"
},
{
"pattern": "redux-persist/**",
"group": "external",
"position": "before"
},
{
"pattern": "**/@store/**",
"group": "internal",
"position": "before"
},
{
"pattern": "**/@layout/**",
"group": "internal",
"position": "before"
},
{
"pattern": "**/@screens/**",
"group": "internal",
"position": "before"
},
{
"pattern": "**/@features/**",
"group": "internal",
"position": "before"
},
{
"pattern": "**/@components/**",
"group": "internal",
"position": "before"
},
{
"pattern": "**/@services/**",
"group": "internal",
"position": "before"
},
{
"pattern": "**/@hooks/**",
"group": "internal",
"position": "before"
},
{
"pattern": "**/@shared/**",
"group": "internal",
"position": "before"
},
{
"pattern": "**/@interfaces/**",
"group": "internal",
"position": "before"
},
{
"pattern": "**/@utils/**",
"group": "internal",
"position": "before"
},
{
"pattern": "**/@config/**",
"group": "internal",
"position": "before"
},
{
"pattern": "**/@events/**",
"group": "internal",
"position": "before"
}
]
}
],
```
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the import/order rule, focusing on how pathGroups and newlines-between are currently interpreted. Compare the requested grouped output with the current behavior and inspect the rule's existing regression coverage. Done means custom path groups can define the requested blank-line boundaries without disrupting ordering or existing newline behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- eslint, javascript
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100