简体   繁体   English

我应该如何配置 eslint 以便所有 if 和 for 语句都被括号和换行符

[英]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我希望通过 eslint 来限制他们的行为,让 if 语句和 for 语句必须有括号换行符

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?我应该如何配置我的 eslint?

The curly rule is what you are searching for:卷曲规则是您要搜索的内容:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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