admin管理员组文章数量:1333487
I have the following code snippet:
const enclosing = () => {
const setClaim = (userId, claim) => {
client
.setClaim({ userId, claim })
.then(() => {
// do something
return resolve(true);
}, // eslint plains about this line
err => reject(err)
);
});
};
ESLint plains about the line marked above as follows:
139:9 error Expected indentation of 6 spaces but found 8 indent
Which indent
rule object option does apply here (has to be changed) as I want to keep the indentation as is?
I don't want to suppress the ESLint error using eslint-disable-line
as this is a global (applies to all of my code being linted) issue for me.
I have the following code snippet:
const enclosing = () => {
const setClaim = (userId, claim) => {
client
.setClaim({ userId, claim })
.then(() => {
// do something
return resolve(true);
}, // eslint plains about this line
err => reject(err)
);
});
};
ESLint plains about the line marked above as follows:
139:9 error Expected indentation of 6 spaces but found 8 indent
Which indent
rule object option does apply here (has to be changed) as I want to keep the indentation as is?
I don't want to suppress the ESLint error using eslint-disable-line
as this is a global (applies to all of my code being linted) issue for me.
-
2
It is the
indent
rule. – Alexander Zeitler Commented May 30, 2017 at 20:55 -
1
I would be more concerned about the mismatched parenthesis
)
on the second-to-last line… – Bergi Commented May 30, 2017 at 22:04 - One has to admit, that's a really weird indentation. Are you going to do this consistently for all multiline arguments, or only when it's a function, or only when there are multiple functions? – Bergi Commented May 30, 2017 at 22:05
- Yes, I think this is the root cause (done by WebStorm) – Alexander Zeitler Commented May 30, 2017 at 22:06
2 Answers
Reset to default 12In case you arrived here looking for Promise Indent answers like I did (see title)... The MemberExpression section of ESLint Indent rules may be helpful. Member expression "enforces indentation level for multi-line property chains".
You can turn off checking for indentation of chained methods by setting "MemberExpression"
to "Off"
in your .eslintrc.js
file.
rules: {
'indent': ['error', 4, { 'MemberExpression': 'off'}]
}
With MemberExpression set to "off", you can write your promises indented, or lined-up.
Lined Up
client
.setClaim({ userId, claim })
.then(resolve(true), reject)
Indented
client
.setClaim({ userId, claim })
.then(resolve(true), reject)
const enclosing = () => {
const setClaim = (userId, claim) => {
client
.setClaim({ userId, claim })
.then(() => {
// ^ insert a newline here
// do something
return resolve(true);
}, // eslint plains about this line
err => reject(err)
);
});
};
I suggest adding a new line before the fulfill handler. Since you give .then
two handlers, doing so can keep them at the same indentation level.
本文标签: javascriptWhich ESLint rule applies to PromiseArrow function indentStack Overflow
版权声明:本文标题:javascript - Which ESLint rule applies to PromiseArrow function indent? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742342128a2456814.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论