question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Rule proposal: `try-maximum-statements`

See original GitHub issue

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
	}
]

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:6
  • Comments:29 (10 by maintainers)

github_iconTop GitHub Comments

4reactions
sindresorhuscommented, May 1, 2020

Name: try-maximum-statements

3reactions
sindresorhuscommented, Apr 25, 2020

@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:

try {
	result = foo
		.someMethodChainMethod1()
		.someMethodChainMethod2()
		.someMethodChainMethod3()
} catch {}
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found