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.

Support for different keyword-spacing with optional catch binding syntax

See original GitHub issue

What rule do you want to change?

keyword-spacing

Does this change cause the rule to produce more or fewer warnings?

Fewer, depending on other configuration (Never more)

How will the change be implemented? (New option, new default behavior, etc.)?

Probably new option

Please provide some example code that this change will affect:

try {
	foo();
} catch(ex) {
	return console.error(ex);
}

// https://tc39.es/proposal-optional-catch-binding/
try {
	foo();
} catch { // This is the root issue
	return console.error("Failed");
}

What does the rule currently do for this code?

With "catch": {"after": false} the first example is, as expected, correct, however when ignoring the thrown error like in the bottom example it still expects you to not have a space after the catch thus causing obviously ugly code.

What will the rule do after it’s changed?

My idea is to add a seperate rule, something like catchNoBody which defaults to whatever catch is set to but allows you to have a different keyword-spacing for catch clauses like the second one

Are you willing to submit a pull request to implement this change?

I probably would not know how to properly implement this seeing the need for inheritance so no.

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
mdjermanoviccommented, Jun 12, 2020

I reopened this thinking it was a bug, but now it looks more like an enhancement to me.

keyword-spacing controls spaces between catch and (, catch and {.

space-before-blocks controls spaces between ) and {, so keyword-spacing shouldn’t enforce anything there.

With the actual schema, I think it’s impossible for keyword-spacing to know that user wants catch(e), but at the same time catch { instead of catch{, so this would most likely need a new option.

(this is somewhat similar to the else++foo issue, a difference is that this one doesn’t seem to be an edge case)

1reaction
anikethsahacommented, Jun 12, 2020

I think this should be re-open! cause it is bug and it will be agreed by the new policy as well

Read more comments on GitHub >

github_iconTop Results From Across the Web

ES2019: optional catch binding
This function is an example of wrapping and documenting code that ignores caught exceptions. Use case: feature detection #. The following code ...
Read more >
babel/plugin-syntax-optional-catch-binding
Syntax only. It's unlikely you want to use this plugin directly as it only enables Babel to parse this syntax.
Read more >
Optional catch Binding in TypeScript
TypeScript 2.5 implemented the optional catch binding proposal, which changes the ECMAScript grammar to allow for the omission of the variable  ...
Read more >
Rules - ESLint - Pluggable JavaScript Linter
A pluggable and configurable linter tool for identifying and reporting on patterns in JavaScript. Maintain your code quality with ease.
Read more >
Optional catch binding
This Software may be subject to third party rights (rights from parties other than Ecma International), including patent rights, and no licenses ...
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