CNode

分享一个代码格式化工具 esformatter 以及一个小插件

分享
Mmagicdawn发布于10 年前最后回复10 年前1 回复6171 浏览0 收藏

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)

T
TakWolf#1·10 年前

mark

来自酷炫的 CNodeMD

参与回复
登录后即可参与回复。登录