Skip to content

Commit 64379c0

Browse files
committed
feat(eslint-config-react-native): define rules
fix: add ignore chore: add ts plugin and parser fix: update files chore: bump version docs: update docs chore: deps align feat: extend by typescript config fix: use singlequote fix: format docs: add links to rules
1 parent 3636786 commit 64379c0

File tree

4 files changed

+59
-20
lines changed

4 files changed

+59
-20
lines changed

package-lock.json

Lines changed: 8 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/eslint-config-react-native/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ import reactNative from '@strv/eslint-config-react-native'
1717
export default reactNative
1818
```
1919

20+
### Tips
21+
1. Use caching, see https://eslint.org/docs/latest/use/command-line-interface#caching
22+
2023
## License
2124

2225
See the [LICENSE](LICENSE) file for information.

packages/eslint-config-react-native/index.mjs

Lines changed: 45 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,83 @@
1+
import typeScriptConfig from '@strv/eslint-config-typescript'
12
import expoConfig from 'eslint-config-expo/flat.js'
23
import { defineConfig, globalIgnores } from 'eslint/config'
34

45
/** Globally ignored */
5-
const ignores = globalIgnores(['.expo/'])
6+
const ignores = globalIgnores(['.expo/', 'expo-env.d.ts'])
67

78
/** @type {import("eslint").Linter.Config} */
89
const common = {
910
rules: {
10-
// Very expensive check
11+
// Very expensive check, see https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/namespace.md
1112
'import/namespace': 'off',
12-
// Very expensive check
13+
// Very expensive check, see https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/no-duplicates.md
1314
'import/no-duplicates': 'off',
15+
// Handled by TypeScript, see https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/no-unresolved.md
16+
'import/no-unresolved': 'off',
17+
// https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/no-named-as-default.md
18+
'import/no-named-as-default': 'off',
19+
// https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/no-named-as-default-member.md
20+
'import/no-named-as-default-member': 'off',
21+
// Handled by TypeScript. Enable noUnusedLocals in your tsconfig.json, see https://www.typescriptlang.org/tsconfig/#noUnusedLocals
22+
// https://eslint.org/docs/latest/rules/no-unused-vars
23+
'no-unused-vars': 'off',
1424
},
1525
}
1626

1727
/** @type {import("eslint").Linter.Config} */
1828
const react = {
29+
files: ['**/*.jsx', '**/*.tsx'],
1930
rules: {
31+
// Enforce alphabetical sorting of props for better readability, see https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-sort-props.md
2032
'react/jsx-sort-props': [
21-
'warn',
33+
'error',
2234
{
2335
multiline: 'first',
2436
reservedFirst: ['key'],
2537
callbacksLast: true,
2638
shorthandLast: true,
2739
},
2840
],
41+
// DisplayName is not required for React Native components, see https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/display-name.md
2942
'react/display-name': 'off',
3043
},
3144
}
3245

3346
/** @type {import("eslint").Linter.Config} */
34-
const typescript = {
47+
const typescript = defineConfig([typeScriptConfig, {
48+
files: ['**/*.ts', '**/*.tsx'],
3549
rules: {
36-
// Handled by TypeScript, see https://www.typescriptlang.org/tsconfig/#noUnusedLocals
50+
// Handled by TypeScript. Enable noUnusedLocals in your tsconfig.json, see https://www.typescriptlang.org/tsconfig/#noUnusedLocals
51+
// https://typescript-eslint.io/rules/no-unused-vars/
3752
'@typescript-eslint/no-unused-vars': 'off',
3853
// Its common in React Native to import types using require syntax, see https://reactnative.dev/docs/images#static-image-resources
54+
// https://typescript-eslint.io/rules/no-require-imports/
3955
'@typescript-eslint/no-require-imports': 'off',
56+
// Very expensive check, see https://typescript-eslint.io/rules/promise-function-async/
57+
'@typescript-eslint/promise-function-async': 'off',
4058

41-
// '@typescript-eslint/consistent-type-imports': [
42-
// 'warn',
43-
// { prefer: 'type-imports', fixStyle: 'inline-type-imports' },
44-
// ],
59+
// Allows variable shadowing in TypeScript contexts, see https://typescript-eslint.io/rules/no-shadow/
60+
'@typescript-eslint/no-shadow': 'off',
61+
// Allows both interface and type definitions, see https://typescript-eslint.io/rules/consistent-type-definitions/
62+
'@typescript-eslint/consistent-type-definitions': 'off',
63+
// Allows Promises in places where they might not be handled properly, see https://typescript-eslint.io/rules/no-misused-promises/
64+
'@typescript-eslint/no-misused-promises': 'off',
65+
// Allows assignments of any typed values, see https://typescript-eslint.io/rules/no-unsafe-assignment/
66+
'@typescript-eslint/no-unsafe-assignment': 'off',
67+
// Allows returning any typed values from functions, see https://typescript-eslint.io/rules/no-unsafe-return/
68+
'@typescript-eslint/no-unsafe-return': 'off',
69+
// Allows unbound method references that may lose 'this' context, see https://typescript-eslint.io/rules/unbound-method/
70+
'@typescript-eslint/unbound-method': 'off',
71+
// Allows member access on any typed values, see https://typescript-eslint.io/rules/no-unsafe-member-access/
72+
'@typescript-eslint/no-unsafe-member-access': 'off',
73+
74+
// Enforce consistent type imports with inline style, see https://typescript-eslint.io/rules/consistent-type-imports/
75+
'@typescript-eslint/consistent-type-imports': [
76+
'error',
77+
{ prefer: 'type-imports', fixStyle: 'inline-type-imports' },
78+
],
4579
},
46-
}
80+
}])
4781

4882
export default defineConfig([
4983
expoConfig,

packages/eslint-config-react-native/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@strv/eslint-config-react-native",
33
"description": "STRV's ESLint config for React Native projects",
4-
"version": "1.0.0",
4+
"version": "4.0.0",
55
"author": "Petr Chalupa <[email protected]>",
66
"keywords": ["eslint", "react-native", "config", "strv"],
77
"repository": {
@@ -16,7 +16,8 @@
1616
"main": "index.mjs",
1717
"type": "module",
1818
"dependencies": {
19-
"eslint-config-expo": "~10.0.0"
19+
"@strv/eslint-config-typescript": "^6.0.0",
20+
"eslint-config-expo": "^10.0.0"
2021
},
2122
"peerDependencies": {
2223
"eslint": "^9"

0 commit comments

Comments
 (0)