Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to format order import styles css module to first line in eslint-plugin-import?

I am trying to config ESLint for my project that using eslint-plugin-import to ogranize module import order but I have a case with style css module. I want to place style css module import to the first line. How I can config to get my expected?
Here is my lint config for that:

.eslintrc.json

    "import/order": [
        "warn",
        {
            "groups": ["builtin", "object", "external", "internal", "type", "parent", "sibling", "index"],
            "pathGroups": [
                {
                    "pattern": "~/**",
                    "group": "internal",
                    "position": "after"
                },
                {
                    "pattern": "**/*.{css,scss}",
                    // How I can config here?
                },
            ],
            "newlines-between": "always"
        }
    ]

My expected:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

import '../styles/style.css'; 

import React from 'react';

import * as utils from '../utils'

>Solution :

To configure ESLint to place style CSS module imports at the top, you can adjust your ESLint configuration as follows:

"import/order": [
    "warn",
    {
        "groups": [["builtin", "external"], "internal", ["parent", "sibling", "index"]],
        "pathGroups": [
            {
                "pattern": "~/**",
                "group": "internal",
                "position": "after"
            },
            {
                "pattern": "**/*.{css,scss}",
                "group": "external",
                "position": "before"
            }
        ],
        "newlines-between": "always"
    }
]
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading