Skip to content
Closed
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions packages/eslint-config-react-native/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,32 @@ yarn add --dev eslint prettier @react-native/eslint-config

## Usage

### For ESLint 9+ (Flat Config)

Add to your `eslint.config.js`:

```javascript
const reactNativeConfig = require('@react-native/eslint-config/flat');

module.exports = [
...reactNativeConfig,
// Your custom config here
];
```

Or with ES modules:

```javascript
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`):

```json
Expand Down
114 changes: 114 additions & 0 deletions packages/eslint-config-react-native/flat.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
* @noflow
*/

const sharedConfig = require('./shared.js');
const babelParser = require('@babel/eslint-parser');
const reactNativePlugin = require('@react-native/eslint-plugin');
const typescriptPlugin = require('@typescript-eslint/eslint-plugin');
const typescriptParser = require('@typescript-eslint/parser');
const prettierConfig = require('eslint-config-prettier');
const eslintCommentsPlugin = require('eslint-plugin-eslint-comments');
const ftFlowPlugin = require('eslint-plugin-ft-flow');
const jestPlugin = require('eslint-plugin-jest');
const reactPlugin = require('eslint-plugin-react');
const reactHooksPlugin = require('eslint-plugin-react-hooks');
const reactNativeExternalPlugin = require('eslint-plugin-react-native');

// Convert globals from legacy format (true/false) to flat config format ('readonly'/'writable')
const convertGlobals = globals => {
const converted = {};
for (const [key, value] of Object.entries(globals)) {
converted[key] = value ? 'writable' : 'readonly';
}
return converted;
};

// Flat Config for ESLint 9+
module.exports = [
// Apply prettier config first (to disable conflicting rules)
prettierConfig,

// Base configuration for all files
{
languageOptions: {
ecmaVersion: 'latest',
sourceType: 'module',
parserOptions: sharedConfig.parserOptions,
globals: convertGlobals(sharedConfig.globals),
},
plugins: {
'eslint-comments': eslintCommentsPlugin,
react: reactPlugin,
'react-hooks': reactHooksPlugin,
'react-native': reactNativeExternalPlugin,
'@react-native': reactNativePlugin,
jest: jestPlugin,
},
settings: sharedConfig.settings,
rules: sharedConfig.rules,
},

// JavaScript files with Babel parser and Flow
{
...sharedConfig.overrides.flow,
files: ['**/*.js'],
languageOptions: {
parser: babelParser,
},
plugins: {
'ft-flow': ftFlowPlugin,
},
},

// JSX files with Babel parser
{
files: ['**/*.jsx'],
languageOptions: {
parser: babelParser,
},
},

// All JS/TS files - React Native specific rules
{
...sharedConfig.overrides.reactNative,
files: ['**/*.js', '**/*.jsx', '**/*.ts', '**/*.tsx'],
},

// TypeScript files
{
...sharedConfig.overrides.typescript,
files: ['**/*.ts', '**/*.tsx'],
languageOptions: {
parser: typescriptParser,
parserOptions: {
ecmaFeatures: {
jsx: true,
},
},
},
plugins: {
'@typescript-eslint': typescriptPlugin,
},
},

// Test files
{
...sharedConfig.overrides.jest,
files: [
'**/*.{spec,test}.{js,ts,tsx}',
'**/__{mocks,tests}__/**/*.{js,ts,tsx}',
],
languageOptions: {
globals: {
...jestPlugin.environments.globals.globals,
},
},
},
];
Loading