add pybeautifier
This commit is contained in:
parent
b6c3d7dad3
commit
d85bd22bcb
|
@ -114,6 +114,10 @@
|
|||
{
|
||||
"name": "Victor Uriarte",
|
||||
"url": "https://github.com/vmuriart"
|
||||
},
|
||||
{
|
||||
"name": "guyskk",
|
||||
"url": "https://github.com/guyskk"
|
||||
}
|
||||
],
|
||||
"engines": {
|
||||
|
@ -288,6 +292,7 @@
|
|||
"clojure beautifier",
|
||||
"nunjucks",
|
||||
"ux markup",
|
||||
"pybeautifier",
|
||||
"cljfmt"
|
||||
],
|
||||
"devDependencies": {
|
||||
|
|
|
@ -57,6 +57,7 @@ module.exports = class Beautifiers extends EventEmitter
|
|||
'php-cs-fixer'
|
||||
'phpcbf'
|
||||
'prettydiff'
|
||||
'pybeautifier'
|
||||
'pug-beautify'
|
||||
'puppet-fix'
|
||||
'remark'
|
||||
|
|
|
@ -0,0 +1,66 @@
|
|||
'use strict'
|
||||
net = require('net')
|
||||
Beautifier = require('./beautifier')
|
||||
|
||||
HOST = '127.0.0.1'
|
||||
PORT = 36805
|
||||
MULTI_LINE_OUTPUT_TABLE = {
|
||||
'Grid': 0,
|
||||
'Vertical': 1,
|
||||
'Hanging Indent': 2,
|
||||
'Vertical Hanging Indent': 3,
|
||||
'Hanging Grid': 4,
|
||||
'Hanging Grid Grouped': 5,
|
||||
'NOQA': 6
|
||||
}
|
||||
|
||||
format = (data, formaters) ->
|
||||
return new Promise (resolve, reject) ->
|
||||
client = new net.Socket()
|
||||
client.on 'error', (error) ->
|
||||
client.destroy()
|
||||
reject(error)
|
||||
client.connect PORT, HOST, ->
|
||||
client.setEncoding('utf8')
|
||||
client.write(JSON.stringify({'data': data, 'formaters': formaters}))
|
||||
response = ''
|
||||
client.on 'data', (chunk) ->
|
||||
response += chunk
|
||||
client.on 'end', ->
|
||||
response = JSON.parse(response)
|
||||
if response.error?
|
||||
reject(Error(response.error))
|
||||
else
|
||||
resolve(response.data)
|
||||
client.destroy()
|
||||
|
||||
module.exports = class PythonBeautifier extends Beautifier
|
||||
|
||||
name: "pybeautifier"
|
||||
link: "https://github.com/guyskk/pybeautifier"
|
||||
|
||||
options: {
|
||||
Python: true
|
||||
}
|
||||
|
||||
beautify: (text, language, options) ->
|
||||
formater = {'name': options.formater}
|
||||
if options.formater == 'autopep8'
|
||||
formater.config = {
|
||||
'ignore': options.ignore
|
||||
'max_line_length': options.max_line_length
|
||||
}
|
||||
else if options.formater == 'yapf'
|
||||
formater.config = {'style_config': options.style_config}
|
||||
formaters = [formater]
|
||||
if options.sort_imports
|
||||
multi_line_output = MULTI_LINE_OUTPUT_TABLE[options.multi_line_output]
|
||||
formaters.push
|
||||
'name': 'isort'
|
||||
'config': {'multi_line_output': multi_line_output}
|
||||
return new @Promise (resolve, reject) ->
|
||||
format(text, formaters)
|
||||
.then (data) ->
|
||||
resolve(data)
|
||||
.catch (error) ->
|
||||
reject(error)
|
|
@ -41,9 +41,30 @@ module.exports = {
|
|||
items:
|
||||
type: 'string'
|
||||
description: "do not fix these errors/warnings"
|
||||
formater:
|
||||
type: 'string'
|
||||
default: 'autopep8'
|
||||
enum: ['autopep8', 'yapf']
|
||||
description: "formater used by pybeautifier"
|
||||
style_config:
|
||||
type: 'string'
|
||||
default: 'pep8'
|
||||
description: "formatting style used by yapf"
|
||||
sort_imports:
|
||||
type: 'boolean'
|
||||
default: false
|
||||
description: "sort imports (requires isort installed)"
|
||||
|
||||
multi_line_output:
|
||||
type: 'string'
|
||||
default: 'Hanging Grid Grouped'
|
||||
enum: [
|
||||
'Grid'
|
||||
'Vertical'
|
||||
'Hanging Indent'
|
||||
'Vertical Hanging Indent'
|
||||
'Hanging Grid'
|
||||
'Hanging Grid Grouped'
|
||||
'NOQA'
|
||||
]
|
||||
description: "defines how from imports wrap (requires isort installed)"
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue