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

jquery: emit warning or error for .done() and .fail() #564

Open
NovemLinguae opened this issue Apr 18, 2024 · 2 comments
Open

jquery: emit warning or error for .done() and .fail() #564

NovemLinguae opened this issue Apr 18, 2024 · 2 comments

Comments

@NovemLinguae
Copy link

Using jQuery's .done() or .fail() instead of native JS promises .then() or catch():

  1. contradicts the advice at https://www.mediawiki.org/wiki/Manual:Coding_conventions/JavaScript#Asynchronous_code

  2. led to some nasty bugs in one repo I was working with, for example, this patch

I'd suggest adding something like the below to our jQuery rules. Code below credit Kosta Harlan.

"no-restricted-syntax": [
	"error",
	{
		"message": "Using .done() is not allowed. See https://www.mediawiki.org/wiki/Manual:Coding_conventions/JavaScript#Asynchronous_code",
		"selector": "MemberExpression > Identifier[name=\"done\"]"
	},
	{
		"message": "Using .fail() is not allowed. See https://www.mediawiki.org/wiki/Manual:Coding_conventions/JavaScript#Asynchronous_code",
		"selector": "MemberExpression > Identifier[name=\"fail\"]"
	}
],
@jdforrester
Copy link
Member

Should this instead be a new https://github.com/wikimedia/eslint-plugin-no-jquery rule? @edg2s, thoughts?

@edg2s
Copy link
Member

edg2s commented Apr 18, 2024

It would probably make sense to add the rules to the plugin, although they will be quite distinct from other rules, in that the apply to neither the $ global object, or a $collection. That said "done" and "fail" are quite uncommon names for methods outside of promises.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants