From af8f0487cb70c3134919dd8b9f4f7cbe0103b144 Mon Sep 17 00:00:00 2001 From: woody Date: Fri, 23 May 2025 17:38:55 +0800 Subject: [PATCH] chore(lint): add lint --- .editorconfig | 12 ++++++++++++ .eslintrc.js | 39 +++++++++++++++++++++++++++++++++++++++ .vscode/settings.json | 24 ++++++++++++++++++++++++ 3 files changed, 75 insertions(+) create mode 100644 .editorconfig create mode 100644 .eslintrc.js create mode 100644 .vscode/settings.json diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..4a7ea30 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,12 @@ +root = true + +[*] +indent_style = space +indent_size = 2 +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true + +[*.md] +trim_trailing_whitespace = false diff --git a/.eslintrc.js b/.eslintrc.js new file mode 100644 index 0000000..e291e76 --- /dev/null +++ b/.eslintrc.js @@ -0,0 +1,39 @@ +module.exports = { + env: { + browser: true, + es2021: true, + node: true, + }, + extends: ['eslint:recommended', '@vue/eslint-config-prettier'], + parserOptions: { + ecmaVersion: 2021, + sourceType: 'module', + }, + globals: { + uni: 'readonly', + wx: 'readonly', + plus: 'readonly', + getCurrentPages: 'readonly', + getApp: 'readonly', + }, + rules: { + // Vue规则 + 'vue/multi-word-component-names': 'off', + 'vue/no-unused-vars': 'error', + 'vue/valid-v-for': 'error', + 'vue/require-v-for-key': 'error', + 'vue/no-deprecated-filter': 'error', + + // JavaScript规则 + 'no-unused-vars': 'warn', + 'no-console': process.env.NODE_ENV === 'production' ? 'warn' : 'off', + 'no-debugger': process.env.NODE_ENV === 'production' ? 'warn' : 'off', + + // 代码风格 + semi: ['error', 'never'], + quotes: ['error', 'single'], + 'comma-dangle': ['error', 'only-multiline'], + indent: ['error', 2], + 'eol-last': ['error', 'always'], + }, +} diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..f8fa38c --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,24 @@ +{ + "editor.formatOnSave": true, + "editor.codeActionsOnSave": { + "source.fixAll.eslint": true, + "source.organizeImports": true + }, + "editor.defaultFormatter": "esbenp.prettier-vscode", + "[vue]": { + "editor.defaultFormatter": "esbenp.prettier-vscode" + }, + "[javascript]": { + "editor.defaultFormatter": "esbenp.prettier-vscode" + }, + "[json]": { + "editor.defaultFormatter": "esbenp.prettier-vscode" + }, + "eslint.validate": ["javascript", "vue"], + "prettier.requireConfig": true, + "editor.tabSize": 2, + "editor.insertSpaces": true, + "files.eol": "\n", + "files.insertFinalNewline": true, + "files.trimTrailingWhitespace": true +}