Skip to content

Commit eb76dba

Browse files
authored
feat: add react native eslint config (#272)
Adding a `@strv/eslint-config-react-native` based on the [eslint-config-expo](https://www.npmjs.com/package/eslint-config-expo).
2 parents 4991976 + 64379c0 commit eb76dba

File tree

6 files changed

+278
-23
lines changed

6 files changed

+278
-23
lines changed

package-lock.json

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

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"node": ">=24",
2424
"npm": ">=11"
2525
},
26+
"packageManager": "[email protected]",
2627
"type": "module",
2728
"homepage": "https://github.com/strvcom/code-quality-tools",
2829
"keywords": [],
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
BSD 3-Clause License
2+
3+
Copyright (c) 2019, STRV
4+
All rights reserved.
5+
6+
Redistribution and use in source and binary forms, with or without
7+
modification, are permitted provided that the following conditions are met:
8+
9+
* Redistributions of source code must retain the above copyright notice, this
10+
list of conditions and the following disclaimer.
11+
12+
* Redistributions in binary form must reproduce the above copyright notice,
13+
this list of conditions and the following disclaimer in the documentation
14+
and/or other materials provided with the distribution.
15+
16+
* Neither the name of the copyright holder nor the names of its
17+
contributors may be used to endorse or promote products derived from
18+
this software without specific prior written permission.
19+
20+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# @strv/eslint-config-react-native
2+
3+
> ESLint config for React-Native projects
4+
5+
## Installation
6+
7+
```sh
8+
npm install -D @strv/eslint-config-react-native
9+
```
10+
11+
## Usage
12+
13+
```js
14+
// eslint.config.mjs
15+
import reactNative from '@strv/eslint-config-react-native'
16+
17+
export default reactNative
18+
```
19+
20+
### Tips
21+
1. Use caching, see https://eslint.org/docs/latest/use/command-line-interface#caching
22+
23+
## License
24+
25+
See the [LICENSE](LICENSE) file for information.
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
import typeScriptConfig from '@strv/eslint-config-typescript'
2+
import expoConfig from 'eslint-config-expo/flat.js'
3+
import { defineConfig, globalIgnores } from 'eslint/config'
4+
5+
/** Globally ignored */
6+
const ignores = globalIgnores(['.expo/', 'expo-env.d.ts'])
7+
8+
/** @type {import("eslint").Linter.Config} */
9+
const common = {
10+
rules: {
11+
// Very expensive check, see https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/namespace.md
12+
'import/namespace': 'off',
13+
// Very expensive check, see https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/no-duplicates.md
14+
'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',
24+
},
25+
}
26+
27+
/** @type {import("eslint").Linter.Config} */
28+
const react = {
29+
files: ['**/*.jsx', '**/*.tsx'],
30+
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
32+
'react/jsx-sort-props': [
33+
'error',
34+
{
35+
multiline: 'first',
36+
reservedFirst: ['key'],
37+
callbacksLast: true,
38+
shorthandLast: true,
39+
},
40+
],
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
42+
'react/display-name': 'off',
43+
},
44+
}
45+
46+
/** @type {import("eslint").Linter.Config} */
47+
const typescript = defineConfig([typeScriptConfig, {
48+
files: ['**/*.ts', '**/*.tsx'],
49+
rules: {
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/
52+
'@typescript-eslint/no-unused-vars': 'off',
53+
// 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/
55+
'@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',
58+
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+
],
79+
},
80+
}])
81+
82+
export default defineConfig([
83+
expoConfig,
84+
ignores,
85+
common,
86+
typescript,
87+
react,
88+
])
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"name": "@strv/eslint-config-react-native",
3+
"description": "STRV's ESLint config for React Native projects",
4+
"version": "4.0.0",
5+
"author": "Petr Chalupa <[email protected]>",
6+
"keywords": ["eslint", "react-native", "config", "strv"],
7+
"repository": {
8+
"type": "git",
9+
"url": "git://github.com/strvcom/code-quality-tools.git"
10+
},
11+
"bugs": {
12+
"url": "https://github.com/strvcom/code-quality-tools/issues"
13+
},
14+
"homepage": "https://github.com/strvcom/code-quality-tools/tree/master/packages/eslint-config-react-native#readme",
15+
"license": "BSD-3-Clause",
16+
"main": "index.mjs",
17+
"type": "module",
18+
"dependencies": {
19+
"@strv/eslint-config-typescript": "^6.0.0",
20+
"eslint-config-expo": "^10.0.0"
21+
},
22+
"peerDependencies": {
23+
"eslint": "^9"
24+
},
25+
"publishConfig": {
26+
"access": "public"
27+
}
28+
}

0 commit comments

Comments
 (0)