React Native [Expo]
npx create-expo-app@latest
npm install --save-dev eslint prettier eslint-config-prettier eslint-plugin-prettier @typescript-eslint/parser @typescript-eslint/eslint-plugin eslint-plugin-react eslint-plugin-react-native eslint-plugin-import-helpers eslint-plugin-jsx-a11y husky lint-staged @commitlint/{cli,config-conventional}
Development Dependencies for React Native [Expo] with TypeScript
--save-dev: Saves dependencies only for the development environment.
eslint: Tool to analyze and find problems in JavaScript and TypeScript code.
prettier: Code formatter that ensures a consistent style throughout the project.
eslint-config-prettier: Disables ESLint rules that might interfere with Prettier.
eslint-plugin-prettier: Integrates Prettier with ESLint to show formatting errors.
@typescript-eslint/parser: Parser that allows ESLint to understand TypeScript.
@typescript-eslint/eslint-plugin: Set of specific TypeScript rules for ESLint.
eslint-plugin-react: Specific rules for React for ESLint.
eslint-plugin-react-native: Specific rules for React Native for ESLint.
eslint-plugin-import-helpers: ESLint plugin to automatically order imports.
eslint-plugin-jsx-a11y: Helps improve accessibility in JSX components.
husky: Tool to create Git hooks, helping automate tasks before committing.
lint-staged: Runs linters on staged files in Git.
@commitlint/cli, @commitlint/config-conventional: Tools to ensure commit messages follow a conventional standard.
Eslint Config
.eslintrc.js
module.exports = {
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaVersion: 2020,
sourceType: 'module',
},
env: {
browser: true,
node: true,
'react-native/react-native': true,
},
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'plugin:react/recommended',
'plugin:react-hooks/recommended',
'plugin:react-native/all',
'prettier',
],
plugins: [
'@typescript-eslint',
'prettier',
'react',
'react-native',
'import-helpers',
'jsx-a11y'
],
rules: {
'prettier/prettier': ['error'],
'react/react-in-jsx-scope': 'off',
'react/prop-types': 'off',
'no-multiple-empty-lines': ['error', { max: 1, maxEOF: 1 }],
'import-helpers/order-imports': [
'warn',
{
newlinesBetween: 'always',
groups: [
['module', '/^react/', '/^react-native/'],
['/^@expo/'],
['/^@components/', '/^@screens/', '/^@assets/'],
['parent', 'sibling', 'index'],
],
alphabetize: { order: 'asc', ignoreCase: true },
},
],
'react-native/no-unused-styles': "off",
'react-native/split-platform-components': "off",
'react-native/no-inline-styles': "off",
'react-native/no-color-literals': 2,
'react-native/no-raw-text': "off",
'jsx-a11y/accessible-emoji': 'off',
'react/no-unescaped-entities': 'off',
'react-native/no-color-literals': 'off',
},
settings: {
react: {
version: 'detect',
},
},
};
Prettier Config
prettier.config.js
module.exports = {
"useTabs": false,
"singleQuote": false,
};
Commitlint Config
commitlint.config.js
module.exports = { extends: ["@commitlint/config-conventional"] };
Husky
npx husky install
pre-commit
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"
npx lint-staged
commit-msg
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"
npx --no -- commitlint --edit
Package.json
package.json
"format": "prettier --write .",
"lint": "eslint --fix . --ext .js,.jsx,.ts,.tsx",
"prepare": "husky install"
Lint Staged Config
.lintstagedrc
{
"**/*.{js,jsx,ts,tsx}": ["npm run format", "npm run lint"]
}
Ignore Eslint
.eslintignore
dist
package-lock.json
husky
configs
env
public
server.js
jsconfig.json
package.json
public
README.md
..eslintrc*
.eslintrc.json
.eslintrc.js
.prettierrc.json
.eslint*
commitlint.config.js
next-env.d.ts
postcss.config.js
prettier.config.js
scripts
Ignore Prettier
.prettierignore
dist
package-lock.json
configs
env
husky
public
server.js
jsconfig.json
package.json
public
README.md
.eslintrc*
.eslintrc.json
.eslintrc.js
.prettierrc.json
commitlint.config.js
next-env.d.ts
postcss.config.js
commitlint.config.js
prettier.config.js
scripts