Prettier options

const lastWorked = results[0] ? results[0].lastwork : Date.now();
const schema = results[0]
? results[0]
: new schemas.user({ user: message.author.id });

How can I make that both will be in 1 line?

message.channel.send(
    "somelongtextbutitshouldstayinthebracketsononeline"
);

How can I change the amount of characters before move the string on the next line?

I would like to know that as well…

Hi!

You can create a file .prettierc in your project to specify options for the code formatter.

The options are described here.

For what you want to do I think you need printWidth, see here.

E.g. .prettierrc:

{
  "printWidth": 100
}
const schema = results[0]
? results[0]
: new schemas.user({ user: message.author.id });

And for something like those?

schemas.user
			.find({
				user: message.author.id
			})
			.then((results) => {

Hi Robin,

Everything will be formatted according to the rules you give in .prettierrc. So if you specified printWidth: 100 all lines will be formatted to fit in 100 characters when you click “Format This File”. So it should also work for the example you gave.

It doesn’t work for those.

What exactly are you trying to accomplish?

Once you have lines of code on different lines, e.g.:

.find({
    user: message.author.id
})

the code formatter won’t change it into one line, if that’s what you mean.

{
“arrowParens”: “always”,
“bracketSpacing”: false,
“printWidth”: 200,
“semi”: true,
“singleQuote”: true,
“tabWidth”: 4,
“useTabs”: true
}

schemas.user
.find({
user: message.author.id
})

I want then schemas.user.find on the same line

As I said above once you’ve put statements on different lines, the formatter won’t change them. I don’t think you can change that, but I’m not very familiar with all the options. Good luck!

1 Like