Skip to content
This repository was archived by the owner on Dec 29, 2022. It is now read-only.

Commit 7103c42

Browse files
committed
setup eslint
1 parent 551b3b8 commit 7103c42

File tree

4 files changed

+633
-16
lines changed

4 files changed

+633
-16
lines changed

.eslintrc.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
module.exports = {
2+
parser: "@typescript-eslint/parser",
3+
plugins: ["tsc", "jest"],
4+
root: true,
5+
extends: "@react-native-community",
6+
rules: {
7+
quotes: ["warn", "double", { allowTemplateLiterals: true }],
8+
"tsc/config": [
9+
1,
10+
{
11+
configFile: "tsconfig.json"
12+
}
13+
],
14+
"comma-dangle": 0,
15+
"react/prop-types": 1,
16+
"prettier/prettier": 1,
17+
"@typescript-eslint/no-unused-vars": 1
18+
},
19+
env: {
20+
"jest/globals": true
21+
}
22+
};

package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,15 @@
1818
"masonry-scroll"
1919
],
2020
"devDependencies": {
21+
"@react-native-community/eslint-config": "^0.0.7",
2122
"@testing-library/react-native": "^5.0.3",
2223
"@types/jest": "^25.1.1",
2324
"@types/react": "^16.9.19",
2425
"@types/react-native": "^0.61.7",
2526
"@types/react-test-renderer": "^16.9.2",
27+
"eslint": "^6.8.0",
28+
"eslint-plugin-prettier": "^3.1.2",
29+
"eslint-plugin-tsc": "^1.2.0",
2630
"husky": "^4.2.1",
2731
"jest": "^25.1.0",
2832
"metro-react-native-babel-preset": "^0.58.0",

precommit-lint.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
3+
echo "ESLint running for staged files..."
4+
5+
# from https://eslint.org/docs/user-guide/integrations#source-control - Git pre-commit hook that only lints staged changes
6+
for file in $(git diff --cached --name-only | grep -E '\.(js|jsx|ts|tsx)$')
7+
do
8+
git show ":$file" | node_modules/.bin/eslint --stdin --stdin-filename "$file" --max-warnings 0 # we only want to lint the staged changes, not any un-staged changes
9+
if [ $? -ne 0 ]; then
10+
echo "ESLint failed on staged file '$file'. Please check your code and try again. You can run ESLint manually via npm run eslint."
11+
exit 1 # exit with failure status
12+
fi
13+
done

0 commit comments

Comments
 (0)