Skip to content

Instantly share code, notes, and snippets.

@Steve-Reid
Last active September 28, 2020 16:55
Show Gist options
  • Select an option

  • Save Steve-Reid/bbba14b22418c1116e6daf05e0042218 to your computer and use it in GitHub Desktop.

Select an option

Save Steve-Reid/bbba14b22418c1116e6daf05e0042218 to your computer and use it in GitHub Desktop.
Using ESLint and Prettier in a TypeScript Next.js Project with pre-commit hooks
module.exports = {
root: true,
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaFeatures: { jsx: true },
},
env: {
browser: true,
node: true,
},
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/eslint-recommended',
'plugin:@typescript-eslint/recommended',
'plugin:react/recommended',
'plugin:react-hooks/recommended',
'plugin:jsx-a11y/recommended',
// Prettier plugin and recommended rules
'plugin:prettier/recommended',
'prettier/@typescript-eslint',
],
rules: {
// Include .prettierrc.js rules
'prettier/prettier': ['error', {}, { usePrettierrc: true }],
'react/prop-types': 'off',
'react/react-in-jsx-scope': 'off',
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/ban-ts-ignore': 'off',
'jsx-a11y/label-has-associated-control': [
'error',
{
labelComponents: [],
labelAttributes: [],
controlComponents: [],
assert: 'either',
depth: 25,
},
],
'@typescript-eslint/no-explicit-any': 'off',
},
settings: {
react: {
version: 'detect',
},
},
};
}
"scripts": {
"dev": "next",
"build": "next build",
"start": "next start",
"lint": "eslint src --ext .ts,.tsx",
"lint:fix": "npm run lint -- --fix"
},
"lint-staged": {
"src/**/*.{ts,tsx}": "npm run lint:fix"
},
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
}
}
module.exports = {
semi: true,
trailingComma: 'es5',
singleQuote: true,
printWidth: 80,
tabWidth: 2,
};
{
"compilerOptions": {
"allowJs": true,
"alwaysStrict": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"isolatedModules": true,
"jsx": "preserve",
"lib": ["dom", "es2017"],
"module": "esnext",
"moduleResolution": "node",
"noEmit": true,
"noFallthroughCasesInSwitch": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"resolveJsonModule": true,
"skipLibCheck": true,
"strict": true,
"target": "esnext"
},
"exclude": ["node_modules"],
"include": ["**/*.ts", "**/*.tsx"]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment