Переглянути джерело

chore: 更新代码风格配置

wll8 5 місяців тому
батько
коміт
e32a858262
8 змінених файлів з 102 додано та 38 видалено
  1. 18 1
      .eslintrc.js
  2. 1 3
      babel.config.js
  3. 11 7
      mm/api/index.js
  4. 20 17
      mm/mm.config.js
  5. 2 2
      mm/util.js
  6. 4 0
      package.json
  7. 7 7
      vue.config.js
  8. 39 1
      yarn.lock

+ 18 - 1
.eslintrc.js

@@ -1,11 +1,21 @@
 module.exports = {
   "root": true,
+  "globals": {
+    echarts: true,
+  },
   "env": {
     "node": true
   },
   "extends": [
     "plugin:vue/essential",
-    "eslint:recommended"
+    "eslint:recommended",
+    "@vue/prettier"
+  ],
+  ignorePatterns: [
+    `node_modules/`,
+    `dist/`,
+    `public/`,
+    `src/assets/`,
   ],
   "parserOptions": {
     "parser": "babel-eslint"
@@ -13,6 +23,13 @@ module.exports = {
   "rules": {
     "no-var": "error",
     "spaced-comment": "error",
+    "prettier/prettier": [
+      "error",
+      {
+        "singleQuote": true,
+        "semi": false
+      }
+    ],
     "semi": [
       "error",
       "never"

+ 1 - 3
babel.config.js

@@ -1,5 +1,3 @@
 module.exports = {
-  presets: [
-    '@vue/cli-plugin-babel/preset'
-  ]
+  presets: [`@vue/cli-plugin-babel/preset`],
 }

+ 11 - 7
mm/api/index.js

@@ -1,19 +1,23 @@
 const { wrapApiData } = require(`../util.js`)
 
 /** @type {import('mockm/@types/config').Config} */
-module.exports = util => {
+module.exports = (util) => {
   const {
     libObj: { mockjs },
   } = util
   return {
     api: {
       // 创建接口并使用 mockjs 生成数据
-      'get /api/test': wrapApiData(mockjs.mock({
-        'data|3-7': [{
-          userId: `@id`,
-          userName: `@cname`,
-        }],
-      })),
+      'get /api/test': wrapApiData(
+        mockjs.mock({
+          'data|3-7': [
+            {
+              userId: `@id`,
+              userName: `@cname`,
+            },
+          ],
+        })
+      ),
     },
   }
 }

+ 20 - 17
mm/mm.config.js

@@ -2,11 +2,11 @@ const api = require(`./api/index.js`)
 const { wrapApiData } = require(`./util.js`)
 
 /**
- * 配置说明请参考文档: 
+ * 配置说明请参考文档:
  * https://hongqiye.com/doc/mockm/config/option.html
  * @type {import('mockm/@types/config').Config}
  */
-module.exports = async util => {
+module.exports = async (util) => {
   const joi = await util.tool.generate.initPackge(`joi`)
   return {
     plugin: [util.plugin.validate, util.plugin.apiDoc],
@@ -22,7 +22,7 @@ module.exports = async util => {
     api: {
       // 在其他文件里的 api
       ...api(util).api,
-      "post /api/login": util.side({
+      'post /api/login': util.side({
         tags: [`admin`],
         summary: `根据用户名获取 token`,
         schema: {
@@ -46,15 +46,15 @@ module.exports = async util => {
         },
       }),
       // 当为基本数据类型时, 直接返回数据, 这个接口返回 {"msg":"ok"}
-      '/api/1': {msg: `ok`},
+      '/api/1': { msg: `ok` },
 
       // 也可以像 express 一样返回数据
-      '/api/2' (req, res) {
-        res.send({msg: `ok`})
+      '/api/2'(req, res) {
+        res.send({ msg: `ok` })
       },
 
       // 一个只能使用 post 方法访问的接口
-      'post /api/3': {msg: `ok`},
+      'post /api/3': { msg: `ok` },
 
       // // 一个 websocket 接口, 会发送收到的消息
       // 'ws /api/4' (ws, req) {
@@ -62,28 +62,31 @@ module.exports = async util => {
       // },
 
       // 一个下载文件的接口
-      '/file' (req, res) {
+      '/file'(req, res) {
         res.download(__filename, `mm.config.js`)
       },
 
       // 获取动态的接口路径的参数 code
-      '/status/:code' (req, res) {
-        res.json({statusCode: req.params.code})
+      '/status/:code'(req, res) {
+        res.json({ statusCode: req.params.code })
       },
 
       // 使用 mockjs 生成数据
-      '/user' (req, res) {
+      '/user'(req, res) {
         const json = util.libObj.mockjs.mock({
-          'data|3-7': [{
-            userId: `@id`,
-            userName: `@cname`,
-          }],
+          'data|3-7': [
+            {
+              userId: `@id`,
+              userName: `@cname`,
+            },
+          ],
         })
         res.json(json)
       },
     },
     static: [],
-    resHandleReplay: ({req, res}) => wrapApiData({code: 200, data: {}}),
-    resHandleJsonApi: ({req, res: {statusCode: code}, data}) => wrapApiData({code, data}),
+    resHandleReplay: ({ req, res }) => wrapApiData({ code: 200, data: {} }),
+    resHandleJsonApi: ({ req, res: { statusCode: code }, data }) =>
+      wrapApiData({ code, data }),
   }
 }

+ 2 - 2
mm/util.js

@@ -5,7 +5,7 @@
  * @param {number|string} [param0.code=200] - http状态码
  * @returns
  */
-function wrapApiData({data, code = 200}) {
+function wrapApiData({ data, code = 200 }) {
   code = String(code)
   return {
     code,
@@ -16,4 +16,4 @@ function wrapApiData({data, code = 200}) {
 
 module.exports = {
   wrapApiData,
-}
+}

+ 4 - 0
package.json

@@ -7,6 +7,7 @@
     "serve": "vue-cli-service serve",
     "mm": "npx mockm --cwd=mm",
     "build": "vue-cli-service build",
+    "lint-es": "npx eslint **/*.js **/*.vue",
     "lint": "vue-cli-service lint"
   },
   "dependencies": {
@@ -31,6 +32,9 @@
     "sass-loader": "^8.0.2",
     "vue-count-to": "^1.0.13",
     "vue-particles": "^1.0.9",
+    "@vue/eslint-config-prettier": "^6.0.0",
+    "eslint-plugin-prettier": "^3.4.0",
+    "prettier": "^2.2.1",
     "vue-template-compiler": "^2.6.11"
   },
   "eslintConfig": {

+ 7 - 7
vue.config.js

@@ -1,5 +1,5 @@
 module.exports = {
-  publicPath: process.env.NODE_ENV === "production" ? "/vueDataV/" : "/",
+  publicPath: process.env.NODE_ENV === `production` ? `/vueDataV/` : `/`,
   productionSourceMap: false,
   lintOnSave: false,
   devServer: {
@@ -18,9 +18,9 @@ module.exports = {
   configureWebpack: {
     // 把原本需要写在webpack.config.js中的配置代码 写在这里 会自动合并
     externals: {
-     'jquery' : '$',
-     'echarts': 'echarts',
-     'axios' : 'axios'
-    }
-  }
-};
+      jquery: `$`,
+      echarts: `echarts`,
+      axios: `axios`,
+    },
+  },
+}

+ 39 - 1
yarn.lock

@@ -1871,6 +1871,13 @@
   optionalDependencies:
     prettier "^1.18.2 || ^2.0.0"
 
+"@vue/eslint-config-prettier@^6.0.0":
+  version "6.0.0"
+  resolved "https://registry.npmmirror.com/@vue/eslint-config-prettier/-/eslint-config-prettier-6.0.0.tgz#ad5912b308f4ae468458e02a2b05db0b9d246700"
+  integrity sha512-wFQmv45c3ige5EA+ngijq40YpVcIkAy0Lihupnsnd1Dao5CBbPyfCzqtejFLZX1EwH/kCJdpz3t6s+5wd3+KxQ==
+  dependencies:
+    eslint-config-prettier "^6.0.0"
+
 "@vue/preload-webpack-plugin@^1.1.0":
   version "1.1.2"
   resolved "https://registry.npmmirror.com/@vue/preload-webpack-plugin/-/preload-webpack-plugin-1.1.2.tgz#ceb924b4ecb3b9c43871c7a429a02f8423e621ab"
@@ -4424,6 +4431,13 @@ escape-string-regexp@^1.0.2, escape-string-regexp@^1.0.5:
   resolved "https://registry.npmmirror.com/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz#1b61c0562190a8dff6ae3bb2cf0200ca130b86d4"
   integrity sha512-vbRorB5FUQWvla16U8R/qgaFIya2qGzwDrNmCZuYKrbdSUMG6I1ZCGQRefkRVhuOkIGVne7BQ35DSfo1qvJqFg==
 
+eslint-config-prettier@^6.0.0:
+  version "6.15.0"
+  resolved "https://registry.npmmirror.com/eslint-config-prettier/-/eslint-config-prettier-6.15.0.tgz#7f93f6cb7d45a92f1537a70ecc06366e1ac6fed9"
+  integrity sha512-a1+kOYLR8wMGustcgAjdydMsQ2A/2ipRPwRKUmfYaSxc9ZPcrku080Ctl6zrZzZNs/U82MjSv+qKREkoq3bJaw==
+  dependencies:
+    get-stdin "^6.0.0"
+
 eslint-loader@^2.2.1:
   version "2.2.1"
   resolved "https://registry.npmmirror.com/eslint-loader/-/eslint-loader-2.2.1.tgz#28b9c12da54057af0845e2a6112701a2f6bf8337"
@@ -4435,6 +4449,13 @@ eslint-loader@^2.2.1:
     object-hash "^1.1.4"
     rimraf "^2.6.1"
 
+eslint-plugin-prettier@^3.4.0:
+  version "3.4.1"
+  resolved "https://registry.npmmirror.com/eslint-plugin-prettier/-/eslint-plugin-prettier-3.4.1.tgz#e9ddb200efb6f3d05ffe83b1665a716af4a387e5"
+  integrity sha512-htg25EUYUeIhKHXjOinK4BgCcDwtLHjqaxCDsMy5nbnUMkKFvIhMVCp+5GFUXQ4Nr8lBsPqtGAqBenbpFqAA2g==
+  dependencies:
+    prettier-linter-helpers "^1.0.0"
+
 eslint-plugin-vue@^6.2.2:
   version "6.2.2"
   resolved "https://registry.npmmirror.com/eslint-plugin-vue/-/eslint-plugin-vue-6.2.2.tgz#27fecd9a3a24789b0f111ecdd540a9e56198e0fe"
@@ -4774,6 +4795,11 @@ fast-deep-equal@^3.1.1:
   resolved "https://registry.npmmirror.com/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz#3a7d56b559d6cbc3eb512325244e619a65c6c525"
   integrity sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==
 
+fast-diff@^1.1.2:
+  version "1.3.0"
+  resolved "https://registry.npmmirror.com/fast-diff/-/fast-diff-1.3.0.tgz#ece407fa550a64d638536cd727e129c61616e0f0"
+  integrity sha512-VxPP4NqbUjj6MaAOafWeUn2cXWLcCtljklUtZf0Ind4XQ+QPtmA0b18zZy0jIQx+ExRVCR/ZQpBmik5lXshNsw==
+
 fast-glob@^2.2.6:
   version "2.2.7"
   resolved "https://registry.npmmirror.com/fast-glob/-/fast-glob-2.2.7.tgz#6953857c3afa475fff92ee6015d52da70a4cd39d"
@@ -5159,6 +5185,11 @@ get-stdin@^4.0.1:
   resolved "https://registry.npmmirror.com/get-stdin/-/get-stdin-4.0.1.tgz#b968c6b0a04384324902e8bf1a5df32579a450fe"
   integrity sha512-F5aQMywwJ2n85s4hJPTT9RPxGmubonuB10MNYo17/xph174n2MIR33HRguhzVag10O/npM7SPk73LMZNP+FaWw==
 
+get-stdin@^6.0.0:
+  version "6.0.0"
+  resolved "https://registry.npmmirror.com/get-stdin/-/get-stdin-6.0.0.tgz#9e09bf712b360ab9225e812048f71fde9c89657b"
+  integrity sha512-jp4tHawyV7+fkkSKyvjuLZswblUtz+SQKzSWnBbii16BuZksJlU1wuBYXY75r+duh/llF1ur6oNwi+2ZzjKZ7g==
+
 get-stream@^3.0.0:
   version "3.0.0"
   resolved "https://registry.npmmirror.com/get-stream/-/get-stream-3.0.0.tgz#8e943d1358dc37555054ecbe2edb05aa174ede14"
@@ -8460,7 +8491,14 @@ prepend-http@^1.0.0:
   resolved "https://registry.npmmirror.com/prepend-http/-/prepend-http-1.0.4.tgz#d4f4562b0ce3696e41ac52d0e002e57a635dc6dc"
   integrity sha512-PhmXi5XmoyKw1Un4E+opM2KcsJInDvKyuOumcjjw3waw86ZNjHwVUOOWLc4bCzLdcKNaWBH9e99sbWzDQsVaYg==
 
-"prettier@^1.18.2 || ^2.0.0":
+prettier-linter-helpers@^1.0.0:
+  version "1.0.0"
+  resolved "https://registry.npmmirror.com/prettier-linter-helpers/-/prettier-linter-helpers-1.0.0.tgz#d23d41fe1375646de2d0104d3454a3008802cf7b"
+  integrity sha512-GbK2cP9nraSSUF9N2XwUwqfzlAFlMNYYl+ShE/V+H8a9uNl/oUqB1w2EL54Jh0OlyRSd8RfWYJ3coVS4TROP2w==
+  dependencies:
+    fast-diff "^1.1.2"
+
+"prettier@^1.18.2 || ^2.0.0", prettier@^2.2.1:
   version "2.8.8"
   resolved "https://registry.npmmirror.com/prettier/-/prettier-2.8.8.tgz#e8c5d7e98a4305ffe3de2e1fc4aca1a71c28b1da"
   integrity sha512-tdN8qQGvNjw4CHbY+XXk0JgCXn9QiF21a55rBe5LJAU+kDyC4WQn4+awm2Xfk2lQMk5fKup9XgzTZtGkjBdP9Q==