Add two beautifiers: clang-format and yapf
This commit is contained in:
parent
075be2cd40
commit
9985f0677b
|
@ -1,3 +1,7 @@
|
|||
# dev
|
||||
- Add [clang-format](http://clang.llvm.org/docs/ClangFormat.html) beautifier for C/C++/Obj-C languages.
|
||||
- Add [yapf](http://github.com/google/yapf) beautifier for Python.
|
||||
|
||||
# v0.29.0
|
||||
- Closes [#447](https://github.com/Glavin001/atom-beautify/issues/447). Improved Handlebars language support
|
||||
|
||||
|
|
|
@ -50,6 +50,10 @@
|
|||
{
|
||||
"name": "Clemens Damke",
|
||||
"url": "https://github.com/Cortys"
|
||||
},
|
||||
{
|
||||
"name": "Zhang YANG",
|
||||
"url": "https://github.com/ProgramFan"
|
||||
}
|
||||
],
|
||||
"engines": {
|
||||
|
|
|
@ -0,0 +1,60 @@
|
|||
###
|
||||
Requires clang-format (https://clang.llvm.org)
|
||||
###
|
||||
|
||||
"use strict"
|
||||
Beautifier = require('./beautifier')
|
||||
path = require('path')
|
||||
fs = require('fs')
|
||||
|
||||
module.exports = class ClangFormat extends Beautifier
|
||||
|
||||
name: "clang-format"
|
||||
|
||||
options: {
|
||||
"C++": true
|
||||
"C": true
|
||||
"Objective-C": true
|
||||
}
|
||||
|
||||
###
|
||||
Dump contents to a given file
|
||||
###
|
||||
dumpToFile: (name = "atom-beautify-dump", contents = "") ->
|
||||
return new Promise((resolve, reject) =>
|
||||
fs.open(name, "w", (err, fd) =>
|
||||
@debug('dumpToFile', name, err, fd)
|
||||
return reject(err) if err
|
||||
fs.write(fd, contents, (err) ->
|
||||
return reject(err) if err
|
||||
fs.close(fd, (err) ->
|
||||
return reject(err) if err
|
||||
resolve(name)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
beautify: (text, language, options) ->
|
||||
return new @Promise((resolve, reject) ->
|
||||
editor = atom.workspace.getActiveTextEditor()
|
||||
if editor?
|
||||
fullPath = editor.getPath()
|
||||
currDir = path.dirname(fullPath)
|
||||
currFile = path.basename(fullPath)
|
||||
dumpFile = path.join(currDir, ".atom-beautify.#{currFile}")
|
||||
resolve dumpFile
|
||||
else
|
||||
reject(new Error("No active editor found!"))
|
||||
)
|
||||
.then((dumpFile) =>
|
||||
# console.log("clang-format", dumpFile)
|
||||
@run("clang-format", [
|
||||
@dumpToFile(dumpFile, text)
|
||||
["--style=file"]
|
||||
], help: {
|
||||
link: "https://clang.llvm.org/docs/ClangFormat.html"
|
||||
}).then( =>
|
||||
fs.unlinkSync(dumpFile)
|
||||
)
|
||||
)
|
|
@ -37,6 +37,7 @@ module.exports = class Beautifiers extends EventEmitter
|
|||
'autopep8'
|
||||
'coffee-formatter'
|
||||
'coffee-fmt'
|
||||
'clang-format'
|
||||
'htmlbeautifier'
|
||||
'csscomb'
|
||||
'gherkin'
|
||||
|
@ -54,6 +55,7 @@ module.exports = class Beautifiers extends EventEmitter
|
|||
'sqlformat'
|
||||
'tidy-markdown'
|
||||
'typescript-formatter'
|
||||
'yapf'
|
||||
]
|
||||
|
||||
###
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
###
|
||||
Requires https://github.com/google/yapf
|
||||
###
|
||||
|
||||
"use strict"
|
||||
Beautifier = require('./beautifier')
|
||||
|
||||
module.exports = class Yapf extends Beautifier
|
||||
|
||||
name: "yapf"
|
||||
|
||||
# I decide to support no options since yapf is configured using its
|
||||
# own configure file.
|
||||
options: {
|
||||
Python: false
|
||||
}
|
||||
|
||||
beautify: (text, language, options) ->
|
||||
# console.log('yapf', options, text, language)
|
||||
@run("yapf", [
|
||||
["--style=pep8"]
|
||||
@tempFile("input", text)
|
||||
], help: {
|
||||
link: "https://github.com/google/yapf"
|
||||
})
|
Loading…
Reference in New Issue