R
R
Rhunadan2021-02-02 15:46:10
JavaScript
Rhunadan, 2021-02-02 15:46:10

How to configure JavaScript arrow function wrapping in VS Code?

There is a function:

const calculate = (firstNum, secondNum, operationType) => operations[operationType](firstNum, secondNum);

which exceeds 100 characters and wraps around after being saved in the editor like so:
const calculate = (firstNum, secondNum, operationType) =>
  operations[operationType](firstNum, secondNum);

which is against the implicit-arrow-linebreak linting rule. Compliance with all the rules is mandatory, and I write it as follows:
const calculate = (
  firstNum,
  secondNum,
  operationType,
) => operations[operationType](firstNum, secondNum);

Linter is satisfied with this entry, but Ctrl + S brings it back to the form:
const calculate = (firstNum, secondNum, operationType) =>
  operations[operationType](firstNum, secondNum);

I can't figure out if Prettier does this or some other setting. How to fix them? Thank you.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
profesor08, 2021-02-02
@profesor08

Can't figure out Prettier does it

It is the most direct when saving the file.
On a good note, the correct configs should be configured within the project. Just a couple of config files that are pulled up and based on them, the code is checked. This is necessary so that different projects have the opportunity to use different rules and environment settings do not spoil anything.

D
davidnum95, 2021-02-02
@davidnum95

Prettier has its own formatting config, try to demolish it and install Prettier ESLint

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question