TypeScript项目中的Eslint和更漂亮-禁用更漂亮的错误

时间:2020-02-29 01:21:12

标签: typescript eslint prettier

我尝试了所有可能的插件组合,并在.eslint中进行了扩展,以便与漂亮的插件一起很好地玩。我想要的是编辑器(vscode)在编写代码时不显示更漂亮的错误,因为我希望它能够理解在保存代码时(通过vscode上的fixOnSave选项)该错误将得到修复。 因此,这是我的eslint配置不起作用:

{
  "parser": "@typescript-eslint/parser",
  "parserOptions": {
    "ecmaVersion": 2018,
    "jsx": true,
    "useJSXTextNode": true
  },
  "env": {
    "browser": true,
    "jest/globals": true,
    "cypress/globals": true
  },
  "plugins": ["@typescript-eslint", "react-hooks", "jest", "prettier"],
  "extends": [
    "plugin:react/recommended",
    "airbnb",
    "plugin:cypress/recommended",
    "plugin:import/errors",
    "plugin:import/warnings",
    "plugin:import/typescript",
    "prettier/react",
    "plugin:prettier/recommended",
    "plugin:@typescript-eslint/eslint-recommended",
    "plugin:@typescript-eslint/recommended"
  ],
  "rules": {
    "prettier/prettier": "error",
    "import/extensions": [
      "error",
      "ignorePackages",
      {
        "js": "never",
        "jsx": "never",
        "ts": "never",
        "tsx": "never"
      }
    ],
    "import/no-extraneous-dependencies": [
      "error",
      {
        "devDependencies": [
          ".storybook/**",
          "**/stories/**",
          "jest.setup.js",
          "**/*.spec.[jt]s?(x)",
          "scripts/**",
          "src/test/**",
          "next.config.js",
          "cypress/**"
        ]
      }
    ],
    /**
     * @description rules of eslint official
     */
    /**
     * @bug https://github.com/benmosher/eslint-plugin-import/issues/1282
     * "import/named" temporary disable.
     */
    // "import/named": "off",
    "react/jsx-props-no-spreading": "off",
    "react/react-in-jsx-scope": "off",
    /**
     * @bug?
     * "import/export" temporary disable.
     */
    "import/export": "off",
    "import/prefer-default-export": "off", // Allow single Named-export
    "no-unused-expressions": [
      "warn",
      {
        "allowShortCircuit": true,
        "allowTernary": true
      }
    ], // https://eslint.org/docs/rules/no-unused-expressions

    /**
     * @description rules of @typescript-eslint
     */
    "@typescript-eslint/prefer-interface": "off", // also want to use "type"
    "@typescript-eslint/explicit-function-return-type": "off", // annoying to force return type

    /**
     * @description rules of eslint-plugin-react
     */
    "react/jsx-filename-extension": [
      "warn",
      {
        "extensions": [".jsx", ".tsx"]
      }
    ], // also want to use with ".tsx"
    "react/prop-types": "off", // Is this incompatible with TS props type?

    /**
     * @description rules of eslint-plugin-react-hooks
     */
    "react-hooks/rules-of-hooks": "error",
    "@typescript-eslint/ban-ts-ignore": "off",
    "no-console": "off",
    "react/destructuring-assignment": "off"
  }
}

这是更漂亮的配置:

{
  "semi": true,
  "trailingComma": "all",
  "singleQuote": true,
  "printWidth": 80
}

我不太了解这些插件如何在extends中一起玩。希望这对stackoverflow是一个有效的问题:)

0 个答案:

没有答案