prettier / eslint-config-prettier

Turns off all rules that are unnecessary or might conflict with Prettier.
MIT License
5.4k stars 254 forks source link

How to make a for loop declaration stay on one line? #144

Closed mdasfour closed 4 years ago

mdasfour commented 4 years ago

Hello,

In a typescript file that I am working on, prettier automatically moves what is in between the brackets of the for loop declaration on a separate line, like so:

for ( let s = 0; s < a.length; s++ )

I want it to be like this:

for ( let s = 0; s < a.length; s++ )

I have searched and tried different ways of getting it to format the way I want it, but to no avail. Is there anyway I can go about getting prettier to format it the way I want?

Thanks.

lydell commented 4 years ago

Hi!

Generally speaking, you can’t influence what Prettier does. It decides on formatting so humans don’t need to think (or discuss!) about it.

This config does not change Prettier in any way. All it does is turning off a bunch of ESLint rules.

Note that even with 4-space indentation, it takes a fair amount of nesting before Prettier breaks your for loop like that:

Prettier 2.0.4 Playground link

--parser babel
--tab-width 4

Input:

{{{{{{{{{{{{
for (
let s = 0;
s < a.length;
s++
);
}}}}}}}}}}}}

Output:

{
    {
        {
            {
                {
                    {
                        {
                            {
                                {
                                    {
                                        {
                                            {
                                                for (
                                                    let s = 0;
                                                    s < a.length;
                                                    s++
                                                );
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}

So maybe the solution is to refactor your code a little bit?

mdasfour commented 4 years ago

Hi Simon,

Sorry for the late reply. Thank you very much for your prompt response and help. I appreciate it.

Thanks.