ZaiZai 2 rokov pred
rodič
commit
9390a47817
5 zmenil súbory, kde vykonal 244 pridanie a 2 odobranie
  1. 10 0
      .eslintignore
  2. 193 0
      .eslintrc.cjs
  3. 35 0
      README.md
  4. 5 1
      package.json
  5. 1 1
      public/version.json

+ 10 - 0
.eslintignore

@@ -0,0 +1,10 @@
+node_modules
+dist
+public
+scripts
+zip
+assets
+styles
+README.md
+yarn.lock
+!.*

+ 193 - 0
.eslintrc.cjs

@@ -0,0 +1,193 @@
+/* eslint-env node */
+module.exports = {
+    root: true,
+    env: {
+        browser: true,
+        es2021: true,
+        node: true,
+    },
+    parser: "vue-eslint-parser",
+    extends: [
+        "plugin:vue/vue3-recommended",
+        'eslint:recommended'
+    ],
+    parserOptions: {
+        ecmaVersion: "latest",
+        sourceType: "module",
+    },
+    globals: {},
+    plugins: ['vue'],
+    rules: {
+        // Common
+        'semi': ['error', 'never'],
+        'curly': 'off',
+        'quotes': ['error', 'single'],
+        'quote-props': ['error', 'consistent-as-needed'],
+        'no-console': 'off',
+
+        // best-practice
+        'array-callback-return': 'error',
+        'block-scoped-var': 'error',
+        'consistent-return': 'off',
+        'complexity': 'off',
+        'eqeqeq': ['error', 'smart'],
+        'no-alert': 'warn',
+        'no-case-declarations': 'error',
+        'no-multi-spaces': 'error',
+        'no-multi-str': 'error',
+        'no-with': 'error',
+        'no-void': 'error',
+        'no-useless-escape': 'off',
+        'vars-on-top': 'error',
+        'require-await': 'off',
+        'no-return-assign': 'off',
+        'operator-linebreak': ['error', 'before'],
+        'max-statements-per-line': ['error', {
+            max: 1
+        }],
+
+        'sort-imports': [
+            'error',
+            {
+                ignoreCase: false,
+                ignoreDeclarationSort: true,
+                ignoreMemberSort: false,
+                memberSyntaxSortOrder: ['none', 'all', 'multiple', 'single'],
+                allowSeparatedGroups: false,
+            },
+        ],
+
+        // typescript
+        'import/named': 'off',
+
+        // Override JS
+        'no-useless-constructor': 'off',
+        'indent': 'off',
+        'no-invalid-this': 'off',
+        'no-redeclare': 'off',
+        "no-use-before-define": 'off',
+        'brace-style': 'error',
+        'comma-dangle': ['error', 'always-multiline'],
+        'object-curly-spacing': ['error', 'always'],
+        'space-before-blocks': ['error', 'always'],
+        'space-before-function-paren': [
+            'error',
+            {
+                anonymous: 'always',
+                named: 'never',
+                asyncArrow: 'always',
+            },
+        ],
+        'space-infix-ops': 'error',
+        'keyword-spacing': ['error', {
+            before: true,
+            after: true
+        }],
+        'comma-spacing': ['error', {
+            before: false,
+            after: true
+        }],
+        'no-extra-parens': ['error', 'functions'],
+        'no-dupe-class-members': 'error',
+        'no-loss-of-precision': 'error',
+        'lines-between-class-members': ['error', 'always', {
+            exceptAfterSingleLine: true
+        }],
+
+        // vue
+        "vue/html-indent": ["error", 4],
+        'vue/max-attributes-per-line': 'off',
+        'vue/no-v-html': 'off',
+        'vue/require-prop-types': 'off',
+        'vue/require-default-prop': 'off',
+        'vue/multi-word-component-names': 'off',
+        'vue/prefer-import-from-vue': 'off',
+        'vue/no-v-text-v-html-on-component': 'off',
+        'vue/no-dupe-keys': 'off',
+
+        // reactivity transform
+        'vue/no-setup-props-destructure': 'off',
+
+        'vue/component-tags-order': ['error', {
+            order: ['template', 'script', 'style'],
+        }],
+        'vue/block-tag-newline': ['error', {
+            singleline: 'always',
+            multiline: 'always',
+        }],
+        'vue/component-name-in-template-casing': ['error', 'PascalCase' || 'kebab-case'],
+        'vue/component-options-name-casing': ['error', 'PascalCase'],
+        'vue/custom-event-name-casing': ['error', 'camelCase'],
+        'vue/define-macros-order': ['error', {
+            order: ['defineProps', 'defineEmits'],
+        }],
+        'vue/html-comment-content-spacing': ['error', 'always', {
+            exceptions: ['-'],
+        }],
+        'vue/no-restricted-v-bind': ['error', '/^v-/'],
+        'vue/no-useless-v-bind': 'error',
+        'vue/no-unused-refs': 'error',
+        'vue/padding-line-between-blocks': ['error', 'always'],
+        'vue/prefer-separate-static-class': 'error',
+
+        // extensions
+        'vue/array-bracket-spacing': ['error', 'never'],
+        'vue/arrow-spacing': ['error', {
+            before: true,
+            after: true
+        }],
+        'vue/block-spacing': ['error', 'always'],
+        'vue/brace-style': ['error', 'stroustrup', {
+            allowSingleLine: true
+        }],
+        'vue/comma-dangle': ['error', 'always-multiline'],
+        'vue/comma-spacing': ['error', {
+            before: false,
+            after: true
+        }],
+        'vue/comma-style': ['error', 'last'],
+        'vue/dot-location': ['error', 'property'],
+        'vue/dot-notation': ['error', {
+            allowKeywords: true
+        }],
+        'vue/eqeqeq': ['error', 'smart'],
+        // 'vue/func-call-spacing': ['off', 'never'],
+        'vue/key-spacing': ['error', {
+            beforeColon: false,
+            afterColon: true
+        }],
+        'vue/keyword-spacing': ['error', {
+            before: true,
+            after: true
+        }],
+        'vue/no-constant-condition': 'warn',
+        'vue/no-empty-pattern': 'error',
+        'vue/no-extra-parens': ['error', 'functions'],
+        'vue/no-irregular-whitespace': 'error',
+        'vue/no-loss-of-precision': 'error',
+        'vue/no-restricted-syntax': ['error', 'DebuggerStatement', 'LabeledStatement', 'WithStatement'],
+        'vue/no-sparse-arrays': 'error',
+        'vue/object-curly-newline': ['error', {
+            multiline: true,
+            consistent: true
+        }],
+        'vue/object-curly-spacing': ['error', 'always'],
+        'vue/object-property-newline': ['error', {
+            allowMultiplePropertiesPerLine: true
+        }],
+        'vue/object-shorthand': ['error', 'always', {
+            ignoreConstructors: false,
+            avoidQuotes: true,
+        }],
+        'vue/operator-linebreak': ['error', 'before'],
+        'vue/prefer-template': 'error',
+        'vue/quote-props': ['error', 'consistent-as-needed'],
+        'vue/space-in-parens': ['error', 'never'],
+        'vue/space-infix-ops': 'error',
+        'vue/space-unary-ops': ['error', {
+            words: true,
+            nonwords: false
+        }],
+        'vue/template-curly-spacing': 'error',
+    },
+};

+ 35 - 0
README.md

@@ -62,6 +62,7 @@ js-fast-way 文档
 - **[文档地址](https://js-fast-way.vercel.app/)**
 - **[国内文档地址](http://izaizaiaa.gitee.io/js-fast-way)**
 
+
 ---
 
 ### 打包说明
@@ -72,6 +73,7 @@ js-fast-way 文档
 `build:test` 为一键打包,然后自动上传到测试服务器上并自动部署的方式
 `build:test:wgt` 为一键打包,然后自动上传到测试服务器上并自动部署的方式(不包含 `/public/plugins` 文件夹)
 
+
 ### 其它说明
 
 一般来说,`/public/plugins` 很少出现变动的情况。
@@ -80,3 +82,36 @@ js-fast-way 文档
 
 如果本地 `/public/plugins` 文件夹 有变动,请使用 非 `wgt` 的打包方式
 
+---
+
+### 代码规范说明
+
+项目启用了 `eslint` 作为代码规范检测
+
+在 `vscode` 中,需要安装 `eslint` 插件,并且在 `settings.json` 中添加以下配置
+
+```json
+{
+    "eslint.autoFixOnSave": true,
+    "eslint.validate": [
+        "javascript",
+        "javascriptreact",
+        {
+            "language": "html",
+            "autoFix": true
+        },
+        {
+            "language": "vue",
+            "autoFix": true
+        }
+    ],
+    "editor.codeActionsOnSave": {
+        "source.fixAll.eslint": true
+    }
+}
+```
+
+这时,在保存代码时,会自动格式化和处理掉一些不规范的代码,但这并不是准确的,保存后,请再检查下,是否有存在不合理的地方,进行手动优化。
+
+在 `webstorm` 中,不需要安装插件,打开 webstorm 设置,语言和框架,`eslint`,勾选自动,再勾选保存时运行,即可。
+

+ 5 - 1
package.json

@@ -8,7 +8,9 @@
         "build:zip": "sh ./scripts/build.sh all",
         "build:zip:wgt": "sh ./scripts/build.sh wgt",
         "build:test": "sh ./scripts/build.sh all test",
-        "build:test:wgt": "sh ./scripts/build.sh wgt test"
+        "build:test:wgt": "sh ./scripts/build.sh wgt test",
+        "lint": "eslint --ext .js,.vue src",
+        "lint:fix": "eslint . --fix"
     },
     "dependencies": {
         "axios": "^1.4.0",
@@ -33,6 +35,8 @@
         "archiver": "^5.3.1",
         "autoprefixer": "^10.4.14",
         "cssnano": "^6.0.1",
+        "eslint": "^8.44.0",
+        "eslint-plugin-vue": "^9.15.1",
         "postcss": "^8.4.24",
         "sass": "^1.63.6",
         "tailwindcss": "3.3.2",

+ 1 - 1
public/version.json

@@ -1,3 +1,3 @@
 {
-  "value": "20230706140907"
+  "value": "20230706141253"
 }