From 0a0ba673e8f148456d5fdb85028c07870ab0b95b Mon Sep 17 00:00:00 2001 From: Glavin Wiechert Date: Sun, 3 May 2015 01:23:29 -0300 Subject: [PATCH] Closes #176. Add gofmt beautifier for Golang language --- .travis.yml | 2 ++ README.md | 1 + .../simple-jsbeautifyrc/go/expected/test.go | 9 ++++++++ .../simple-jsbeautifyrc/go/original/test.go | 10 ++++++++ package.json | 4 +++- spec/beautify-languages-spec.coffee | 3 ++- src/beautifiers/gofmt.coffee | 18 +++++++++++++++ src/beautifiers/index.coffee | 5 ++-- src/languages/go.coffee | 23 +++++++++++++++++++ src/languages/index.coffee | 1 + 10 files changed, 72 insertions(+), 4 deletions(-) create mode 100644 examples/simple-jsbeautifyrc/go/expected/test.go create mode 100644 examples/simple-jsbeautifyrc/go/original/test.go create mode 100644 src/beautifiers/gofmt.coffee create mode 100644 src/languages/go.coffee diff --git a/.travis.yml b/.travis.yml index 1626ca1..afba334 100644 --- a/.travis.yml +++ b/.travis.yml @@ -39,6 +39,8 @@ before_install: - brew install pandoc # Java, C, C++, C#, Objective-C, D, Pawn, Vala - brew install uncrustify + # Golang + - brew install go # PHP # - brew tap homebrew/homebrew-php # - brew gist-logs php56 diff --git a/README.md b/README.md index 0fc9902..a18ba0a 100644 --- a/README.md +++ b/README.md @@ -44,6 +44,7 @@ Or Settings/Preferences ➔ Packages ➔ Search for `atom-beautify` - [x] [Ruby](https://github.com/donaldpipowitch/atom-beautify/issues/25) - Requires [Ruby Beautify](https://github.com/erniebrodeur/ruby-beautify) - [x] [CoffeeScript](https://github.com/donaldpipowitch/atom-beautify/issues/31) +- [x] [Golang](https://github.com/Glavin001/atom-beautify/issues/176) - [x] [Java](https://github.com/Glavin001/atom-beautify/issues/45) - Requires [Uncrustify](http://sourceforge.net/projects/uncrustify/) - [x] [C](https://github.com/Glavin001/atom-beautify/issues/57) diff --git a/examples/simple-jsbeautifyrc/go/expected/test.go b/examples/simple-jsbeautifyrc/go/expected/test.go new file mode 100644 index 0000000..dbfa518 --- /dev/null +++ b/examples/simple-jsbeautifyrc/go/expected/test.go @@ -0,0 +1,9 @@ +package main + +import "fmt" + +func main() { + // Why so much white space? + + fmt.Println("This is a poorly formatted file!") +} diff --git a/examples/simple-jsbeautifyrc/go/original/test.go b/examples/simple-jsbeautifyrc/go/original/test.go new file mode 100644 index 0000000..0194903 --- /dev/null +++ b/examples/simple-jsbeautifyrc/go/original/test.go @@ -0,0 +1,10 @@ +package main + +import "fmt" + +func main() { + // Why so much white space? + + + fmt.Println( "This is a poorly formatted file!" ) +} \ No newline at end of file diff --git a/package.json b/package.json index 5acacf9..062144d 100644 --- a/package.json +++ b/package.json @@ -129,6 +129,8 @@ "yaml", "front matter", "jekyll", - "marko" + "marko", + "go", + "golang" ] } diff --git a/spec/beautify-languages-spec.coffee b/spec/beautify-languages-spec.coffee index f75cf6d..d63dde4 100644 --- a/spec/beautify-languages-spec.coffee +++ b/spec/beautify-languages-spec.coffee @@ -20,7 +20,8 @@ describe "BeautifyLanguages", -> "java", "javascript", "json", "less", "mustache", "objective-c", "perl", "php", "python", "ruby", "sass", "sql", - "typescript", "xml", "csharp", "gfm", "marko", "tss" + "typescript", "xml", "csharp", "gfm", "marko", + "tss", "go" ] beforeEach -> diff --git a/src/beautifiers/gofmt.coffee b/src/beautifiers/gofmt.coffee new file mode 100644 index 0000000..41716f7 --- /dev/null +++ b/src/beautifiers/gofmt.coffee @@ -0,0 +1,18 @@ +### +Requires http://golang.org/cmd/gofmt/ +### + +"use strict" +Beautifier = require('./beautifier') + +module.exports = class gofmt extends Beautifier + name: "gofmt" + + options: { + Go: true + } + + beautify: (text, language, options) -> + @run("gofmt", [ + @tempFile("input", text) + ]) diff --git a/src/beautifiers/index.coffee b/src/beautifiers/index.coffee index ebf1319..f67bff9 100644 --- a/src/beautifiers/index.coffee +++ b/src/beautifiers/index.coffee @@ -36,6 +36,7 @@ module.exports = class Beautifiers 'coffee-formatter' 'htmlbeautifier' 'csscomb' + 'gofmt' 'js-beautify' 'perltidy' 'php-cs-fixer' @@ -332,12 +333,12 @@ module.exports = class Beautifiers userId: atom.config.get("atom-beautify._analyticsUserId") event: "Beautify" properties: - language: language.name + language: language?.name grammar: grammar extension: fileExtension version: version options: allOptions - label: language.name + label: language?.name category: version # if unsupportedGrammar diff --git a/src/languages/go.coffee b/src/languages/go.coffee new file mode 100644 index 0000000..174a029 --- /dev/null +++ b/src/languages/go.coffee @@ -0,0 +1,23 @@ +module.exports = { + + name: "Go" + description: "Golang" + namespace: "go" + + ### + Supported Grammars + ### + grammars: [ + "Go" + ] + + ### + Supported extensions + ### + extensions: [ + "go" + ] + + options: [] + +} \ No newline at end of file diff --git a/src/languages/index.coffee b/src/languages/index.coffee index f580cea..2b11a5f 100644 --- a/src/languages/index.coffee +++ b/src/languages/index.coffee @@ -28,6 +28,7 @@ module.exports = class Languages "d" "ejs" "erb" + "go" "handlebars" "html" "java"