Intellicode / eslint-plugin-react-native

React Native plugin for ESLint
MIT License
722 stars 130 forks source link

Remove dependency on @babel/traverse to fix linting issues #314

Closed hsource closed 1 year ago

hsource commented 2 years ago

Motivation

Fixes #270. babel-traverse expects that it's passed an entire tree that spans to the top of the program. eslint does not guarantee that, which causes crashes when parsing some programs (see #270 for many examples).

Fix

Testing

Added automated test based on repro case from #270: https://github.com/Intellicode/eslint-plugin-react-native/issues/270#issuecomment-897766305

sonarcloud[bot] commented 2 years ago

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 1 Code Smell

No Coverage information No Coverage information
0.0% 0.0% Duplication

JLHwung commented 2 years ago

Babel's maintainer here.

https://github.com/Intellicode/eslint-plugin-react-native/blob/4b7149ea7019d288d6318dfabb05461f3134a975/lib/rules/no-raw-text.js#L52-L53

I am worried by the usage of @babel/traverse here:

In #270, Babel is constructing a new scope when it visits a Function () => {} in the JSXOpeningElement <foo bar={() => {}} />. It should work if the passed scope is created by Babel traverse, so that Babel can find all the way up to the program scope. But since we are passing an ESLint scope, it results to an obscure internal Babel error.

This PR looks good to me. If we want to be future-proof, we can get the visitorKeys of JSXOpeningElement from context.getSourceCode().visitorKeys and traverse accordingly.

hsource commented 2 years ago

@Intellicode I think this quick PR should resolve #270, which has seen a lot of activity. Can you help take a look?

peterpme commented 1 year ago

Merged into https://github.com/peterpme/eslint-plugin-react-native

peterpme commented 1 year ago

Merged into https://github.com/peterpme/eslint-plugin-react-native

Intellicode commented 1 year ago

Thanks for the fix @hsource, sorry for the late review, life got in the way

peterpme commented 1 year ago

Thank you @Intellicode!

I saw your README. I would be happy to take this over and maintain it. I work closely with React Native & the Expo team and would be honored to be passed the torch