项目作者: luozyiii

项目描述 :
基于eslint-config-alloy的vue项目校验
高级语言: JavaScript
项目地址: git://github.com/luozyiii/eslint-config-alloy-vue.git
创建时间: 2020-05-14T14:25:05Z
项目社区:https://github.com/luozyiii/eslint-config-alloy-vue

开源协议:

下载


eslint-config-alloy-vue

node版本需在12.0.0以上

安装ESLint

  1. yarn add eslint babel-eslint vue-eslint-parser eslint-plugin-vue eslint-config-alloy -D

安装Prettier

  1. yarn add prettier eslint-config-prettier eslint-plugin-prettier -D

在你的项目的根目录下创建一个 .eslintrc.js 文件,并将以下内容复制进去:

  1. // .eslintrc.js
  2. // extends 这一句很关键 plugin:prettier/recommended
  3. module.exports = {
  4. extends: ['alloy', 'alloy/vue', 'plugin:prettier/recommended'],
  5. env: {
  6. // 你的环境变量(包含多个预定义的全局变量)
  7. //
  8. // browser: true,
  9. // node: true,
  10. // mocha: true,
  11. // jest: true,
  12. // jquery: true
  13. },
  14. globals: {
  15. // 你的全局变量(设置为 false 表示它不允许被重新赋值)
  16. //
  17. // myGlobal: false
  18. },
  19. rules: {
  20. // 自定义你的规则
  21. }
  22. };

在你的项目的根目录下创建一个 .prettierrc.js 文件,并将以下内容复制进去:

  1. // .prettierrc.js
  2. module.exports = {
  3. // 一行最多 100 字符
  4. printWidth: 100,
  5. // 使用 2 个空格缩进
  6. tabWidth: 2,
  7. // 不使用缩进符,而使用空格
  8. useTabs: false,
  9. // 行尾需要有分号
  10. semi: true,
  11. // 使用单引号
  12. singleQuote: true,
  13. // 对象的 key 仅在必要时用引号
  14. quoteProps: 'as-needed',
  15. // jsx 不使用单引号,而使用双引号
  16. jsxSingleQuote: false,
  17. // 末尾不需要逗号
  18. trailingComma: 'none',
  19. // 大括号内的首尾需要空格
  20. bracketSpacing: true,
  21. // jsx 标签的反尖括号需要换行
  22. jsxBracketSameLine: false,
  23. // 箭头函数,只有一个参数的时候,也需要括号
  24. arrowParens: 'always',
  25. // 每个文件格式化的范围是文件的全部内容
  26. rangeStart: 0,
  27. rangeEnd: Infinity,
  28. // 不需要写文件开头的 @prettier
  29. requirePragma: false,
  30. // 不需要自动在文件开头插入 @prettier
  31. insertPragma: false,
  32. // 使用默认的折行标准
  33. proseWrap: 'preserve',
  34. // 根据显示样式决定 html 要不要折行
  35. htmlWhitespaceSensitivity: 'css',
  36. // 换行符使用 lf
  37. endOfLine: 'lf'
  38. };

vscode setting 配置

  1. {
  2. "eslint.autoFixOnSave": true,
  3. "eslint.validate": [
  4. {
  5. "language": "javascript",
  6. "autoFix": true
  7. },
  8. {
  9. "language": "javascriptreact",
  10. "autoFix": true
  11. },
  12. {
  13. "language": "typescript",
  14. "autoFix": true
  15. },
  16. {
  17. "language": "html",
  18. "autoFix": true
  19. },
  20. {
  21. "language": "vue",
  22. "autoFix": true
  23. }
  24. ],
  25. "editor.codeActionsOnSave": {
  26. "source.fixAll.eslint": true
  27. }
  28. }