前端-标准-elint代码格式化

eslint配置文件

// .eslintignore文件// 不检测iconfont.js文件**/iconfont.jsroot = true [*]charset = utf-8end_of_line = lfindent_size = 2indent_style = spaceinsert_final_newline = truetrim_trailing_whitespace = true

常见命令

  • 主动格式化修复src文件夹下文件:eslint --fix src
  • 自动检测并列举不合乎的格局:eslint src
  • 检测指定文件夹下的.js和.vue文件:eslint --ext .js,.vue src
  • 依据配置文件检测指定类型文件:eslint --config .eslintrc.js --ext .js,.vue src

设置代码跳过eslint检测

  • 不检测当行:// eslint-disable-line
  • 不检测下一行:// eslint-disable-next-line
  • 整个文件不检测:头部放/* eslint-disable */
  • 跳过多行:

    /* eslint-disable */function a() {    return this;}/* eslint-enable */