Skip to content

Instantly share code, notes, and snippets.

@thanhtoan1196
Forked from heyitsarpit/.eslintignore
Created September 15, 2020 12:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thanhtoan1196/10b8b6081a6dda8135221cf975600a5e to your computer and use it in GitHub Desktop.
Save thanhtoan1196/10b8b6081a6dda8135221cf975600a5e to your computer and use it in GitHub Desktop.
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