简体   繁体   中英

How should I configure eslint so that all if and for statements are bracketed and newline

I don't like the following style of code


const flag = Math.random() > 0.5;

if (flag) console.log('A');
else console.log('B');

for (let index = 0; index < 999; index++) console.log(index);

I hope to restrict their behavior through eslint, so that if statements and for statements must have parentheses and newlines

const flag = Math.random() > 0.5;

if (flag) {
  console.log('A');
} else {
  console.log('B');
}

for (let index = 0; index < 999; index++) {
  console.log(index);
}

How should I configure my eslint?

The curly rule is what you are searching for:

https://eslint.org/docs/latest/rules/curly

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM