Rule proposal: `try-maximum-statements`
See original GitHub issueThe 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
}
]
Issue Analytics
- State:
- Created 3 years ago
- Reactions:6
- Comments:29 (10 by maintainers)
Top Results From Across the Web
Proposed rule: Order Competition Rule - SEC.gov
proposed rule would prohibit a restricted competition trading center from internally executing certain orders of individual investors at a ...
Read more >SEC Proposes Equity Market Overhaul and Best Execution Rule
The SEC is proposing to amend Regulation NMS to (1) amend the tick sizes under Rule 612 to establish a variable minimum pricing...
Read more >eslint-plugin-unicorn - Bountysource
Rule proposal: Use `Array.includes()` instead of repeated conditional checks $ 0 ... The rule name may be called unicorn/try-maximum-statements .
Read more >Federal Register/Vol. 87, No. 41/Wednesday, March 2, 2022 ...
Rule 614(e ) requires participants to the effective national market system plan(s) for NMS stocks to file by November 5, 2021, an amendment...
Read more >sindresorhus/eslint-plugin-unicorn (Raised $2856.00)
Rule proposal: Prefer explicit array check over `Array#flat()`. Unfunded#1719created byfisker. $0.00.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Name:
try-maximum-statements
@yvele Instead of lines, how about we limit it to one statement? And maybe also an option to allow a
return
statement at the end in addition.I still feel like “number of lines” is too naive.
For example, the below is still one statement: