sindresorhus/eslint-plugin-unicorn
View on GitHubRule proposal: `try-maximum-statements`
Open
#651 opened on Mar 31, 2020
help wantednew rule
Description
The rule name may be called unicorn/try-maximum-statements.
The idea is to avoid try on whole code blocks and encourage the developer to target the exact line statement of code that is expecting to throw.
Should we add a parameter to customize the maximum number of line statement or hardcode it to 1 line of code? 🤔
Note that I'm not a native english speaker so please fix the rule/option names.
Enforce a maximum number of lines statements to try
Applies to try clauses.
The maximum number of triable lines statements of code configurable, but defaults to 1.
This rule is not fixable.
Fail
try {
doSomething();
doSomethingElse();
} catch (err) {
// …
}
Pass
try {
doSingleThing();
} catch (err) {
// …
}
Options
maximumNumberOfStatement
Type: number
You can set the maximum number of statements like this:
"unicorn/try-maximum-statement": [
"error",
{
"maximumNumberOfStatement": 2
}
]