首页 > 技术文章 > 自己的eslint

jackzhoumine 2020-08-13 04:59 原文

/*
* "eslint": "^7.6.0",
  "eslint-plugin-vue": "^6.2.2",
  "babel-eslint": "^10.1.0",
*/
module.exports = {
  env: {
    browser: true,
    es6: true,
    node: true
  },
  extends: [
    'eslint:recommended',
    'plugin:vue/essential'
  ],
  plugins: [
    'vue'
  ],
  globals: {
    Atomics: 'readonly',
    SharedArrayBuffer: 'readonly'
  },
  // NOTE 异步加载路由报错:Parsing error: Unexpected token import
  parser: 'vue-eslint-parser',
  parserOptions: {
    parser: 'babel-eslint',
    ecmaVersion: '2018',
    sourceType: 'module'
  },
  rules: {
    quotes: [2, 'single', { 'allowTemplateLiterals': true }],
    semi: [2, 'never'],
    // 强制在关键字前后使用一致的空格 (前后腰需要)
    'keyword-spacing': 2,
    // 强制一行的最大长度 
    'max-len': [1, 100],
    // 使用 === 替代 == allow-null允许null和undefined==
    'eqeqeq': [2, 'allow-null'],
    // 禁止将变量初始化为 undefined 
    'no-undef-init': 2,
    // 禁止将 undefined 作为标识符 
    'no-undefined': 0,
    // 禁止出现未使用过的变量
    'no-unused-vars': [2, { 'vars': 'all', 'args': 'none' }],
    // 要求使用 const 声明那些声明后不再被修改的变量 
    'no-var': 2,
    'prefer-const': 2,
    'spaced-comment': [2, 'always'],
    'vue/multiline-html-element-content-newline': 0,
    'vue/max-attributes-per-line': [2, {
      'singleline': 4,
      'multiline': {
        'max': 4,
        'allowFirstLine': true
      }
    }],
    'vue/html-indent': [2, 'tab', {
      'attribute': 4,
      'baseIndent': 1,
      'closeBracket': 0,
      'alignAttributesVertically': true,
      'ignores': []
    }],
    // https://eslint.vuejs.org/rules/attributes-order.html
    'vue/attributes-order': [2, {
      'order': [
        'DEFINITION',
        'LIST_RENDERING',
        'CONDITIONALS',
        'RENDER_MODIFIERS',
        'GLOBAL',
        'UNIQUE',
        'TWO_WAY_BINDING',
        'OTHER_DIRECTIVES',
        'OTHER_ATTR',
        'EVENTS',
        'CONTENT'
      ],
      'alphabetical': false
    }]
  }
}

公司不配置,发布在此,自己去公司复制。
扩展配置

{
 "workbench.colorTheme": "Visual Studio Dark",
  "editor.fontSize": 18,
  "terminal.integrated.shell.windows": "C:\\Program Files\\Git\\bin\\bash.exe",
  // # 每次保存的时候自动格式化
  "editor.formatOnSave": false,
  // #每次保存的时候将代码按 eslint 格式进行修复
  // 添加 vue 支持
  "eslint.validate": [
    "javascript",
    "javascriptreact",
    "vue"
  ],
  "editor.codeActionsOnSave": {
    "source.fixAll.eslint": true,
    "source.fixAll.tslint": true
  },
  "vetur.format.defaultFormatter.js": "none",
  "vetur.format.defaultFormatterOptions": {
    "js-beautify-html": {
      "wrap_attributes": "force-aligned", //"auto""
      // #vue 组件中html代码格式化样式
      "wrap_line_length": 120,
      "end_with_newline": false
    }
  },
     "todo-tree.general.tags": [
    "TODO", // TODO 待办
    "FIXME", // FIXME 待完善,没有明显的 bug, 代码可工作,可能不够优雅、不易理解
    "BUG", // BUG  代码
    "NOTE" // NOTE 复杂逻辑的关键处、易错额外说明
  ],
  "todo-tree.tree.showInExplorer": true,
  "todo-tree.highlights.defaultHighlight": {
    // 默认 tag 设置
    "background": "#f9f9fb", //"peekViewResult.background", // 使用 // "yellow", // 标记的背景色
    "foreground": "yellow", // 标记前景色 (文字颜色)
    "icon": "check", // 使用的图标
    "rulerColour": "yellow", // 在右侧快速预览的颜色
    "type": "tag", // 在文件中如何高亮  tag:只高亮标签  text:标签和后面的文字  tag-and-comment:高亮注释和标签  text-and-comment:标签 文字和注释  line:标记的一行  whole-line:
    "iconColour": "#fff" // 左侧 todo tree  图标的颜色,没有设置,使用前景色
  },
  "todo-tree.highlights.customHighlight": {
    "BUG": {
      "background": "#D01F00", // 红色
      "foreground": "#f9f9fb",
      "icon": "bug", // 显示的 icon
      "rulerColor": "#D01F00", // 预览表标尺的颜色
      "iconColour": "#D01F00", // todo  树中图标颜色
      "gutterIcon": true // 是否在行号旁显示图标
    },
    "TODO": {
      "background": "#3399CC", // 蓝色
      "foreground": "#f9f9fb",
      "iconColour": "#3399CC",
      "icon": "todo",
      "rulerLane": "full",
      "gutterIcon": true
    },
    "FIXME": {
      "background": "#FF9900", // 黄色
      "foreground": "#f9f9fb",
      "iconColour": "#FF9900",
      "icon": "alert", // 警告
      "gutterIcon": true,
      "type": "text" // 有文字部分(代码、tab、text), 后面的空白部分不高亮
    },
    "NOTE": {
      "background": "#f9f9fb",
      "foreground": "#000", // 黑色
      "icon": "note",
      // "type": "whole-line", // 整行高亮
      "rulerColour": "#D1BC15",
      "iconColour ": "white",
      "hideFromTree": true // 在  todo  树中隐藏
    }
  },
  "todo-tree.general.statusBar": "none", // 状态栏显示样式
  "todo-tree.tree.showScanModeButton": true,
}

推荐阅读