Skip to content
chris edited this page May 12, 2016 · 8 revisions

JFormatter

FECSJavaScript 的修复是基于 EFE 团队邵帅 专门针对我们的 JavaScript 编码规范 打造的 jformatterJSHint 团队的 fixmyjs,最后使用 esformatter 作空格和换行方面的格式化。

使用方式

最常用的方式就是直接调用fecs format --type=js,此时会递归的扫描当前目录下面的所有的 JavaScript 文件(默认已经忽略 node_modules, bower_components 目录),然后依次调用 fixmyjsjformatteresformatter 格式化得到的 JavaScript 文件,默认所有格式化后的文件按源目录结构保存在当前工作目录的 output 目录。

如果想要忽略某些文件或目录,可以使用 ignore 参数执行,例如:

$ fecs format --type=js --ignore='**/cli/**'

同时也可以使用 .fecsignore 文件来配置类似 Git 方式的 .gitignore 忽略规则。

另外,需要同时格式化多个目录时,可以这样:

$ fecs format dir1 dir2 --type=js

默认规则

  1. https://github.com/ecomfe/jformatter/blob/master/.jformatterrc
  2. https://github.com/ecomfe/fecs/blob/master/lib/js/jformatter.yml

注意事项

由于修复后的代码生成使用 escodegen,它将忽略源码中的空行,因此格式化后的代码将会缺少原有的空行(相关讨论),目前的解决方案是使用 --safe=high 放弃更多的修复,但保留源码空行。激进用户可以尝试使用 --safe=low 来作更多的修复。