Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
ESlint and Prettier for React apps (Bonus - Next.js and TypeScript)
module.exports = {
root: true,
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaVersion: 2020,
sourceType: 'module',
ecmaFeatures: {
jsx: true
}
},
settings: {
react: {
version: 'detect'
}
},
env: {
browser: true,
amd: true,
node: true
},
plugins: ['simple-import-sort'],
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/eslint-recommended',
'plugin:@typescript-eslint/recommended',
'plugin:react/recommended',
'plugin:jsx-a11y/recommended',
'prettier/@typescript-eslint',
'plugin:prettier/recommended'
],
rules: {
'prettier/prettier': ['error', {}, { usePrettierrc: true }],
'react/react-in-jsx-scope': 'off',
'react/prop-types': 'off',
'@typescript-eslint/explicit-function-return-type': 'off',
'simple-import-sort/sort': 'error',
'jsx-a11y/anchor-is-valid': [
'error',
{
components: ['Link'],
specialLink: ['hrefLeft', 'hrefRight'],
aspects: ['invalidHref', 'preferButton']
}
]
}
};
{
"semi": true,
"tabWidth": 4,
"printWidth": 100,
"singleQuote": true,
"trailingComma": "none",
"jsxBracketSameLine": true
}
npm i -D eslint \
prettier \
eslint-plugin-react \
eslint-plugin-react-hooks \
eslint-config-prettier \
eslint-plugin-prettier \
eslint-plugin-jsx-a11y
# TypeScript dependencies
npm i -D @typescript-eslint/eslint-plugin \
@typescript-eslint/parser \
# Import sort plugin
npm i -D eslint-plugin-simple-import-sort
# Husky and lint-staged
npm i -D husky lint-staged
{
"scripts": {
"lint": "eslint --fix .",
"format": "prettier --write './**/*.{js,jsx,ts,tsx,css,md,json}' --config ./.prettierrc"
},
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
"lint-staged": {
"./**/*.{js,jsx,ts,tsx}": [
"eslint --fix",
]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment