Last active
February 2, 2024 11:07
-
-
Save jsun969/a12ac050e66bb2a4eb8d63adabe2dc76 to your computer and use it in GitHub Desktop.
Typescript Project Formatter & Linter & Git Hooks
This file contains 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 = { | |
parser: '@typescript-eslint/parser', | |
parserOptions: { | |
project: ['./tsconfig.json'], | |
}, | |
plugins: ['@typescript-eslint'], | |
extends: [ | |
'eslint:recommended', | |
'plugin:@typescript-eslint/recommended', | |
'plugin:prettier/recommended', | |
// React | |
'plugin:react-hooks/recommended', | |
// NextJS | |
'next/core-web-vitals', | |
], | |
ignorePatterns: ['*.cjs', '*.mjs'], | |
rules: { | |
'@typescript-eslint/explicit-function-return-type': 'off', | |
'@typescript-eslint/explicit-module-boundary-types': 'off', | |
'@typescript-eslint/no-non-null-assertion': 'off', | |
'@typescript-eslint/no-unused-vars': ['warn', { ignoreRestSiblings: true }], | |
'@typescript-eslint/consistent-type-imports': [ | |
'warn', | |
{ disallowTypeAnnotations: false }, | |
], | |
'no-console': 'warn', | |
}, | |
}; |
This file contains 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
/** @type {import('prettier').Config & import('prettier-plugin-tailwindcss').PluginOptions & import('@trivago/prettier-plugin-sort-imports').PluginConfig} */ | |
module.exports = { | |
singleQuote: true, | |
trailingComma: 'all', | |
useTabs: true, | |
plugins: [ | |
'@trivago/prettier-plugin-sort-imports', | |
'prettier-plugin-tailwindcss', | |
], | |
importOrder: ['<THIRD_PARTY_MODULES>', '^[./]'], | |
importOrderSeparation: true, | |
}; |
This file contains 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
pnpm add -D eslint @typescript-eslint/parser @typescript-eslint/eslint-plugin eslint-config-prettier eslint-plugin-prettier | |
# React | |
pnpm add -D eslint-plugin-react eslint-plugin-react-hooks | |
# NextJS | |
pnpm add -D eslint-plugin-next |
This file contains 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
pnpm add -D simple-git-hooks lint-staged | |
# After configure package.json | |
npx simple-git-hooks |
This file contains 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
pnpm add -D prettier @trivago/prettier-plugin-sort-imports |
This file contains 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": { | |
"prepare": "simple-git-hooks", | |
"format": "prettier --write \"**/*.{js,ts,tsx,css,md,,cjs,mjs,json}\"", | |
"lint": "eslint \"**/*.{js,ts,tsx}\" --fix" | |
}, | |
"lint-staged": { | |
"*.{js,ts,tsx,css,md,cjs,mjs,json}": [ | |
"prettier --write" | |
] | |
}, | |
"simple-git-hooks": { | |
"pre-commit": "npx lint-staged" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
tql