Skip to content

Commit 2594035

Browse files
Add ESLint support for React and React Native (#4)
* feat(package): add eslint rules for react * feat(package): add eslint rules for react-native
1 parent 4092444 commit 2594035

7 files changed

Lines changed: 708 additions & 10 deletions

File tree

packages/eslint/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ This project is an ESLint config that gathers all the rules, plugins and parsers
44

55
## How to use?
66

7-
In your app, run `yarn add --dev @bam.tech/eslint-config @typescript-eslint/eslint-plugin eslint`.
7+
In your app, run `yarn add --dev @bam.tech/eslint-config eslint-plugin-react-native eslint-plugin-react @typescript-eslint/eslint-plugin eslint`.
88

99
In your `.eslintrc` config file, extend the exported configuration:
1010

packages/eslint/index.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,25 @@
33
module.exports = {
44
env: {
55
node: true,
6+
"react-native/react-native": true,
67
},
7-
extends: ["eslint:recommended", "plugin:@typescript-eslint/recommended"],
8+
extends: [
9+
"eslint:recommended",
10+
"plugin:@typescript-eslint/recommended",
11+
"plugin:react/recommended",
12+
"plugin:react-native/all",
13+
],
814
parser: "@typescript-eslint/parser",
915
parserOptions: {
1016
ecmaVersion: "latest",
17+
ecmaFeatures: {
18+
jsx: true,
19+
},
20+
},
21+
plugins: ["@typescript-eslint", "react-native"],
22+
settings: {
23+
react: {
24+
version: "detect",
25+
},
1126
},
12-
plugins: ["@typescript-eslint"],
1327
};

packages/eslint/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
"license": "MIT",
66
"peerDependencies": {
77
"@typescript-eslint/eslint-plugin": ">= 5",
8-
"eslint": ">= 8"
8+
"eslint": ">= 8",
9+
"eslint-plugin-react": "^7.31.11",
10+
"eslint-plugin-react-native": "^4.0.0"
911
},
1012
"devDependencies": {
1113
"@typescript-eslint/parser": "^5.48.0"
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// This should trigger two errors breaking eslint-plugin-react:
2+
// react/react-in-jsx-scope
3+
// react/react-in-jsx-scope
4+
export const MyComponent = () => <ThisIsAViewThatDoesntExist />;
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// This should trigger two errors breaking eslint-plugin-react-native:
2+
// react-native/no-color-literals
3+
// react-native/sort-styles
4+
const styles = StyleSheet.create({
5+
button: {
6+
width: 100,
7+
color: "green",
8+
},
9+
});

packages/example-app/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
"devDependencies": {
1111
"@bam.tech/eslint-config": "*",
1212
"@typescript-eslint/eslint-plugin": "^5.48.0",
13-
"eslint": "^8.31.0"
13+
"eslint": "^8.31.0",
14+
"eslint-plugin-react": "^7.31.11",
15+
"eslint-plugin-react-native": "^4.0.0"
1416
},
1517
"private": "true"
1618
}

0 commit comments

Comments
 (0)