Skip to content

Commit 9dea93c

Browse files
authored
Feat/basic setup (#14)
* chore: use eslint package from the repo and not from npm in the example app * chore: add defineConfig to type-check the index.js file * feat: ignore default config files for analysis * fix: parser is a dependency * refacto: remove unnecessary plugins Both plugins were already included in the shareable configs imported in the "extends" section * feat: disable rule that require to import React with jsx * feat: add rules for react-hooks * feat: add prettier config * chore: reproduce same config as in enablers * feat: add custom rules config from enablers * feat: add rules for typescript * fix: config eslint extension for monorepo
1 parent 2bd61c4 commit 9dea93c

13 files changed

Lines changed: 3137 additions & 137 deletions

.vscode/settings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
22
"editor.defaultFormatter": "esbenp.prettier-vscode",
3-
"editor.formatOnSave": true
3+
"editor.formatOnSave": true,
4+
"eslint.workingDirectories": ["packages/example-app", "packages/eslint"]
45
}

packages/eslint/README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ 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 eslint-plugin-react-native eslint-plugin-react @typescript-eslint/eslint-plugin @typescript-eslint/parser eslint typescript`.
7+
In your app, run
8+
9+
```bash
10+
yarn add --dev @bam.tech/eslint-config @typescript-eslint/eslint-plugin eslint eslint-plugin-prettier eslint-plugin-react eslint-plugin-react-hooks eslint-plugin-react-native prettier
11+
```
812

913
In your `.eslintrc` config file, extend the exported configuration:
1014

packages/eslint/index.js

Lines changed: 53 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,73 @@
1+
// @ts-check
12
"use strict";
23

3-
module.exports = {
4-
env: {
5-
node: true,
6-
"react-native/react-native": true,
7-
},
4+
const { defineConfig } = require("eslint-define-config");
5+
6+
module.exports = defineConfig({
7+
ignorePatterns: [
8+
".cache", // tsc/eslint/metro cache
9+
".expo-shared",
10+
".expo",
11+
".yarn", // yarn 3
12+
"android", // react-native
13+
"ios", // react-native
14+
"coverage", // jest
15+
"dist", // expo updates
16+
"node_modules",
17+
],
818
extends: [
919
"eslint:recommended",
1020
"plugin:@typescript-eslint/recommended",
1121
"plugin:react/recommended",
22+
"plugin:react/jsx-runtime", // Disables the rules that require importing react when using JSX
1223
"plugin:react-native/all",
24+
"plugin:react-hooks/recommended",
25+
"plugin:prettier/recommended", // Enables eslint-plugin-prettier and displays prettier errors as ESLint errors. Make sure this is always the last configuration in the extends array.
1326
],
27+
rules: {
28+
"@typescript-eslint/ban-ts-comment": "warn",
29+
"@typescript-eslint/explicit-function-return-type": "off",
30+
"@typescript-eslint/indent": "off",
31+
"@typescript-eslint/no-explicit-any": "error",
32+
"@typescript-eslint/no-unused-vars": "error",
33+
"no-console": ["error", { allow: ["warn", "error"] }],
34+
"no-return-await": "error",
35+
"prettier/prettier": ["error", { printWidth: 80 }],
36+
"react-hooks/exhaustive-deps": "error",
37+
"react-native/no-color-literals": "off",
38+
"react-native/no-raw-text": ["error", { skip: ["Trans"] }],
39+
"react-native/sort-styles": "off",
40+
"react/no-unstable-nested-components": "error",
41+
"react/prop-types": "off",
42+
},
43+
env: {
44+
node: true,
45+
"react-native/react-native": true,
46+
},
1447
parser: "@typescript-eslint/parser",
1548
parserOptions: {
1649
ecmaVersion: "latest",
50+
sourceType: "module",
1751
ecmaFeatures: {
1852
jsx: true,
1953
},
2054
},
21-
plugins: ["@typescript-eslint", "react-native"],
2255
settings: {
2356
react: {
2457
version: "detect",
2558
},
2659
},
27-
};
60+
overrides: [
61+
{
62+
files: ["**/*.ts?(x)"],
63+
parserOptions: {
64+
project: "tsconfig.json",
65+
},
66+
rules: {
67+
// Note: disable the base rule as it can report incorrect errors
68+
"no-return-await": "off",
69+
"@typescript-eslint/return-await": "error",
70+
},
71+
},
72+
],
73+
});

packages/eslint/package.json

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,16 @@
99
"peerDependencies": {
1010
"@typescript-eslint/eslint-plugin": ">= 5",
1111
"eslint": ">= 8",
12-
"eslint-plugin-react": "^7.31.11",
13-
"eslint-plugin-react-native": "^4.0.0"
12+
"eslint-plugin-prettier": ">=4.2.1",
13+
"eslint-plugin-react": ">=7.31.11",
14+
"eslint-plugin-react-hooks": ">=4.6.0",
15+
"eslint-plugin-react-native": ">=4.0.0",
16+
"prettier": ">=2.8.8",
17+
"react": ">=17"
1418
},
15-
"devDependencies": {
16-
"@typescript-eslint/parser": "^5.48.0"
19+
"dependencies": {
20+
"@typescript-eslint/parser": "^5.48.0",
21+
"eslint-config-prettier": "^8.8.0",
22+
"eslint-define-config": "^1.21.0"
1723
}
1824
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// This should trigger an error breaking eslint-plugin-prettier:
2+
// prettier/prettier
3+
4+
export function aVeryLongFunctionNameWhichShouldBeForbiddenBecauseItIsReallyTooLongToRead() { return 1; }
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// This should trigger two errors breaking eslint-plugin-react:
2-
// react/react-in-jsx-scope
3-
// react/react-in-jsx-scope
1+
// This should trigger one error breaking eslint-plugin-react:
2+
// react/jsx-no-undef
3+
44
export const MyComponent = () => <ThisIsAViewThatDoesntExist />;
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// This should trigger an error breaking eslint-plugin-react-hooks:
2+
// react-hooks/exhaustive-deps
3+
4+
import { useState, useEffect } from "react";
5+
6+
const MyComponent = () => {
7+
const [count, setCount] = useState(0);
8+
9+
useEffect(() => {
10+
setCount(count + 1);
11+
}, []);
12+
13+
return <></>;
14+
};
15+
16+
export default MyComponent;

packages/example-app/break-react-native-eslint-rules.ts

Lines changed: 0 additions & 9 deletions
This file was deleted.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// This should trigger one error breaking eslint-plugin-react-native:
2+
// react-native/no-raw-text
3+
4+
import { View } from "react-native";
5+
6+
export const MyText = () => {
7+
return <View>Test</View>;
8+
};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// This should trigger two errors breaking typescript-eslint rules:
22
// @typescript-eslint/no-unused-vars
33
// @typescript-eslint/ban-types
4+
45
const str: String = "foo";

0 commit comments

Comments
 (0)