Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enforce (fix) imports to be fully on a single line

I have the following eslint config:

   "object-curly-newline": ["error", {
        "ImportDeclaration": "never",
        "ExportDeclaration": "never"
    }],

That transforms:

import { 
    something,
    somethingelse, 
} from "../here";

to

import { something,
    somethingelse, } from "../here";

but I'd like to get my import so it goes to a single line. Like so:

import { something, somethingelse, } from "../here";

Is there a way to do this within "object-curly-newline"? Or can I accomplish it via some other rule? I've tried the various other properties, but haven't had any luck.

like image 963
Mark Nenadov Avatar asked Oct 17 '25 16:10

Mark Nenadov


1 Answers

I believe this might be related to the multiline setting of object-curly-newline, depending on your settings.

"multiline": true requires line breaks if there are line breaks inside properties or between properties. Otherwise, it disallows line breaks.

That is what I noticed in my situation.

enter image description here

You can see which rule applies before saving, by hovering over the red or yellow underlines. In my case these were shown underneath the curly braces.

like image 146
Michiel Pater Avatar answered Oct 20 '25 06:10

Michiel Pater



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!