【问题标题】:Prettier and / or Eslint?更漂亮和/或 Eslint?
【发布时间】:2020-10-19 02:51:23
【问题描述】:

我从事的大多数项目都只是启动,最多禁用一个让我烦恼的 linting 规则。也就是说我对 linting 和 linters 了解不多,除了 eslint 无处不在。

我现在正在处理的一个 Vue 项目(我最初没有构建)有四个 linting 模块,我现在想了解它们是否都是必需的,它们是否相互冲突或相互补充。我收到了很多黄色警告,这些警告没有用 --fix 标志修复,我想卸载所有东西并安装一个 linter 来统治它们。

项目 package.json 有这些:

{
  "eslint": "^7.3.1",
  "eslint-plugin-prettier": "^3.1.1",
  "eslint-plugin-vue": "^6.2.2",
  "lint-staged": "^10.2.7"
}

想法?

我的 eslintrc.js

module.exports = {
  root: true,
  env: {
    node: true,
  },
  extends: ["plugin:vue/essential", "@vue/prettier"],
  rules: {
    "no-console": process.env.NODE_ENV === "production" ? "off" : "off",
    "no-debugger": process.env.NODE_ENV === "production" ? "error" : "off",
    "max-len": [0, 0, 0],
    singleQuote: 0,
    trailingComma: 0,
    "no-unused-vars": 0,
    "vue/no-unused-components": 0,
  },
  parserOptions: {
    parser: "babel-eslint",
  },
  overrides: [
    {
      files: ["**/__tests__/*.{j,t}s?(x)", "**/tests/unit/**/*.spec.{j,t}s?(x)"],
      env: {
        jest: true,
      },
    },
  ],
};

【问题讨论】:

    标签: javascript eslint prettier


    【解决方案1】:

    不确定我是否可以直接回答,但通过eslint-plugin-prettiereslintprettier 结合起来非常常见。我们使用prettier 纯粹用于代码格式化规则,例如:

    • 单引号和双引号
    • 最大行长
    • 分号与否

    eslint 更常用于查找代码中的错误,否则这些错误直到运行时才会被发现。并非eslint 中的每条规则都可以通过eslint --fix 修复,但很多都可以。你的.eslintrc 是什么样的?

    【讨论】:

    • 谢谢。我在我的问题中添加了我的.eslintrc
    猜你喜欢
    • 2021-04-08
    • 2019-01-23
    • 2021-06-02
    • 2021-04-06
    • 2018-05-13
    • 2020-02-13
    • 2021-09-12
    • 2021-08-31
    • 2020-01-28
    相关资源
    最近更新 更多