-
Notifications
You must be signed in to change notification settings - Fork 449
/
Copy pathtypescript-formatter.coffee
47 lines (39 loc) · 1.24 KB
/
typescript-formatter.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
"use strict"
Beautifier = require('./beautifier')
module.exports = class TypeScriptFormatter extends Beautifier
name: "TypeScript Formatter"
link: "https://github.com/vvakame/typescript-formatter"
options: {
TypeScript:
indent_with_tabs: true
tab_width: true
indent_size: true
TSX:
indent_with_tabs: true
tab_width: true
indent_size: true
}
beautify: (text, language, options) ->
return new @Promise((resolve, reject) =>
try
format = require("typescript-formatter/lib/formatter").format
formatterUtils = require("typescript-formatter/lib/utils")
# @verbose('format', format, formatterUtils)
opts = formatterUtils.createDefaultFormatCodeSettings()
if options.indent_with_tabs
opts.convertTabsToSpaces = false
else
opts.tabSize = options.tab_width or options.indent_size
opts.indentSize = options.indent_size
opts.indentStyle = 'space'
if language is "TSX"
fileName = 'test.tsx'
else
fileName = ''
@verbose('typescript', text, opts)
result = format(fileName, text, opts)
@verbose(result)
resolve result
catch e
return reject(e)
)