Sfoglia il codice sorgente

增加 eslint 校验功能。

sybotan 4 anni fa
parent
commit
b1255cef9c
3 ha cambiato i file con 77 aggiunte e 1 eliminazioni
  1. 9 0
      .editorconfig
  2. 61 0
      .eslintrc.js
  3. 7 1
      package.json

+ 9 - 0
.editorconfig

@@ -0,0 +1,9 @@
+root = true
+
+[*]
+charset = utf-8
+indent_style = space
+indent_size = 4
+end_of_line =lf
+insert_final_newline = true
+trim_trailing_whitespace = true

+ 61 - 0
.eslintrc.js

@@ -0,0 +1,61 @@
+/*
+ * ********************************************************************************************************************
+ *
+ *               iFHS7.
+ *              ;BBMBMBMc                  rZMBMBR              BMB
+ *              MBEr:;PBM,               7MBMMEOBB:             BBB                       RBW
+ *     XK:      BO     SB.     :SZ       MBM.       c;;     ir  BBM :FFr       :SSF:    ;xBMB:r   iuGXv.    i:. iF2;
+ *     DBBM0r.  :D     S7   ;XMBMB       GMBMu.     MBM:   BMB  MBMBBBMBMS   WMBMBMBBK  MBMBMBM  BMBRBMBW  .MBMBMBMBB
+ *      :JMRMMD  ..    ,  1MMRM1;         ;MBMBBR:   MBM  ;MB:  BMB:   MBM. RMBr   sBMH   BM0         UMB,  BMB.  KMBv
+ *     ;.   XOW  B1; :uM: 1RE,   i           .2BMBs  rMB. MBO   MBO    JMB; MBB     MBM   BBS    7MBMBOBM:  MBW   :BMc
+ *     OBRJ.SEE  MRDOWOR, 3DE:7OBM       .     ;BMB   RMR7BM    BMB    MBB. BMB    ,BMR  .BBZ   MMB   rMB,  BMM   rMB7
+ *     :FBRO0D0  RKXSXPR. JOKOOMPi       BMBSSWBMB;    BMBB:    MBMB0ZMBMS  .BMBOXRBMB    MBMDE RBM2;SMBM;  MBB   xBM2
+ *         iZGE  O0SHSPO. uGZ7.          sBMBMBDL      :BMO     OZu:BMBK,     rRBMB0;     ,EBMB  xBMBr:ER.  RDU   :OO;
+ *     ,BZ, 1D0  RPSFHXR. xWZ .SMr                  . .BBB
+ *      :0BMRDG  RESSSKR. 2WOMBW;                   BMBMR
+ *         i0BM: SWKHKGO  MBDv
+ *           .UB  OOGDM. MK,                                          Copyright (c) 2015-2020.  斯伯坦机器人
+ *              ,  XMW  ..
+ *                  r                                                                     All rights reserved.
+ *
+ * ********************************************************************************************************************
+ */
+
+module.exports = {
+    root: true,
+    parser: "@typescript-eslint/parser",
+    extends: [
+        "plugin:@typescript-eslint/recommended",
+        "prettier/@typescript-eslint",
+        "plugin:prettier/recommended", // 此行必须在最后
+    ],
+    env: {
+        es6: true,
+        node: true,
+    },
+    parserOptions: {
+        // 支持最新 JavaScript
+        ecmaVersion: 2018,
+        sourceType: "module",
+    },
+    rules: {
+        // 文件
+        "max-classes-per-file": ["error", 1], // 一个文件中只能定义一个类
+        "max-lines-per-function": ["error", 200], // 一个函数最多200行代码
+        "max-statements-per-line": ["error", { max: 1 }], // 一行只允许有一条语句
+        // 缩进
+        indent: ["error", 4], // 缩进控制4空格
+        "max-len": ["error", 120], // 每行字符不超过120
+        "no-mixed-spaces-and-tabs": "error", // 禁止使用空格和tab混合缩进
+        // 类型检查
+        "@typescript-eslint/no-explicit-any": ["off"], // 取消 any 类型检查
+        "@typescript-eslint/no-unused-vars": ["off"],
+        // 语句
+        curly: ["error", "multi-line"], // if、else if、else、for、while强制使用大括号,但允许在单行中省略大括号。
+        semi: ["error", "always"], // 不得省略语句结束的分号
+        "@typescript-eslint/explicit-member-accessibility": [
+            "error",
+            { accessibility: "no-public" },
+        ], // public访问不需加访问修饰符
+    },
+};

+ 7 - 1
package.json

@@ -9,7 +9,8 @@
   "scripts": {
     "dev": "vuepress dev docs",
     "build": "vuepress build docs",
-    "publish": "node publish.js"
+    "publish": "node publish.js",
+    "lint": "eslint docs/**/*.{js,ts,tsx}"
   },
   "dependencies": {
     "@persagy-web/base": "2.2.1",
@@ -24,6 +25,11 @@
     "vue-class-component": "^7.0.2"
   },
   "devDependencies": {
+    "@typescript-eslint/eslint-plugin": "^2.33.0",
+    "@typescript-eslint/parser": "^2.33.0",
+    "eslint": "^7.0.0",
+    "eslint-config-prettier": "^6.11.0",
+    "eslint-plugin-prettier": "^3.1.3",
     "@types/uuid": "^8.0.0",
     "@vue/cli-plugin-babel": "^3.9.0",
     "@vue/cli-plugin-typescript": "^3.9.0",