分享一个代码格式化工具 esformatter 以及一个小插件
发布于 8 年前 作者 magicdawn 4999 次浏览 来自 分享

esformatter 使用了 babylon 作为 parser, 支持 async function / es6 module import 等等啊, 比较好使 这里写了一个小插件 esformatter-curly https://github.com/magicdawn/esformatter-curly 例如下面的代码

import multiline

import {
  x as X,
  y as Y
} from 'utils'

会被格式化成一行(默认)

import { x as X, y as Y } from 'utils'

使用这个 esformatter-curly 可以避免这个现象, 如果原来是多行的, 使用这个插件之后, 给你保留多行

inline object

像下面这个对象字面两, 会被格式化成多行(默认)

var o = { x: 'hello', y: 'world' }

格式化成

var o = {
  x: 'hello',
  y: 'world'
}

有了这个插件之后可以避免这种状况, 如果你原来是单行的, 使用这个插件, 检测到是单行的, 就给你保留

插件地址 https://github.com/magicdawn/esformatter-curly 求 star, 另这个esformatter 真的比较强大, 自己写插件可以 limit linebreak indent whitespace 等等… 写点自定义的插件比较好玩…

1 回复

mark

来自酷炫的 CNodeMD

回到顶部