Skip to content

Commit d056559

Browse files
feat: update eslint to v9 (#794)
### Summary This PR updates ESLint to version 9 for all created projects and for this very same repository as well. Upgrading to ESLint 9 implies moving the inline ESLint config (located at `package.json`) to a separate file: `.eslint.config.mjs` ([docs](https://eslint.org/docs/latest/use/migrate-to-9.0.0#flat-config)). We are coming from discussion #793 ### Test plan - Run `yarn lint` in this project to make sure linting is unaffected. - Create a new project with `create-react-native-library` and run `yarn lint` on the newly created project to make sure linting does not report any error.
1 parent 7258052 commit d056559

File tree

17 files changed

+1262
-1697
lines changed

17 files changed

+1262
-1697
lines changed

docs/next.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// eslint-disable-next-line @typescript-eslint/no-require-imports
12
const withNextra = require('nextra')({
23
theme: 'nextra-theme-docs',
34
themeConfig: './theme.config.jsx',

eslint.config.mjs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// eslint-disable-next-line import-x/extensions,import-x/no-unresolved
2+
import { defineConfig } from 'eslint/config';
3+
import satya164 from 'eslint-config-satya164';
4+
5+
export default defineConfig([
6+
...satya164,
7+
{
8+
ignores: [
9+
'node_modules/',
10+
'**/coverage/',
11+
'**/lib/',
12+
'**/templates/',
13+
'**/__fixtures__/',
14+
],
15+
},
16+
]);

package.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,17 @@
2323
},
2424
"devDependencies": {
2525
"@commitlint/config-conventional": "^17.0.2",
26+
"@eslint/compat": "^1.2.7",
27+
"@eslint/eslintrc": "^3.3.0",
28+
"@eslint/js": "^9.22.0",
2629
"@evilmartians/lefthook": "^1.5.0",
2730
"@lerna-lite/cli": "^1.13.0",
2831
"@lerna-lite/run": "^1.13.0",
2932
"commitlint": "^17.0.2",
3033
"concurrently": "^7.2.2",
31-
"eslint": "^8.52.0",
32-
"eslint-config-satya164": "^3.2.0",
34+
"eslint": "^9.23.0",
35+
"eslint-config-satya164": "^4.0.1",
36+
"globals": "^16.0.0",
3337
"prettier": "^3.0.3",
3438
"typescript": "^5.2.2"
3539
},

packages/create-react-native-library/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import { resolveNpmPackageVersion } from './utils/resolveNpmPackageVersion';
2323
const FALLBACK_BOB_VERSION = '0.38.3';
2424
const FALLBACK_NITRO_MODULES_VERSION = '0.22.1';
2525

26+
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
2627
yargs
2728
.command(
2829
'$0 [name]',

packages/create-react-native-library/templates/common/$package.json

Lines changed: 7 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -78,19 +78,22 @@
7878
},
7979
"devDependencies": {
8080
"@commitlint/config-conventional": "^19.6.0",
81+
"@eslint/compat": "^1.2.7",
82+
"@eslint/eslintrc": "^3.3.0",
83+
"@eslint/js": "^9.22.0",
8184
"@evilmartians/lefthook": "^1.5.0",
8285
<% if (example === 'vanilla' && (project.moduleConfig === 'turbo-modules' || project.viewConfig === 'fabric-view')) { -%>
8386
"@react-native-community/cli": "15.0.0-alpha.2",
8487
<% } -%>
85-
"@react-native/eslint-config": "^0.73.1",
88+
"@react-native/eslint-config": "^0.78.0",
8689
"@release-it/conventional-changelog": "^9.0.2",
8790
"@types/jest": "^29.5.5",
8891
"@types/react": "^19.0.12",
8992
"commitlint": "^19.6.1",
9093
"del-cli": "^5.1.0",
91-
"eslint": "^8.51.0",
92-
"eslint-config-prettier": "^9.0.0",
93-
"eslint-plugin-prettier": "^5.0.1",
94+
"eslint": "^9.22.0",
95+
"eslint-config-prettier": "^10.1.1",
96+
"eslint-plugin-prettier": "^5.2.3",
9497
"jest": "^29.7.0",
9598
<% if (project.moduleConfig === 'nitro-modules') { -%>
9699
"nitro-codegen": "^<%- versions.nitroCodegen %>",
@@ -154,30 +157,6 @@
154157
}
155158
}
156159
},
157-
"eslintConfig": {
158-
"root": true,
159-
"extends": [
160-
"@react-native",
161-
"prettier"
162-
],
163-
"rules": {
164-
"react/react-in-jsx-scope": "off",
165-
"prettier/prettier": [
166-
"error",
167-
{
168-
"quoteProps": "consistent",
169-
"singleQuote": true,
170-
"tabWidth": 2,
171-
"trailingComma": "es5",
172-
"useTabs": false
173-
}
174-
]
175-
}
176-
},
177-
"eslintIgnore": [
178-
"node_modules/",
179-
"lib/"
180-
],
181160
"prettier": {
182161
"quoteProps": "consistent",
183162
"singleQuote": true,
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { fixupConfigRules } from '@eslint/compat';
2+
import { FlatCompat } from '@eslint/eslintrc';
3+
import js from '@eslint/js';
4+
import prettier from 'eslint-plugin-prettier';
5+
import { defineConfig } from 'eslint/config';
6+
import path from 'node:path';
7+
import { fileURLToPath } from 'node:url';
8+
9+
const __filename = fileURLToPath(import.meta.url);
10+
const __dirname = path.dirname(__filename);
11+
const compat = new FlatCompat({
12+
baseDirectory: __dirname,
13+
recommendedConfig: js.configs.recommended,
14+
allConfig: js.configs.all,
15+
});
16+
17+
export default defineConfig([
18+
{
19+
extends: fixupConfigRules(compat.extends('@react-native', 'prettier')),
20+
plugins: { prettier },
21+
rules: {
22+
'react/react-in-jsx-scope': 'off',
23+
'prettier/prettier': [
24+
'error',
25+
{
26+
quoteProps: 'consistent',
27+
singleQuote: true,
28+
tabWidth: 2,
29+
trailingComma: 'es5',
30+
useTabs: false,
31+
},
32+
],
33+
},
34+
},
35+
{
36+
ignores: [
37+
'node_modules/',
38+
'lib/'
39+
],
40+
},
41+
]);

packages/react-native-builder-bob/babel-config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* eslint-disable import/no-commonjs */
1+
/* eslint-disable @typescript-eslint/no-require-imports, import-x/no-commonjs, no-undef */
22

33
const path = require('path');
44
const { cosmiconfigSync } = require('cosmiconfig');

packages/react-native-builder-bob/babel-preset.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* eslint-disable import/no-commonjs */
1+
/* eslint-disable @typescript-eslint/no-require-imports, import-x/no-commonjs, no-undef */
22

33
const browserslist = require('browserslist');
44

packages/react-native-builder-bob/metro-config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* eslint-disable import/no-commonjs */
1+
/* eslint-disable @typescript-eslint/no-require-imports, import-x/no-commonjs, no-undef */
22

33
const path = require('path');
44
const escape = require('escape-string-regexp');

packages/react-native-builder-bob/src/__tests__/babel.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { expect, it } from '@jest/globals';
1+
import { expect, test } from '@jest/globals';
22
import { transformFileAsync } from '@babel/core';
33
import fs from 'node:fs';
44
import path from 'node:path';
55

6-
it.each(['imports', 'exports'])(`adds extension to %s`, async (name) => {
6+
test.each(['imports', 'exports'])(`adds extension to %s`, async (name) => {
77
const filepath = path.resolve(
88
__dirname,
99
`../__fixtures__/project/code/$${name}-input.ts`

0 commit comments

Comments
 (0)