-
-
Save anzart/b3a1ca8fa61890a0448977f8c9953726 to your computer and use it in GitHub Desktop.
ESlint and Prettier for React apps (Bonus - Next.js and TypeScript)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
node_modules |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'] | |
} | |
] | |
} | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
node_modules |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"semi": true, | |
"tabWidth": 4, | |
"printWidth": 100, | |
"singleQuote": true, | |
"trailingComma": "none", | |
"jsxBracketSameLine": true | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"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