Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add prefer-optional-catch-binding rule #671

Merged

Conversation

fisker
Copy link
Collaborator

@fisker fisker commented Apr 9, 2020

Fixes #670

Note: I'm not check destructuring, so the following code will pass

try {} catch({message}) {}

This can get really complicated,

Case 1:

try {} catch({nonExistsProperty = thisWillExecute()}) {}

In this case nonExistsProperty is not used, removing thisWillExecute() is not safe.

Case 2:

try {} catch({a, b = a}) {}

I'm not sure we can track both a and b.

Note2: white spaces not removed.

@fisker
Copy link
Collaborator Author

fisker commented Apr 25, 2020

@sindresorhus This is ready, have to land in v20 now :(

@sindresorhus
Copy link
Owner

Sorry, I misunderstood. I thought you intended to fix https://github.com/sindresorhus/eslint-plugin-unicorn/pull/671/files#diff-52502d7490c2a15f41e0def7598c29a4R109 in this PR and I was waiting for that.

@fisker
Copy link
Collaborator Author

fisker commented Apr 25, 2020

Right. I forgot that, now we have time, I'll try to fix it.

@fisker
Copy link
Collaborator Author

fisker commented Apr 25, 2020

try {
} catch(error) {
	var error = 1;
}

This one seems hard to fix, the core rule no-unused-vars has lots of code to check, really too complicated. And it's only about var because you can't

try {
} catch(error) {
	const error = 1;
}
// VM170:3 Uncaught SyntaxError: Identifier 'error' has already been declared

OR

try {
} catch(error) {
	function error(){}
}
// VM191:3 Uncaught SyntaxError: Identifier 'error' has already been declared

I'm going to give up.

If people really want that, we can improve later.

@sindresorhus
Copy link
Owner

And it's only about var because you can't

Just leave it. I really don't care about var.

In general, just ignore any legacy syntax. We should not waste time on that.

@fisker
Copy link
Collaborator Author

fisker commented Apr 25, 2020

I alway try to to better, if it's not hard . :)

@fisker
Copy link
Collaborator Author

fisker commented Apr 25, 2020

Integration test failure due to https://github.com/then/is-promise/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc , they publish a module:type package with wrong main field.

@fisker
Copy link
Collaborator Author

fisker commented May 1, 2020

Are we good to merge?

@sindresorhus sindresorhus merged commit efdb03a into sindresorhus:master May 1, 2020
@fisker fisker deleted the rule/prefer-optional-catch-binding branch May 1, 2020 07:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Rule proposal: prefer-optional-catch-binding
2 participants