关于规范化:前端规范elint代码格式化

11次阅读

共计 523 个字符,预计需要花费 2 分钟才能阅读完成。

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

eslint 配置文件

// .eslintignore 文件

// 不检测 iconfont.js 文件
**/iconfont.js

root = true
 
[*]
charset = utf-8
end_of_line = lf
indent_size = 2
indent_style = space
insert_final_newline = true
trim_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 */
正文完
 0