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

feat(linter) eslint-plugin-react(no-is-mounted) #1033

Closed
wants to merge 2 commits into from

Conversation

aminpaks
Copy link

No description provided.

@CLAassistant
Copy link

CLAassistant commented Oct 23, 2023

CLA assistant check
All committers have signed the CLA.

@github-actions github-actions bot added the A-linter Area - Linter label Oct 23, 2023
@aminpaks aminpaks force-pushed the amin/react-no-is-mounted branch 6 times, most recently from b67c4a2 to aad36a8 Compare October 23, 2023 02:53
@aminpaks aminpaks marked this pull request as ready for review October 23, 2023 02:54
Copy link
Member

@Boshen Boshen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your first contribution!

@codspeed-hq
Copy link

codspeed-hq bot commented Oct 23, 2023

CodSpeed Performance Report

Merging #1033 will not alter performance

Comparing aminpaks:amin/react-no-is-mounted (accacb6) with main (854b55a)

Summary

✅ 22 untouched benchmarks

Copy link
Member

@Boshen Boshen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need a quick cargo fmt.

By the way, the test in the plugin checks for MethodDefinition, by there are no accompany failure case for it 🤔 https://github.com/jsx-eslint/eslint-plugin-react/blob/9da1bb0f4aa44849b56e8c2064afd582ea8b36f8/lib/rules/no-is-mounted.js#L43-L50

@aminpaks aminpaks force-pushed the amin/react-no-is-mounted branch from aad36a8 to accacb6 Compare October 23, 2023 11:55
@aminpaks
Copy link
Author

aminpaks commented Oct 23, 2023

@Boshen

Need a quick cargo fmt.

By the way, the test in the plugin checks for MethodDefinition, by there are no accompany failure case for it 🤔 https://github.com/jsx-eslint/eslint-plugin-react/blob/9da1bb0f4aa44849b56e8c2064afd582ea8b36f8/lib/rules/no-is-mounted.js#L43-L50

I think it's testing if any ancestors has a binding of isMounted no it's no this case, I'm wondering what it's testing with the ancestors:

var Hello = createReactClass({
        someFn: this.isMounted,
	componentDidUpdate: function() {
	if (this.someFn()) {
		return;
	}
	},
	render: function() {
	return <div>Hello</div>;
	}
});

I don't know how to achieve this in oxc parser. How do I walk the tree to the root?

@camc314
Copy link
Contributor

camc314 commented Oct 23, 2023

to see how to access parent nodes, take a look at logic where we do:

ctx.nodes().parent_node(node.id()):

it returns an option of the parent node

e.g. here: we are walking up the tree, checking the kind of the parent

https://github.com/web-infra-dev/oxc/blob/25247e3839afcb3fc1c0640e6bc49adf6d61f3ad/crates/oxc_linter/src/rules/react/jsx_key.rs#L74-L83

@aminpaks aminpaks marked this pull request as draft October 24, 2023 00:35
@aminpaks
Copy link
Author

aminpaks commented Oct 24, 2023

👋 @camc314

Is this how we're supposed to implement the ancestors' walk?

I'm not sure but I don't think it would pass in our case. Even when I looked at the ESLint AST I can't find any references to "MethodDefinition" or "Property" in the tree 🤷

@Boshen
Copy link
Member

Boshen commented Oct 24, 2023

👋 @camc314

Is this how we're supposed to implement the ancestors' walk?

We also have the ancestors you may try for cleaner code. https://github.com/web-infra-dev/oxc/blob/2483e5cbf1776d025b6c8fea2fe5a170817555d0/crates/oxc_linter/src/rules/deepscan/bad_comparison_sequence.rs#L59-L74

I'm not sure but I don't think it would pass in our case. Even when I looked at the ESLint AST I can't find any references to "MethodDefinition" or "Property" in the tree 🤷

You can try our playground https://web-infra-dev.github.io/oxc/playground/

It seems to be MethodDefinition and ObjectProperty in our AST.

@camc314
Copy link
Contributor

camc314 commented Dec 5, 2023

Closed in favour of #1550

@camc314 camc314 closed this Dec 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-linter Area - Linter
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants