vue-cli项目 eslint和prettier搭配 如何过滤掉某一些文件或者文件夹?

_SYY_
  • 38

需求:
比如 引入了一个UI组件库
项目:
使用了eslint和eslint-config-prettier
如下图

"devDependencies": {
    "@dcloudio/types": "*",
    "@dcloudio/uni-automator": "^2.0.0-28620200814004",
    "@dcloudio/uni-cli-shared": "^2.0.0-28620200814004",
    "@dcloudio/uni-migration": "^2.0.0-28620200814004",
    "@dcloudio/uni-template-compiler": "^2.0.0-28620200814004",
    "@dcloudio/vue-cli-plugin-hbuilderx": "^2.0.0-28620200814004",
    "@dcloudio/vue-cli-plugin-uni": "^2.0.0-28620200814004",
    "@dcloudio/vue-cli-plugin-uni-optimize": "^2.0.0-28620200814004",
    "@dcloudio/webpack-uni-mp-loader": "^2.0.0-28620200814004",
    "@dcloudio/webpack-uni-pages-loader": "^2.0.0-28620200814004",
    "@vue/cli-plugin-babel": "^4.5.0",
    "@vue/cli-plugin-eslint": "^3.9.0",
    "@vue/cli-service": "^4.5.0",
    "@vue/eslint-config-prettier": "^4.0.1",
    "babel-eslint": "^10.0.1",
    "babel-plugin-import": "^1.11.0",
    "cross-env": "^7.0.2",
    "eslint": "^5.16.0",
    "eslint-plugin-vue": "^5.0.0",
    "jest": "^25.4.0",
    "mini-types": "*",
    "miniprogram-api-typings": "*",
    "node-sass": "^4.14.1",
    "postcss-comment": "^2.0.0",
    "sass-loader": "^9.0.3",
    "uview-ui": "^1.6.2",
    "vue-template-compiler": "^2.6.11"
  }

文件结构如图所示
image

如图所示 uview-ui 为需要过滤文件

.eslintrc.js

module.exports = {
  root: true,
  env: {
    node: true
  },
  extends: ["plugin:vue/essential", "@vue/prettier"],
  rules: {
    "no-console": process.env.NODE_ENV === "production" ? "error" : "off",
    "no-debugger": process.env.NODE_ENV === "production" ? "error" : "off"
  },
  parserOptions: {
    parser: "babel-eslint"
  },
  globals: {
    uni: true
  }
};

.eslintignore

/src/uview-ui/
/src/uview-ui/*

.prettierignore

/src/uview-ui/*
/src/uview-ui/

需要过滤掉 src文件夹 下面的uview-ui文件夹中的所有内容
现在的问题是
已经能够正确在代码编辑时
屏蔽掉uview-ui文件夹中文件
停止eslint校对 以及 prettier 自动格式化
但是 当运行项目时
比如 npm run dev
image

这个警告报错 如何屏蔽掉呢?

目前尝试的可解决方法
在每个需要屏蔽的文件标题添加
/ eslint-disable /
但是文件太多了 有没有别的办法?

回复
阅读 2.3k
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
宣传栏