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

react/no-this-in-sfc: eslint-plugin-react 7.25.0 interprets an old legacy jQuery plugin as a sfc #3054

Closed
doberkofler opened this issue Aug 29, 2021 · 7 comments · Fixed by #3056

Comments

@doberkofler
Copy link

I get lot's of false positive react/no-this-in-sfc warnings in Typescript (*.ts) Files.
It seems as if TypeScript files with ts (not just tsx) extension would be regarded as react files and of type $.fn.<lowercase>... = function (): <type> | null would be interpreted as an sfc:

$.fn.getValueAsStringWeak = function (): string | null {
	const val = this.length === 1 ? this.val() : null;

	return typeof val === 'string' ? val : null;
};
@ljharb
Copy link
Member

ljharb commented Aug 29, 2021

Does this not happen in v7.24.0?

@doberkofler
Copy link
Author

doberkofler commented Aug 29, 2021

Does this not happen in v7.24.0?

Yes, it does this not happen in v7.24.0

@ljharb
Copy link
Member

ljharb commented Aug 29, 2021

I’d expect this to not be identified as a component since it’s not a PascalCase-named function.

@ljharb
Copy link
Member

ljharb commented Aug 29, 2021

Using git bisect, this appears to have been introduced by 9a8a4b5 / #2992 / @Wesitos.

@Wesitos
Copy link
Contributor

Wesitos commented Aug 29, 2021

I found this equivalent false positive. I'm debugging this. Not sure how it broke.

obj.notAComponent = function () {
  return this.a || null;
};`

@ljharb
Copy link
Member

ljharb commented Aug 29, 2021

I’ve got a local test case as well i can tack on if you make a PR :-)

@Wesitos
Copy link
Contributor

Wesitos commented Aug 29, 2021

I just noticed that I also modified getStatelessComponent. Well... that explains it :b.

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

Successfully merging a pull request may close this issue.

3 participants