Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add goimports beautifier for Go language #1726

Merged
merged 1 commit into from
Jun 22, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Next
- Add goimports beautifier for Go language
- ...

# v0.30.1 (2017-06-19)
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ Some of the supported beautifiers are developed for Node.js and are automaticall
| Fortran Beautifier | :warning: 1 executable | :x: No Docker support | :bookmark_tabs: Manually:<br/>1. Install [Emacs (`emacs`)](https://www.gnu.org/software/emacs/) by following https://www.gnu.org/software/emacs/<br/> |
| Gherkin formatter | :white_check_mark: | :ok_hand: Not necessary | :smiley: Nothing! |
| gofmt | :warning: Manual installation | :construction: Not an executable | :page_facing_up: Go to https://golang.org/cmd/gofmt/ and follow the instructions. |
| goimports | :warning: 1 executable | :x: No Docker support | :bookmark_tabs: Manually:<br/>1. Install [goimports (`goimports`)](https://godoc.org/golang.org/x/tools/cmd/goimports) by following https://godoc.org/golang.org/x/tools/cmd/goimports<br/> |
| hh_format | :warning: Manual installation | :construction: Not an executable | :page_facing_up: Go to http://hhvm.com/ and follow the instructions. |
| HTML Beautifier | :warning: Manual installation | :construction: Not an executable | :page_facing_up: Go to https://github.com/threedaymonk/htmlbeautifier and follow the instructions. |
| JS Beautify | :white_check_mark: | :ok_hand: Not necessary | :smiley: Nothing! |
Expand Down Expand Up @@ -142,7 +143,7 @@ See [all supported options in the documentation at `docs/options.md`](docs/opti
| Fortran | `Fortran - Modern` |`.f90`, `.F90`, `.f95`, `.F95`, `.f03`, `.F03`, `.f08`, `.F08` | **[`Fortran Beautifier`](https://www.gnu.org/software/emacs/)** |
| gherkin | `Gherkin` |`.feature` | **[`Gherkin formatter`](https://github.com/Glavin001/atom-beautify/blob/master/src/beautifiers/gherkin.coffee)** |
| GLSL | `C`, `opencl`, `GLSL` |`.vert`, `.frag` | **[`clang-format`](https://clang.llvm.org/docs/ClangFormat.html)** |
| Go | `Go` |`.go` | **[`gofmt`](https://golang.org/cmd/gofmt/)** |
| Go | `Go` |`.go` | **[`gofmt`](https://golang.org/cmd/gofmt/)**, [`goimports`](https://godoc.org/golang.org/x/tools/cmd/goimports) |
| Golang Template | `HTML (Go)`, `Go Template` |`.gohtml` | **[`Pretty Diff`](https://github.com/prettydiff/prettydiff)** |
| Handlebars | `Handlebars`, `HTML (Handlebars)` |`.hbs`, `.handlebars` | **[`JS Beautify`](https://github.com/beautify-web/js-beautify)**, [`Pretty Diff`](https://github.com/prettydiff/prettydiff) |
| Haskell | `Haskell` |`.hs` | **[`stylish-haskell`](https://github.com/jaspervdj/stylish-haskell)** |
Expand Down
31 changes: 24 additions & 7 deletions docs/options.md
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,23 @@ Options for Emacs executable.
2. Go into *Packages* and search for "*Atom Beautify*" package.
3. Find the option "*Emacs*" and change it to your desired configuration.

##### [goimports](#goimports)

**Important**: This option is only configurable from within Atom Beautify's setting panel.

**Type**: `object`

**Description**:

Options for goimports executable.

**How to Configure**

1. You can open the [Settings View](https://github.com/atom/settings-view) by navigating to
*Edit > Preferences (Linux)*, *Atom > Preferences (OS X)*, or *File > Preferences (Windows)*.
2. Go into *Packages* and search for "*Atom Beautify*" package.
3. Find the option "*goimports*" and change it to your desired configuration.

##### [isort](#isort)

**Important**: This option is only configurable from within Atom Beautify's setting panel.
Expand Down Expand Up @@ -3920,13 +3937,13 @@ Path to clang-format config file. i.e. clang-format.cfg (Supported by clang-form

#### [Go](#go)

**Supported Beautifiers**: [`gofmt`](#gofmt)
**Supported Beautifiers**: [`gofmt`](#gofmt) [`goimports`](#goimports)

| Option | gofmt |
| --- | --- |
| `disabled` | :white_check_mark: |
| `default_beautifier` | :white_check_mark: |
| `beautify_on_save` | :white_check_mark: |
| Option | gofmt | goimports |
| --- | --- | --- |
| `disabled` | :white_check_mark: | :white_check_mark: |
| `default_beautifier` | :white_check_mark: | :white_check_mark: |
| `beautify_on_save` | :white_check_mark: | :white_check_mark: |

**Description**:

Expand Down Expand Up @@ -3957,7 +3974,7 @@ Disable Go Beautification

**Type**: `string`

**Enum**: `gofmt`
**Enum**: `gofmt` `goimports`

**Description**:

Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,8 @@
"nginx",
"nginx beautify",
"golang template",
"align-yaml"
"align-yaml",
"goimports"
],
"devDependencies": {
"coffeelint": "1.16.0"
Expand Down
36 changes: 36 additions & 0 deletions src/beautifiers/goimports.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
###
Requires https://godoc.org/golang.org/x/tools/cmd/goimports
###

"use strict"
Beautifier = require('./beautifier')

module.exports = class Goimports extends Beautifier
name: "goimports"
link: "https://godoc.org/golang.org/x/tools/cmd/goimports"
executables: [
{
name: "goimports"
cmd: "goimports"
homepage: "https://godoc.org/golang.org/x/tools/cmd/goimports"
installation: "https://godoc.org/golang.org/x/tools/cmd/goimports"
version: {
# Does not display version
args: ['--help'],
parse: (text) -> text.indexOf("usage: goimports") isnt -1 and "0.0.0",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also created a Docker image for goimports: https://hub.docker.com/r/unibeautify/goimports/
I am going to use it during my testing right now.

runOptions: {
ignoreReturnCode: true,
returnStderr: true
}
}
}
]

options: {
Go: false
}

beautify: (text, language, options) ->
@exe("goimports").run([
@tempFile("input", text)
])
1 change: 1 addition & 0 deletions src/beautifiers/index.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ module.exports = class Beautifiers extends EventEmitter
'csscomb'
'gherkin'
'gofmt'
'goimports'
'latex-beautify'
'fortran-beautifier'
'js-beautify'
Expand Down
22 changes: 20 additions & 2 deletions src/options.json
Original file line number Diff line number Diff line change
Expand Up @@ -2085,7 +2085,8 @@
"description": "Options for language Go",
"collapsed": true,
"beautifiers": [
"gofmt"
"gofmt",
"goimports"
],
"grammars": [
"Go"
Expand All @@ -2108,7 +2109,8 @@
"default": "gofmt",
"description": "Default Beautifier to be used for Go",
"enum": [
"gofmt"
"gofmt",
"goimports"
]
},
"beautify_on_save": {
Expand Down Expand Up @@ -9244,6 +9246,22 @@
}
}
},
"goimports": {
"key": "goimports",
"title": "goimports",
"type": "object",
"collapsed": true,
"description": "Options for goimports executable.",
"properties": {
"path": {
"key": "path",
"title": "Binary/Script Path",
"type": "string",
"default": "",
"description": "Absolute path to the \"goimports\" executable's binary/script."
}
}
},
"emacs": {
"key": "emacs",
"title": "Emacs",
Expand Down