简体   繁体   English

更漂亮和/或 Eslint?

[英]Prettier and / or Eslint?

Most of the projects I work on I just fire up and, at most, disable a linting rule that bugs me.我从事的大多数项目都只是启动,最多禁用一个让我烦恼的 linting 规则。 That is to say I don't know much about linting and linters except that eslint is everywhere.也就是说我对 linting 和 linters 了解不多,除了 eslint 无处不在。

A Vue project I'm working on now (that I did not initially build) has four linting modules and I now want to understand if all of them are necessary, if they are conflicting with each other or complimenting each other.我现在正在处理的一个 Vue 项目(我最初没有构建)有四个 linting 模块,我现在想了解它们是否都是必需的,它们是否相互冲突或相互补充。 I'm getting so many yellow warnings that don't get fixed with the --fix flag that I want to uninstall everything and install one linter to rule them all.我收到了很多黄色警告,这些警告没有用 --fix 标志修复,我想卸载所有东西并安装一个 linter 来统治它们。

The project package.json has these: package.json 项目有这些:

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

Thoughts?想法?

My eslintrc.js我的 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,
      },
    },
  ],
};

Not sure if I can give a direct answer, but it's super common to combine eslint along with prettier via eslint-plugin-prettier .不确定我是否可以直接回答,但是通过eslint-plugin-prettiereslintprettier结合起来是非常常见的。 We use prettier purely for code formatting rules like:我们将prettier纯粹用于代码格式化规则,例如:

  • single vs double quotes单引号和双引号
  • max line length最大线长
  • semicolons or not分号与否

eslint is more commonly used to find errors in your code that otherwise wouldn't have been caught until runtime. eslint更常用于查找代码中的错误,否则这些错误直到运行时才会被捕获。 Not every rule in eslint can be fixed via eslint --fix , but many can be.不是eslint中的每条规则都可以通过eslint --fix来修复,但很多都可以。 What does your .eslintrc look like?你的.eslintrc是什么样的?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM