Skip to content

Commit 45e7abc

Browse files
committed
chore: upgrade eslint and all plugins, add new config
1 parent 4d3f6dc commit 45e7abc

File tree

5 files changed

+1679
-1030
lines changed

5 files changed

+1679
-1030
lines changed

package/.eslintignore

Lines changed: 0 additions & 8 deletions
This file was deleted.

package/.eslintrc.json

Lines changed: 0 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -14,72 +14,6 @@
1414
},
1515
"plugins": ["babel", "markdown", "sort-destructure-keys"],
1616
"rules": {
17-
"array-callback-return": 2,
18-
"arrow-body-style": 2,
19-
"comma-dangle": 0,
20-
"babel/no-invalid-this": 2,
21-
"default-case": 2,
22-
"eqeqeq": [2, "smart"],
23-
"jest/expect-expect": 0,
24-
"jest/no-conditional-expect": 0,
25-
"jsx-quotes": ["error", "prefer-single"],
26-
"linebreak-style": [2, "unix"],
27-
"no-console": 0,
28-
"no-mixed-spaces-and-tabs": 1,
29-
"no-self-compare": 2,
30-
"no-underscore-dangle": [2, { "allowAfterThis": true }],
31-
"no-unused-vars": [1, { "ignoreRestSiblings": true }],
32-
"no-useless-concat": 2,
33-
"no-var": 2,
34-
"object-shorthand": 1,
35-
"prefer-const": 1,
36-
"react/jsx-sort-props": [
37-
"error",
38-
{
39-
"callbacksLast": false,
40-
"ignoreCase": true,
41-
"noSortAlphabetically": false,
42-
"reservedFirst": false,
43-
"shorthandFirst": false,
44-
"shorthandLast": false
45-
}
46-
],
47-
"react/prop-types": 0,
48-
"require-await": 2,
49-
"semi": [1, "always"],
50-
"sort-destructure-keys/sort-destructure-keys": [2, { "caseSensitive": false }],
51-
"sort-imports": [
52-
"error",
53-
{
54-
"allowSeparatedGroups": true,
55-
"ignoreCase": true,
56-
"ignoreDeclarationSort": true,
57-
"ignoreMemberSort": false,
58-
"memberSyntaxSortOrder": ["none", "all", "multiple", "single"]
59-
}
60-
],
61-
"sort-keys": ["error", "asc", { "caseSensitive": false, "minKeys": 2, "natural": false }],
62-
"valid-typeof": 2,
63-
"import/order": [
64-
"error",
65-
{
66-
"groups": ["builtin", "external", "internal", "sibling", "parent", "index", "object"],
67-
"pathGroups": [
68-
{
69-
"pattern": "react*",
70-
"group": "external",
71-
"position": "before"
72-
}
73-
],
74-
"pathGroupsExcludedImportTypes": ["react*"],
75-
"newlines-between": "always-and-inside-groups",
76-
"alphabetize": {
77-
"order": "asc",
78-
"caseInsensitive": true
79-
}
80-
}
81-
],
82-
"import/no-unresolved": ["error", { "ignore": ["types"] }]
8317
},
8418
"settings": {
8519
"import/resolver": {

package/eslint.config.mjs

Lines changed: 192 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,192 @@
1+
import jsEslint from '@eslint/js';
2+
import eslintReactNativeConfig from '@react-native-community/eslint-config';
3+
import eslintPluginReactNativeOfficial from '@react-native-community/eslint-plugin';
4+
import eslintPluginComments from 'eslint-plugin-eslint-comments';
5+
import eslintPluginImport from 'eslint-plugin-import';
6+
import eslintPluginJest from 'eslint-plugin-jest';
7+
import eslintPluginPrettier from 'eslint-plugin-prettier';
8+
import eslintPluginReact from 'eslint-plugin-react';
9+
import eslintPluginReactHooks from 'eslint-plugin-react-hooks';
10+
import eslintPluginReactNative from 'eslint-plugin-react-native';
11+
import eslintPluginSortDestructureKeys from 'eslint-plugin-sort-destructure-keys';
12+
13+
import tsEslint from 'typescript-eslint';
14+
15+
/**
16+
* @react-native-community/eslint-config is for some reason still using the old notation
17+
* for globals. We parse them manually here to make sure they're compatible with
18+
* the new config. All globals which were previously set to true are now readonly.
19+
*/
20+
const reactNativeGlobals = Object.keys(eslintReactNativeConfig.globals).reduce((acc, key) => {
21+
if (eslintReactNativeConfig.globals[key]) {
22+
acc[key] = 'readonly';
23+
}
24+
return acc;
25+
}, {});
26+
27+
/**
28+
* We filter out the jest/ rules as they're part of another config layer.
29+
*/
30+
const reactNativeRules = Object.keys(eslintReactNativeConfig.rules).reduce((acc, key) => {
31+
if (!key.startsWith('jest/')) {
32+
acc[key] = eslintReactNativeConfig.rules[key];
33+
}
34+
return acc;
35+
}, {});
36+
37+
export default tsEslint.config(
38+
jsEslint.configs.recommended,
39+
tsEslint.configs.recommended,
40+
eslintPluginReact.configs.flat.recommended,
41+
{
42+
ignores: [
43+
'node_modules/',
44+
'build/',
45+
'dist/',
46+
'.expo/',
47+
'vendor/',
48+
'*.md',
49+
'src/components/docs/',
50+
'lib/',
51+
],
52+
},
53+
{
54+
files: ['**/*.js', '**/*.jsx', '**/*.ts', '**/*.tsx'],
55+
languageOptions: {
56+
ecmaVersion: 2020,
57+
globals: {
58+
...reactNativeGlobals,
59+
console: 'readonly',
60+
},
61+
parser: tsEslint.parser,
62+
parserOptions: {
63+
ecmaFeatures: {
64+
modules: true,
65+
jsx: true,
66+
},
67+
},
68+
sourceType: 'module',
69+
},
70+
plugins: {
71+
'@react-native-community': eslintPluginReactNativeOfficial,
72+
'eslint-comments': eslintPluginComments,
73+
import: eslintPluginImport,
74+
prettier: eslintPluginPrettier,
75+
react: eslintPluginReact,
76+
'react-hooks': eslintPluginReactHooks,
77+
'react-native': eslintPluginReactNative,
78+
'sort-destructure-keys': eslintPluginSortDestructureKeys,
79+
},
80+
settings: {
81+
'import/resolver': {
82+
// 'babel-module': {},
83+
node: {
84+
extensions: ['.js', '.jsx', '.ts', '.tsx'],
85+
paths: ['src'],
86+
},
87+
},
88+
'import/ignore': ['react-native'],
89+
react: {
90+
pragma: 'React',
91+
version: 'detect',
92+
},
93+
},
94+
rules: {
95+
...reactNativeRules,
96+
'array-callback-return': 2,
97+
'arrow-body-style': 2,
98+
'comma-dangle': 0,
99+
'default-case': 2,
100+
eqeqeq: [2, 'smart'],
101+
'import/no-unresolved': ['error', { ignore: ['types'] }],
102+
'import/order': [
103+
'error',
104+
{
105+
alphabetize: {
106+
caseInsensitive: true,
107+
order: 'asc',
108+
},
109+
groups: ['builtin', 'external', 'internal', 'sibling', 'parent', 'index', 'object'],
110+
'newlines-between': 'always-and-inside-groups',
111+
pathGroups: [
112+
{
113+
group: 'external',
114+
pattern: 'react*',
115+
position: 'before',
116+
},
117+
],
118+
pathGroupsExcludedImportTypes: ['react*'],
119+
},
120+
],
121+
'jsx-quotes': ['error', 'prefer-single'],
122+
'linebreak-style': [2, 'unix'],
123+
'no-console': 0,
124+
'no-mixed-spaces-and-tabs': 1,
125+
'no-self-compare': 2,
126+
'no-underscore-dangle': [2, { allowAfterThis: true }],
127+
'no-unused-vars': 'off',
128+
'no-useless-concat': 2,
129+
'no-var': 2,
130+
'object-shorthand': 1,
131+
'prefer-const': 1,
132+
'react/jsx-sort-props': [
133+
'error',
134+
{
135+
callbacksLast: false,
136+
ignoreCase: true,
137+
noSortAlphabetically: false,
138+
reservedFirst: false,
139+
shorthandFirst: false,
140+
shorthandLast: false,
141+
},
142+
],
143+
'react/prop-types': 0,
144+
'require-await': 2,
145+
semi: [1, 'always'],
146+
'sort-destructure-keys/sort-destructure-keys': [2, { caseSensitive: false }],
147+
'sort-imports': [
148+
'error',
149+
{
150+
allowSeparatedGroups: true,
151+
ignoreCase: true,
152+
ignoreDeclarationSort: true,
153+
ignoreMemberSort: false,
154+
memberSyntaxSortOrder: ['none', 'all', 'multiple', 'single'],
155+
},
156+
],
157+
'sort-keys': ['error', 'asc', { caseSensitive: false, minKeys: 2, natural: false }],
158+
'valid-typeof': 2,
159+
'@typescript-eslint/explicit-module-boundary-types': 0,
160+
'@typescript-eslint/no-empty-interface': 0,
161+
'@typescript-eslint/ban-ts-comment': 0,
162+
'@typescript-eslint/no-unused-vars': [
163+
'warn',
164+
{ ignoreRestSiblings: false, caughtErrors: 'none' },
165+
],
166+
'@typescript-eslint/no-var-requires': 0,
167+
'react-hooks/exhaustive-deps': 1,
168+
'react-native/no-inline-styles': 0,
169+
'babel/no-invalid-this': 0,
170+
'@typescript-eslint/no-invalid-this': 'error',
171+
'no-shadow': 0,
172+
},
173+
},
174+
{
175+
name: 'jest',
176+
files: ['src/**/__tests__/**'],
177+
plugins: { jest: eslintPluginJest },
178+
languageOptions: {
179+
globals: eslintPluginJest.environments.globals.globals,
180+
},
181+
rules: {
182+
'jest/expect-expect': 'off',
183+
'jest/no-conditional-expect': 'off',
184+
'jest/prefer-inline-snapshots': 'off',
185+
'jest/lowercase-name': 'off',
186+
'jest/prefer-expect-assertions': 'off',
187+
'jest/no-hooks': 'off',
188+
'jest/no-if': 'off',
189+
'jest/prefer-spy-on': 'warn',
190+
},
191+
},
192+
);

package/package.json

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@
105105
"@babel/preset-typescript": "7.13.0",
106106
"@babel/runtime": "^7.20.0",
107107
"@op-engineering/op-sqlite": "^9.3.0",
108-
"@react-native-community/eslint-config": "2.0.0",
109-
"@react-native-community/eslint-plugin": "1.1.0",
108+
"@react-native-community/eslint-config": "3.2.0",
109+
"@react-native-community/eslint-plugin": "1.3.0",
110110
"@react-native-community/netinfo": "^11.3.2",
111111
"@react-native/babel-preset": "0.73.21",
112112
"@testing-library/jest-native": "^5.4.3",
@@ -121,28 +121,26 @@
121121
"@types/react-test-renderer": "18.0.7",
122122
"@types/use-sync-external-store": "^0.0.6",
123123
"@types/uuid": "^8.3.4",
124-
"@typescript-eslint/eslint-plugin": "^6.21.0",
125-
"@typescript-eslint/parser": "^6.21.0",
126124
"babel-eslint": "10.1.0",
127125
"babel-jest": "29.6.3",
128126
"babel-loader": "8.2.2",
129127
"babel-plugin-module-resolver": "4.1.0",
130128
"better-sqlite3": "9.0.0",
131-
"eslint": "7.32.0",
129+
"eslint": "^9.20.1",
132130
"eslint-config-prettier": "8.3.0",
133-
"eslint-import-resolver-babel-module": "^5.3.1",
134-
"eslint-plugin-babel": "5.3.1",
135-
"eslint-plugin-import": "^2.25.3",
136-
"eslint-plugin-jest": "24.3.6",
137-
"eslint-plugin-markdown": "2.1.0",
138-
"eslint-plugin-prettier": "3.4.0",
139-
"eslint-plugin-react": "7.34.1",
140-
"eslint-plugin-sort-destructure-keys": "1.5.0",
141-
"eslint-plugin-typescript-sort-keys": "3.2.0",
131+
"eslint-plugin-import": "^2.31.0",
132+
"eslint-plugin-jest": "^28.11.0",
133+
"eslint-plugin-markdown": "5.1.0",
134+
"eslint-plugin-prettier": "5.2.3",
135+
"eslint-plugin-react": "^7.37.4",
136+
"eslint-plugin-sort-destructure-keys": "2.0.0",
137+
"eslint-plugin-eslint-comments": "^3.2.0",
138+
"eslint-plugin-react-hooks": "^5.1.0",
139+
"eslint-plugin-react-native": "^5.0.0",
142140
"i18next-parser": "^9.0.0",
143-
"jest": "29.6.3",
141+
"jest": "^29.7.0",
144142
"moment-timezone": "^0.5.45",
145-
"prettier": "2.8.8",
143+
"prettier": "^3.5.1",
146144
"react": "18.2.0",
147145
"react-native": "0.73.6",
148146
"react-native-builder-bob": "0.23.1",
@@ -151,6 +149,7 @@
151149
"react-native-svg": "15.1.0",
152150
"react-test-renderer": "18.2.0",
153151
"typescript": "5.0.4",
152+
"typescript-eslint": "^8.24.1",
154153
"uuid": "^8.3.2"
155154
},
156155
"resolutions": {

0 commit comments

Comments
 (0)