mirror of
https://github.com/react/react-native.git
synced 2026-09-28 05:13:06 +08:00
Summary: When trying to use the `react-native/eslint-config` with ESLint v9, we get an issue with the `eslint-plugin-ft-flow`: ```bash Oops! Something went wrong! :( ESLint: 9.39.2 TypeError: Error while loading rule 'ft-flow/define-flow-type': context.getAllComments is not a function ``` Looking into it, I noticed that our current version (`^2.0.0`) does not support ESLint v9. Only in version `^3.0.11` it show as a valid peer dependency version. So, although we do have a flat config, we don't support ESLint v9 out of the box. ## Changelog: <!-- Help reviewers and the release process by writing your own changelog entry. Pick one each for the category and type tags: [ANDROID|GENERAL|IOS|INTERNAL] [BREAKING|ADDED|CHANGED|DEPRECATED|REMOVED|FIXED|SECURITY] - Message For more details, see: https://reactnative.dev/contributing/changelogs-in-pull-requests --> [General] [Fixed] - Fixed the issue when using the flat config with ESLint v9. Pull Request resolved: https://github.com/react/react-native/pull/55628 Test Plan: I've made a repro repo: https://github.com/tcK1/Repro-ESLint9-RN Updated the ESLint version to v9 and added the `eslint-plugin-ft-flow` version in the `resolutions` configuration in the `package.json`. In this state, running `yarn eslint .` works as expected. To reproduce the issue, remove the `resolutions` field (and run `yarn install` again to update the dependencies) and run the command again. Reviewed By: cipolleschi Differential Revision: D121042705 Pulled By: cortinico fbshipit-source-id: fd330a514ad991de379ddadc2295190e75ccb663
@react-native/eslint-config
ESLint and Prettier configuration used by React Native apps.
Installation
yarn add --dev eslint prettier @react-native/eslint-config
Usage
For ESLint 9+ (Flat Config)
Add to your eslint.config.js:
const reactNativeConfig = require('@react-native/eslint-config/flat');
module.exports = [
...reactNativeConfig,
// Your custom config here
];
Or with ES modules:
import reactNativeConfig from '@react-native/eslint-config/flat';
export default [
...reactNativeConfig,
// Your custom config here
];
For ESLint 8 (Legacy Config)
Add to your eslint config (.eslintrc, or eslintConfig field in package.json):
{
"extends": "@react-native"
}