-
Notifications
You must be signed in to change notification settings - Fork 453
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2189 from arl-o/master
Add Black beautifier for Python
- Loading branch information
Showing
7 changed files
with
97 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
### | ||
Requires [black](https://github.com/ambv/black) | ||
### | ||
"use strict" | ||
Beautifier = require('./beautifier') | ||
path = require('path') | ||
|
||
module.exports = class Black extends Beautifier | ||
name: "black" | ||
link: "https://github.com/ambv/black" | ||
executables: [ | ||
{ | ||
name: "black" | ||
cmd: "black" | ||
homepage: "https://github.com/ambv/black" | ||
installation: "https://github.com/ambv/black#installation" | ||
version: { | ||
parse: (text) -> | ||
# Try to read beta values, eg "black, version 18.6b4" -> 18.6.4 | ||
try | ||
text.match(/black, version (\d+\.\d+)/)[1] + "." + text.match(/b(\d+)$/)[1] | ||
catch | ||
text.match(/black, version (\d+\.\d+)/)[1] + ".0" | ||
} | ||
} | ||
] | ||
|
||
options: { | ||
Python: false | ||
} | ||
|
||
beautify: (text, language, options, context) -> | ||
cwd = context.filePath and path.dirname context.filePath | ||
# `-` as filename reads from stdin | ||
@exe("black").run(["-"], { | ||
cwd: cwd | ||
onStdin: (stdin) -> | ||
stdin.end text | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters