added import sorting using isort + small yapf fix

This commit is contained in:
Mark Baas 2015-11-18 14:45:08 -04:00
parent 04528f7643
commit 1bc919eafa
3 changed files with 35 additions and 3 deletions

View File

@ -15,10 +15,24 @@ module.exports = class Autopep8 extends Beautifier
beautify: (text, language, options) ->
@run("autopep8", [
@tempFile("input", text)
tempFile = @tempFile("input", text)
"-i"
["--max-line-length", "#{options.max_line_length}"] if options.max_line_length?
["--indent-size","#{options.indent_size}"] if options.indent_size?
["--ignore","#{options.ignore.join(',')}"] if options.ignore?
], help: {
link: "https://github.com/hhatto/autopep8"
})
.then(=>
if options.sort_imports
@run("isort",
[tempFile],
help: {
link: "https://github.com/timothycrosley/isort"
})
.then(=>
@readFile(tempFile)
)
else
@readFile(tempFile)
)

View File

@ -15,8 +15,22 @@ module.exports = class Yapf extends Beautifier
beautify: (text, language, options) ->
@run("yapf", [
"-i"
["--style=pep8"]
@tempFile("input", text)
tempFile = @tempFile("input", text)
], help: {
link: "https://github.com/google/yapf"
}, ignoreReturnCode: true)
.then(=>
if options.sort_imports
@run("isort",
[tempFile],
help: {
link: "https://github.com/timothycrosley/isort"
})
.then(=>
@readFile(tempFile)
)
else
@readFile(tempFile)
)

View File

@ -41,5 +41,9 @@ module.exports = {
items:
type: 'string'
description: "do not fix these errors/warnings"
sort_imports:
type: 'boolean'
default: false
description: "sort imports (requires isort installed)"
}