求一个针对 React+TSX 的 ESLint+Prettier 的 Boilerplate - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
请不要在回答技术问题时复制粘贴 AI 生成的内容
xlsepiphone
V2EX    程序员

求一个针对 React+TSX 的 ESLint+Prettier 的 Boilerplate

  •  
  •   xlsepiphone 2021-09-16 16:28:22 +08:00 1959 次点击
    这是一个创建于 1536 天前的主题,其中的信息可能已经有所发展或是发生改变。

    想优化一下自己的配置,但是感觉又无从下手(之前从 Google 抄的,感觉是个缝合怪,所以不敢乱改,怕配坏了,折腾半天),如果 ESLint 和 Prettier 能够合并成一个工具那就好了,主要是我看到 eslint 兼容 prettier 的那堆配置,我心里发慌,不敢乱动。

    所以 RT,求一个针对 React+TSX 的 ESLint+Prettier 的 Boilerplate,最好是主流常用的。

    楼主非专业前端,看到一大堆配置就发慌,轻喷。

    9 条回复    2021-09-24 14:52:12 +08:00
    withoutxx
        1
    withoutxx  
       2021-09-16 16:38:45 +08:00   1
    @umijs/fabric 试试这个
    rioshikelong121
        2
    rioshikelong121  
       2021-09-16 18:23:36 +08:00
    cra 不是自带么。
    XTTX
        3
    XTTX  
       2021-09-16 18:24:29 +08:00   1
    https://github.com/wesbos/eslint-config-wesbos
    ========================================
    tsconfig
    {
    "compilerOptions": {
    "target": "es5",
    "lib": ["dom", "dom.iterable", "esnext"],
    "allowJs": true,
    "skipLibCheck": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "noFallthroughCasesInSwitch": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "noEmit": true,
    "jsx": "react-jsx"
    },
    "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],
    "exclude": ["node_modules"]
    }
    XTTX
        4
    XTTX  
       2021-09-16 18:25:32 +08:00
    eslintrc
    ======================================
    {
    "extends": ["wesbos", "wesbos/typescript"],
    "parserOptions": {
    "project": ["./tsconfig.json"]
    },
    "rules": {
    "no-use-before-define": "off",
    "no-shadow": "off",
    "@typescript-eslint/no-unsafe-assignment": "off",
    "@typescript-eslint/no-unsafe-call": "off",
    "@typescript-eslint/no-unsafe-member-access": "off",
    "@typescript-eslint/no-unsafe-return": "warn",
    "@typescript-eslint/no-floating-promises": "warn",
    "@typescript-eslint/no-use-before-define": "error",
    "@typescript-eslint/require-await": "off",
    "@typescript-eslint/restrict-plus-operands": "off",
    "prefer-template": "off",
    "arrow-body-style": "off",
    "react/button-has-type": "off",
    "@typescript-eslint/restrict-template-expressions": "off",
    "no-console": "off",
    "prettier/prettier": [
    "warn",
    {
    "endOfLine": "auto",
    "singleQuote": true,
    "semi": false
    }
    ]
    }
    }
    XTTX
        5
    XTTX  
       2021-09-16 18:26:30 +08:00
    airbnb 的规范 我很多都搞不懂,我在不停地添加 rules, 改成 “off” 或者“warn"
    7anshuai
        6
    7anshuai  
       2021-09-16 18:59:14 +08:00   1
    https://github.com/vikpe/react-webpack-typescript-starter 这个是极简风的,可以根据自己需求添加规则
    beginor
        7
    beginor  
       2021-09-16 19:02:16 +08:00 via Android   1
    喜欢严格模式的话,可以看看我的这个

    https://github.com/beginor/rollup-react
    myCupOfTea
        8
    myCupOfTea  
       2021-09-24 14:51:07 +08:00
    直接用 vite 的模版 然后装 prettier 和 eslint 就好了
    myCupOfTea
        9
    myCupOfTea  
       2021-09-24 14:52:12 +08:00
    "@typescript-eslint/eslint-plugin": "^4.29.0",
    "@typescript-eslint/parser": "^4.29.0",
    "@typescript-eslint/typescript-estree": "^4.29.0",
    "eslint": "^7.32.0",
    "eslint-config-airbnb": "^18.2.1",
    "eslint-config-airbnb-typescript": "^12.3.1",
    "eslint-config-prettier": "^8.3.0",
    "eslint-plugin-import": "^2.23.4",
    "eslint-plugin-jest": "^24.4.0",
    "eslint-plugin-jsx-a11y": "^6.4.1",
    "eslint-plugin-react": "^7.24.0",
    "eslint-plugin-react-hooks": "^4.2.0",
    "eslint-plugin-unicorn": "^35.0.0",
    "prettier-eslint": "^13.0.0",
    "prettier-eslint-cli": "^5.0.1",
    关于     帮助文档     自助推广系统     博客     API     FAQ     Solana     5557 人在线   最高记录 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 30ms UTC 03:28 PVG 11:28 LAX 19:28 JFK 22:28
    Do have faith in what you're doing.
    ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86