Repository navigation
Support ESLint 10 in @react-native/eslint-config - #59071
usama-liaqat wants to merge 1 commit into
Conversation
|
Hi @usama-liaqat! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
|
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
|
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
Summary:
@react-native/eslint-configdeclares support foreslint ^8 || ^9, but apps on the latest ESLint (10.x) can't use it. Under ESLint 10:@babel/eslint-parser7 crashes on every file (scopeManager.addGlobals is not a function). Version 8 supports ESLint 10 but requires@babel/core8, which Metro doesn't support yet.@react-native/eslint-plugin-specscallscontext.getFilename()andcontext.getSourceCode(), which ESLint 10 removed.eslint-plugin-react,eslint-plugin-react-native,eslint-plugin-ft-flowand the unmaintainedeslint-plugin-eslint-commentsstill use removed rule-context APIs.eslint-plugin-jestpulled in a nested@typescript-eslint/utils8.39, which crashes on load under ESLint 10.This PR makes the flat config (
@react-native/eslint-config/flat) work on ESLint 9 and 10, and leaves the legacy ESLint 8 config (extends: '@react-native') unchanged:.js/.jsxwithflow-eslintinstead of@babel/eslint-parser. It supports Flow and JSX, it's the parser the monorepo already uses, and it doesn't read the app's Babel config. That also fixes a parse error on@flowfiles when@react-native/babel-presetuses hermes-parser.fixupPluginRulesfrom@eslint/compat.@eslint-community/eslint-plugin-eslint-comments, registered under the sameeslint-commentskey, so rule names and existing disable comments still work. The legacy config keeps the original plugin.react-native-modulesusescontext.filenameandcontext.sourceCode, with fallbacks to the method forms for older ESLint 8 releases.no-unused-vars:caughtErrors: 'none'is now set explicitly. That was the ESLint 8 default, so ESLint 9 and 10 report the same as 8.eslint-plugin-jest(^29.17.0),eslint-plugin-react-hooks(^7.1.1) and@typescript-eslint/*(^8.71.2) to versions that support ESLint 10, and refreshed the lockfile so the stale nested@typescript-eslint/utilsis deduped.eslintis now^8.0.0 || ^9.0.0 || ^10.0.0.The monorepo's own lint setup is unchanged; it stays on ESLint 8 and
.eslintrc.js.Known upstream issue: ESLint's built-in
no-unused-varscrashes on some Flowdeclare classdeclarations in ESLint 9 and 10, with both flow-eslint and hermes-eslint. The bug is in ESLint itself, not this config.Changelog:
[GENERAL] [ADDED] -
@react-native/eslint-config: support ESLint 10; the flat config now parses JavaScript withflow-eslintTest Plan:
Repo checks, still on ESLint 8:
The prettier config test now also checks every block in
flat.js, so no block re-enables a rule thateslint-config-prettierturns off.Consumer smoke test: I ran
npm packon@react-native/eslint-configand@react-native/eslint-plugin, installed them into a sample app viaoverrides, and linted.js(Flow + JSX),.tsx,.tsand__tests__files:no-unused-vars,@react-native/no-deep-imports,react-native/no-inline-styles,@typescript-eslint/no-unused-varsand@typescript-eslint/no-shadow..eslintrcconfig: works as before. The one@flowfile fails withCannot read properties of undefined (reading 'forEach'), and so does unchangedmainwith@react-native/babel-preset0.84, so this PR doesn't cause it.@react-native/eslint-plugin-specson ESLint 10:react-native-modulesreports an invalidNativeSeeded.jsspec ('AnyTypeAnnotation' is unsupported in NativeModule specs) instead of throwing.