V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
TWorldIsNButThis
V2EX  ›  前端开发

2022 年了,怎么还没有 all in one 的 linter+formatter

  •  
  •   TWorldIsNButThis · 2022-03-04 22:22:19 +08:00 · 1632 次点击
    这是一个创建于 775 天前的主题,其中的信息可能已经有所发展或是发生改变。

    最近要新建一个项目,想把各个依赖都升到最新,结果 vite ts react 的模板项目装好 eslint 上来就报了几个错,用的 airbnb 的预设

    react 插件有好几条老规则早不适用了不知道为什么还不改,比如什么 jsx 文件必须引入 react ,还什么函数式组件也提示必须写 defaultProps

    还是说这是 airbnb 预设的问题?

    然后 prettier 和 eslint 还有冲突,比如我声明一个箭头函数,参数用的解构声明,eslint 说太长了必须换行,prettier 说解构声明的大括号后面里不能换行?

    听说 fb 弄了个 all in one 的 rome ,但是我搜了下官网说现在在用 rust 重构项目,这个有人用过吗?

    8 条回复    2022-04-13 18:50:27 +08:00
    yoa1q7y
        1
    yoa1q7y  
       2022-03-04 22:39:52 +08:00
    eslint config 部分配置
    ```json
    {
    "extends": [
    "eslint:recommended",
    "plugin:@typescript-eslint/recommended",
    "plugin:react/recommended",
    "plugin:react-hooks/recommended",
    "plugin:prettier/recommended"
    ],
    "parser": "@typescript-eslint/parser",
    "parserOptions": {
    "ecmaFeatures": {
    "jsx": true
    },
    "ecmaVersion": "latest",
    "sourceType": "module"
    },
    "settings": {
    "react": {
    "version": "detect"
    }
    }
    }
    ```

    package.json
    ```json
    {
    "@typescript-eslint/eslint-plugin": "^5.12.1",
    "@typescript-eslint/parser": "^5.12.1",
    "eslint": "^8.10.0",
    "eslint-config-prettier": "^8.4.0",
    "eslint-plugin-prettier": "^4.0.0",
    "eslint-plugin-react": "^7.29.2",
    "eslint-plugin-react-hooks": "^4.3.0"
    }
    ```

    这样就足够了
    seki
        2
    seki  
       2022-03-04 22:46:21 +08:00
    当然是自己选配啊,当年那些希望推行统一规则的项目比如 jshint 和 standard ,都已经没人用了,因为用的时候总有想法不一致的地方。airbnb 也是适合 airbnb 的情况而已,你用着不舒服也很正常

    prettier 你要看 plugin-prettier 的文档,需要覆盖掉一些规则
    erguotou521
        3
    erguotou521  
       2022-03-04 23:13:48 +08:00 via Android
    npm i -g fe-conf
    fe-conf
    TWorldIsNButThis
        4
    TWorldIsNButThis  
    OP
       2022-03-05 03:57:34 +08:00
    @yoa1q7y
    这个是不是要把 prettier 的配置写在 eslint 里
    然后试了下必须引入 react 的报错还是必须得手动关掉,settings 里设置 react 的版本有啥用
    noe132
        5
    noe132  
       2022-03-05 11:06:50 +08:00 via Android
    自己配+1
    或者不想自己配可以试试我的 config
    https://www.npmjs.com/package/@noe132/eslint-config-react
    eslint fix 就是 formatter ,不需要启用 prettier
    Charrlles
        6
    Charrlles  
       2022-03-05 15:05:43 +08:00 via iPhone
    用 vite 还是需要引入 react 的吧
    Jaosn
        7
    Jaosn  
       2022-03-05 23:47:25 +08:00
    不要用 airbnb ,确实我也觉得前端需要一个 all in one
    hronro
        8
    hronro  
       2022-04-13 18:50:27 +08:00 via iPhone
    说道 all in one ,为啥不考虑 deno ? Linter, Fomatter, Runner 全都有了,速度还特别快(因为它的 linter formatter 都是 Rust 实现的)
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5271 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 07:36 · PVG 15:36 · LAX 00:36 · JFK 03:36
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.