记录:个人习惯的开发工作区配置

160 阅读4分钟

.vscode/settings.json

{
  "editor.formatOnSave": false,
  "javascript.format.enable": false,
  "typescript.format.enable": false,
  "editor.codeActionsOnSave": {
    "source.fixAll": true,
    "source.fixAll.eslint": true,
    "source.fixAll.stylelint": true
  },
  "editor.accessibilitySupport": "off",
  "editor.cursorSmoothCaretAnimation": "on",
  "editor.find.addExtraSpaceOnTop": false,
  "editor.glyphMargin": true,
  "editor.guides.bracketPairs": "active",
  "editor.inlineSuggest.enabled": true,
  "editor.lineNumbers": "interval",
  "editor.multiCursorModifier": "ctrlCmd",
  "editor.renderWhitespace": "boundary",
  "editor.suggestSelection": "first",
  "editor.tabSize": 2,
  "editor.unicodeHighlight.invisibleCharacters": false,
  "workbench.activityBar.visible": true,
  "workbench.editor.closeOnFileDelete": true,
  "workbench.editor.highlightModifiedTabs": true,
  "workbench.fontAliasing": "antialiased",
  "workbench.list.smoothScrolling": true,
  "workbench.productIconTheme": "icons-carbon",
  "workbench.startupEditor": "newUntitledFile",
  "workbench.tree.expandMode": "singleClick",
  "workbench.tree.indent": 10,
  "terminal.integrated.cursorBlinking": true,
  "terminal.integrated.cursorStyle": "line",
  "terminal.integrated.fontWeight": "300",
  "terminal.integrated.persistentSessionReviveProcess": "never",
  "terminal.integrated.tabs.enabled": true,
  "git.autofetch": true,
  "git.confirmSync": false,
  "git.enableSmartCommit": true,
  "git.untrackedChanges": "separate",
  "extensions.autoUpdate": "onlyEnabledExtensions",
  "extensions.ignoreRecommendations": true,
  "files.eol": "\n",
  "files.insertFinalNewline": true,
  "files.simpleDialog.enable": true,
  "eslint.format.enable": true,
  "eslint.quiet": true,
  "errorLens.enabledDiagnosticLevels": [
    "warning",
    "error"
  ],
  "errorLens.excludeBySource": [
    "cSpell",
    "Grammarly",
    "eslint"
  ],
  "search.exclude": {
    "**/.git": true,
    "**/.github": true,
    "**/.nuxt": true,
    "**/.output": true,
    "**/.pnpm": true,
    "**/.vscode": true,
    "**/.yarn": true,
    "**/bower_components": true,
    "**/dist/**": true,
    "**/logs": true,
    "**/node_modules": true,
    "**/out/**": true,
    "**/package-lock.json": true,
    "**/pnpm-lock.yaml": true,
    "**/tmp": true,
    "**/yarn.lock": true
  },
  "javascript.validate.enable": false,
  "eslint.validate": [
    "html",
    "javascript",
    "typescript",
    "javascriptreact",
    "typescriptreact",
    "vue"
  ],
  "stylelint.validate": [
    "vue",
    "scss",
    "css"
  ],
  "emmet.showSuggestionsAsSnippets": true,
  "emmet.triggerExpansionOnTab": true,
  "files.associations": {
    ".env.*": "dotenv"
  },
  "cSpell.allowCompoundWords": true,
  "cSpell.language": "en,en-US",
  "volar.autoCompleteRefs": false,
  "volar.codeLens.pugTools": false,
  "volar.codeLens.scriptSetupTools": true,
  "volar.completion.preferredTagNameCase": "pascal",
  "volar.showWelcomePage": false,
  "explorer.confirmDelete": false,
  "explorer.confirmDragAndDrop": false,
  "explorer.fileNesting.enabled": true,
  "explorer.fileNesting.expand": false,
  "explorer.fileNesting.patterns": {
    "package.json": ".browserslist*, .circleci*, .codecov, .commitlint*, .cz-config.js, .czrc, .editorconfig, .eslint*, .firebase*, .flowconfig, .github*, .gitlab*, .gitpod*, .huskyrc*, .jslint*, .lighthouserc.*, .lintstagedrc*, .markdownlint*, .mocha*, .node-version, .nodemon*, .npm*, .nvmrc, .pm2*, .pnp.*, .pnpm*, .prettier*, .releaserc*, .sentry*, .stackblitz*, .styleci*, .stylelint*, .tazerc*, .textlint*, .tool-versions, .travis*, .versionrc*, .vscode*, .watchman*, .xo-config*, .yamllint*, .yarnrc*, Procfile, api-extractor.json, apollo.config.*, appveyor*, ava.config.*, azure-pipelines*, bower.json, build.config.*, commitlint*, crowdin*, cypress.json, dangerfile*, dprint.json, firebase.json, grunt*, gulp*, jasmine.*, jenkins*, jest.config.*, jsconfig.*, karma*, lerna*, lighthouserc.*, lint-staged*, nest-cli.*, netlify*, nodemon*, nx.*, package-lock.json, phpcs.xml, playwright.config.*, pm2.*, pnpm*, prettier*, pullapprove*, puppeteer.config.*, pyrightconfig.json, renovate*, rollup.config.*, stylelint*, tsconfig.*, tsdoc.*, tslint*, tsup.config.*, turbo*, typedoc*, vercel*, vetur.config.*, vitest.config.*, webpack*, workspace.json, xo.config.*, yarn*, settings.xml",
    "shims.d.ts": "*.d.ts",
    "vite.config.ts": "vite.config.*.ts, *.env, .babelrc*, .codecov, .cssnanorc*, .env.*, .envrc, .htmlnanorc*, .lighthouserc.*, .mocha*, .postcssrc*, .terserrc*, api-extractor.json, ava.config.*, babel.config.*, cssnano.config.*, cypress.json, env.d.ts, htmlnanorc.*, jasmine.*, jest.config.*, jsconfig.*, karma*, lighthouserc.*, playwright.config.*, postcss.config.*, puppeteer.config.*, svgo.config.*, tailwind.config.*, tsdoc.*, unocss.config.*, vitest.config.*, webpack.config.*, windi.config.*, axios.config.*, build.info.*",
  }
}

.editorconfig

[*.{js,jsx,ts,tsx,vue}]
indent_style = space
indent_size = 2
trim_trailing_whitespace = true
insert_final_newline = true

eslintrc.cjs

/* eslint-env node */
require('@rushstack/eslint-patch/modern-module-resolution')

/* eslint-disable id-length */
module.exports = {
  root: true,
  extends: [
    'plugin:vue/vue3-essential',
    'plugin:vue/vue3-recommended',
    'eslint:recommended',
    'plugin:import/recommended',
    'plugin:import/typescript',
    '@vue/eslint-config-typescript/recommended',
  ],
  env: {
    'vue/setup-compiler-macros': true,
  },
  rules: {
    'new-cap': ['error', {
      newIsCap: true,
      capIsNew: false,
    }],
    'id-length': ['error', { max: 25, min: 1 }],
    camelcase: ['error', {
      allow: ['^UNSAFE_'],
      properties: 'never',
      ignoreGlobals: true,
    }],
    'quote-props': ['warn', 'as-needed'],
    'line-comment-position': 'error',
    'lines-around-comment': 'error',
    'spaced-comment': ['error', 'always', {
      exceptions: ['*'],
    }],
    'function-paren-newline': [
      'error',
      'multiline',
    ],
    'object-property-newline': ['error', {
      allowAllPropertiesOnSameLine: true,
    }],
    'newline-per-chained-call': ['error', {
      ignoreChainWithDepth: 4,
    }],
    'brace-style': 'error',
    'operator-linebreak': ['error', 'before'],
    'padding-line-between-statements': ['error',
      { blankLine: 'always', prev: ['export', 'cjs-export'], next: '*' },
      { blankLine: 'any', prev: ['export', 'cjs-export'], next: ['export', 'cjs-export'] },
      { blankLine: 'always', prev: ['import', 'cjs-import'], next: '*' },
      { blankLine: 'any', prev: ['import', 'cjs-import'], next: ['import', 'cjs-import'] },
      { blankLine: 'always', prev: ['var', 'const', 'let'], next: '*' },
      { blankLine: 'any', prev: ['const', 'let', 'var'], next: ['const', 'let', 'var'] },
    ],
    'space-before-blocks': ['error', 'always'],
    'space-before-function-paren': ['off'],
    'space-in-parens': ['error', 'never'],
    'space-infix-ops': ['error', { int32Hint: false }],
    'space-unary-ops': ['error', { words: true, nonwords: false }],
    'no-multi-spaces': 'error',
    'semi-spacing': 'error',
    curly: 'error',
    'comma-dangle': ['error', 'always-multiline'],
    'comma-spacing': ['error'],
    semi: ['error', 'never'],
    'max-lines': ['error', 1000],
    'max-len': ['error', {
      code: 120,
      tabWidth: 2,
      ignoreComments: true,
      ignoreUrls: true,
      ignoreTemplateLiterals: true,
    }],
    'max-lines-per-function': ['error', {
      max: 50,
      skipBlankLines: true,
      skipComments: true,
    }],
    complexity: ['error', 15],
    'max-depth': ['error', 4],
    'max-nested-callbacks': ['error', 4],
    'no-var': ['error'],
    'prefer-const': ['error'],
    'one-var-declaration-per-line': ['error', 'always'],
    'one-var': ['error', 'never'],
    'no-multi-assign': ['error'],
    'no-undef-init': ['error'],
    'no-shadow': ['error'],
    'max-params': ['error', 5],
    'default-param-last': ['error'],
    'no-param-reassign': ['error'],
    'arrow-body-style': ['error', 'as-needed'],
    'no-caller': ['error'],
    'prefer-rest-params': ['error'],
    'prefer-destructuring': ['error', {
      array: true,
      object: true,
    }],
    'no-this-before-super': ['error'],
    'jsx-quotes': ['error', 'prefer-double'],
    quotes: ['error', 'single'],
    'prefer-template': ['error'],
    'no-useless-concat': ['error'],
    'accessor-pairs': ['error'],
    'object-shorthand': ['error', 'always'],
    'no-prototype-builtins': ['error'],
    'no-extend-native': ['error'],
    eqeqeq: ['error', 'always'],
    'no-nested-ternary': ['error'],
    'no-negated-condition': ['error'],
    'no-mixed-operators': ['error'],
    'default-case': ['error'],
    'no-fallthrough': ['error'],
    'no-regex-spaces': ['error'],
    'prefer-named-capture-group': ['error'],
    'no-duplicate-imports': ['error'],
    'import/order': ['error', {
      pathGroups: [
        { pattern: '@/**', group: 'internal', position: 'after' },
      ],
    }],
    'import/extensions': 'off',
    'import/prefer-default-export': 'off',
    'import/no-mutable-exports': ['error'],
    'import/no-unresolved': 'off',
    'no-floating-decimal': ['error'],
    'use-isnan': ['error'],
    'no-unsafe-finally': ['error'],
    'prefer-promise-reject-errors': ['error'],
    'no-return-await': ['error'],
    'no-implied-eval': ['error'],
    'no-eval': ['error'],
    'no-with': ['error'],
    'no-continue': ['error'],
    'no-alert': ['error'],
    'no-implicit-coercion': ['error'],
    'no-useless-return': ['error'],
    'dot-notation': ['error'],

    /**
     * part-of eslint-config-standard
     * @wework/eslint-config-standard
     */
    'array-bracket-spacing': ['error', 'never', {
      singleValue: false,
      arraysInArrays: false,
      objectsInArrays: false,
    }],
    'array-callback-return': ['error', {
      checkForEach: false,
    }],
    'arrow-spacing': ['error'],
    'block-spacing': ['error'],
    'no-unused-vars': ['error'],
    'eol-last': ['error', 'always'],
    'no-multiple-empty-lines': [
      'error', { max: 1, maxEOF: 1 },
    ],
    'no-trailing-spaces': ['error'],
    'dot-location': ['error', 'property'],
    'func-call-spacing': 'off',
    'key-spacing': ['error', {
      beforeColon: false,
    }],
    'keyword-spacing': ['error'],
    'lines-between-class-members': ['error', 'always', { exceptAfterSingleLine: true }],
    'no-async-promise-executor': ['error'],
    'no-case-declarations': ['error'],
    'no-class-assign': ['error'],
    'no-cond-assign': 'error',
    'no-constant-condition': ['error', { checkLoops: false }],
    'import/no-duplicates': 'error',
    'valid-typeof': ['error', { requireStringLiterals: true }],
    'object-curly-spacing': ['error', 'always'],

    /**
     * Vue 3 UnCategorized Rules
     * @wework/eslint-config-vue
     */
    'vue/component-name-in-template-casing': ['error', 'PascalCase', {
      registeredComponentsOnly: false,
    }],
    'vue/component-options-name-casing': ['error', 'PascalCase'],
    'vue/custom-event-name-casing': ['error',
      'kebab-case', {
        ignores: [],
      },
    ],
    'vue/html-comment-content-spacing': ['error',
      'always', {
        exceptions: [],
      },
    ],
    'vue/html-comment-indent': ['error', 2],
    'vue/match-component-file-name': ['error', {
      extensions: ['jsx'],
      shouldMatchCase: false,
    }],
    'vue/no-empty-component-block': ['error'],
    'vue/no-reserved-component-names': ['error'],
    'vue/no-useless-mustaches': ['error'],
    'vue/no-useless-v-bind': ['error'],
    'vue/padding-line-between-blocks': ['error'],
    // Vue 3 Only
    'vue/prefer-import-from-vue': ['warn'],
    'vue/require-emit-validator': ['error'],
    'vue/v-on-function-call': ['error',
      'never', {
        ignoreIncludesComment: false,
      },
    ],
    'vue/max-attributes-per-line': ['warn', {
      singleline: { max: 4 },
      multiline: { max: 1 },
    }],
    'vue/multi-word-component-names': ['error', {
      ignores: ['index'],
    }],
    'vue/no-static-inline-styles': ['error', {
      allowBinding: false,
    }],
    'vue/space-unary-ops': ['error', { words: true, nonwords: false }],
    'vue/space-in-parens': ['error', 'never'],
    'vue/space-infix-ops': ['error', { int32Hint: false }],

    /**
     * ESLint TypeScript
     */
    indent: 'off',
    '@typescript-eslint/indent': ['error', 2],
    '@typescript-eslint/func-call-spacing': ['error', 'never'],
    '@typescript-eslint/space-infix-ops': ['error', { int32Hint: false }],
    '@typescript-eslint/type-annotation-spacing': ['error', {
      before: false,
      after: true,
      overrides: {
        arrow: {
          before: true,
        },
      },
    }],
    '@typescript-eslint/naming-convention': [
      'error',
      {
        selector: ['interface', 'typeAlias', 'enum'],
        format: ['PascalCase'],
      },
    ],
    '@typescript-eslint/no-explicit-any': ['warn'],

    /**
     * 个性化配置
     */
    'no-warning-comments': 'warn',
    'no-debugger': 'warn',
    'no-console': 'warn',
  },
}

.stylelintrc.js

/* eslint-env node */
module.exports = {
  root: true,
  extends: [
    'stylelint-config-standard-scss',
    'stylelint-config-standard-vue/scss',
    'stylelint-config-recess-order',
  ],
  rules: {
    'selector-class-pattern': [
      '^[a-z]+[a-z\\d-_]*[a-z]+$', {
        message: 'invalid selector class',
      },
    ],
    indentation: 2,
    'no-empty-source': null,
    'selector-list-comma-newline-after': 'always-multi-line',
    'selector-list-comma-space-after': 'always-single-line',
  },
}

.commitlint.config.js

/* eslint-env node */
module.exports = {
  extends: [
    '@commitlint/config-conventional',
  ],
  parserPreset: {
    parserOpts: {
      // issue 前缀,自动识别 #1234 为 issue,可在 commit message 中写入关闭的问题 id
      issuePrefixes: ['#'],
    },
  },
  rules: {
    'header-max-length': [0, 'always', 100],
    'type-enum': [
      2,
      'always',
      [
        // feature 新功能,新需求
        'feat',
          
        // 修复 bug
        'fix',
          
        // 仅仅修改了文档,比如README, CHANGELOG, CONTRIBUTE等等
        'docs',
          
        // 仅仅修改了空格、格式缩进、逗号等等,不改变代码逻辑
        'style',
          
        // 代码重构,没有加新功能或者修复bug
        'refactor',
          
        // 测试用例,包括单元测试、集成测试等
        'test',
          
        // 回滚到上一个版本
        'revert',
          
        // 性能优化
        'perf',
          
        // 解决合并过程中的冲突
        'conflict',
          
        // ci/cd 配置文件修改
        'ci',
          
        // 杂项,不属于以上范围的修改
        'chore',
      ],
    ],
  },
}