Last active
December 2, 2024 16:01
-
-
Save jsun969/a12ac050e66bb2a4eb8d63adabe2dc76 to your computer and use it in GitHub Desktop.
Typescript Project Formatter & Linter & Git Hooks
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
| /** @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 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
| import js from '@eslint/js'; | |
| import eslintPluginPrettierRecommended from 'eslint-plugin-prettier/recommended'; | |
| import reactHooks from 'eslint-plugin-react-hooks'; | |
| import reactRefresh from 'eslint-plugin-react-refresh'; | |
| import globals from 'globals'; | |
| import tseslint from 'typescript-eslint'; | |
| export default tseslint.config( | |
| { ignores: ['dist'] }, | |
| { | |
| extends: [ | |
| js.configs.recommended, | |
| eslintPluginPrettierRecommended, | |
| ...tseslint.configs.recommended, | |
| ], | |
| files: ['**/*.{ts,tsx}'], | |
| languageOptions: { | |
| ecmaVersion: 'latest', | |
| globals: globals.browser, | |
| }, | |
| plugins: { | |
| 'react-hooks': reactHooks, | |
| 'react-refresh': reactRefresh, | |
| }, | |
| rules: { | |
| ...reactHooks.configs.recommended.rules, | |
| 'react-refresh/only-export-components': [ | |
| 'warn', | |
| { allowConstantExport: true }, | |
| ], | |
| '@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', | |
| eqeqeq: 'warn', | |
| 'prefer-const': 'warn', | |
| 'no-var': 'warn', | |
| }, | |
| }, | |
| ); |
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
| pnpm add -D eslint @eslint/js @types/eslint__js typescript typescript-eslint eslint-plugin-prettier eslint-config-prettier globals | |
| # React | |
| pnpm add -D eslint-plugin-react eslint-plugin-react-hooks | |
| # NextJS | |
| pnpm add -D eslint-plugin-next |
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
| pnpm add -D simple-git-hooks pretty-quick | |
| # After configure package.json | |
| npx simple-git-hooks |
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
| pnpm add -D prettier @trivago/prettier-plugin-sort-imports |
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": { | |
| "prepare": "simple-git-hooks", | |
| "format": "prettier --write \"**/*.{js,ts,tsx,css,md,cjs,mjs,json,html}\"", | |
| "lint": "eslint \"**/*.{js,ts,tsx}\" --fix" | |
| }, | |
| "simple-git-hooks": { | |
| "pre-commit": "pnpx pretty-quick --staged" | |
| }, | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
tql