关于在 vue3+vite+ts 的情况下,构建 eslint 的方法,亲测有效

本贴最后更新于 645 天前,其中的信息可能已经水流花落

一、首先安装 eslint 所需的依赖

yarn add eslint eslint-plugin-vue  eslint-plugin-prettier eslint-config-airbnb-base eslint-plugin-import @typescript-eslint/parser --dev

二、在根目录下创建 eslint 的配置文件.eslintrc

{
  "root": true,
  "env": {
    "browser": true,
    "vue/setup-compiler-macros": true
  },
  "parserOptions": {
    "ecmaVersion": 12,
    "parser": "@typescript-eslint/parser"
  },
  "plugins": [
    "prettier"
  ],
  "globals": { //这个地方配置是为了防止下面的几个东西没有引入而被报错
    "defineProps": "readonly",
    "defineEmits": "readonly",
    "defineExpose": "readonly",
    "withDefaults": "readonly",
    "defineOptions": "readonly"
  },
  "extends": [
    "plugin:vue/vue3-recommended",
    "airbnb-base",
    "plugin:prettier/recommended"
  ],
  "overrides": [
    {
      "files": "*.html",
      "processor": "vue/.vue"
    }
  ],
  "settings": {
    "import/resolver": {
      "node": {
        "extensions": [
          ".js",
          ".jsx",
          ".ts",
          ".tsx"
        ]
      }
    }
  },
  "rules": {
    "prettier/prettier": [
      "error",
      {
        "semi": true,
        "endOfLine": "auto",
        "singleQuote": true,
        "trailingComma": "none",
        "bracketSpacing": true,
        "jsxBracketSameLine": false,
        "vueIndentScriptAndStyle": false,
        "jsxBracketSameLine:": true,
        "htmlWhitespaceSensitivity": "ignore",
        "wrapAttributes": true,
        "overrides": [
          {
            "files": "*.html",
            "options": {
              "parser": "html"
            }
          }
        ]
      }
    ],
    "import/no-extraneous-dependencies": ["error",  {"devDependencies": true}],
    "vue/multi-word-component-names": "off",
    "import/no-unresolved": "off",
    "import/extensions": "off",
    "no-console": "off",
    "consistent-return": "off",
    "no-param-reassign": "off",
    "new-cap": "off",
    "no-shadow": "off",
    "no-underscore-dangle": "off",
    "vue/no-v-html": "off",
    "no-restricted-syntax": "off",
    "guard-for-in": "off",
    "import/prefer-default-export": "off",
    "camelcase": "off",
    "no-use-before-define": "off"
  }
}


三、安装 prettier 的依赖

yarn add prettier eslint-config-prettier eslint-config-prettier --dev

以下为 prettier 的配置在根目录下新建 .prettierrc 文件

{
  "semi": true,
  "endOfLine": "auto",
  "singleQuote": true,
  "trailingComma": "none",
  "bracketSpacing": true,
  "jsxBracketSameLine": false,
  "vueIndentScriptAndStyle": false,
  "jsxBracketSameLine:": true,
  "htmlWhitespaceSensitivity": "ignore",
  "wrapAttributes": true,
  "overrides": [
    {
      "files": "*.html",
      "options": {
        "parser": "html"
      }
    }
  ]
}
  • eslint
    3 引用
  • Vue.js

    Vue.js(读音 /vju ː/,类似于 view)是一个构建数据驱动的 Web 界面库。Vue.js 的目标是通过尽可能简单的 API 实现响应的数据绑定和组合的视图组件。

    266 引用 • 665 回帖
  • vite
    5 引用 • 2 回帖
  • TypeScript
    22 引用 • 19 回帖 • 2 关注
2 操作
tenxll 在 2023-02-15 01:24:28 更新了该帖
tenxll 在 2023-02-10 21:41:45 更新了该帖

相关帖子

欢迎来到这里!

我们正在构建一个小众社区,大家在这里相互信任,以平等 • 自由 • 奔放的价值观进行分享交流。最终,希望大家能够找到与自己志同道合的伙伴,共同成长。

注册 关于
请输入回帖内容 ...