提交 c267afd3 编写于 作者: K Kenan Karamehmedovic 提交者: Sebastian Florek

Replace gofmt code formating tool with goimports (#2172)

上级 db4f293b
...@@ -28,7 +28,7 @@ import path from 'path'; ...@@ -28,7 +28,7 @@ import path from 'path';
import through from 'through2'; import through from 'through2';
import conf from './conf'; import conf from './conf';
import {gofmtCommand} from './gocommand'; import {goimportsCommand} from './gocommand';
/** HTML beautifier from js-beautify package */ /** HTML beautifier from js-beautify package */
const htmlBeautify = beautify.html; const htmlBeautify = beautify.html;
...@@ -126,10 +126,10 @@ gulp.task('format-html', function() { ...@@ -126,10 +126,10 @@ gulp.task('format-html', function() {
}); });
/** /**
* Formats all project's Go files using gofmt. * Formats all project's Go files using goimports tool.
*/ */
gulp.task('format-go', function(doneFn) { gulp.task('format-go', function(doneFn) {
gofmtCommand( goimportsCommand(
[ [
'-w', '-w',
path.relative(conf.paths.base, conf.paths.backendSrc), path.relative(conf.paths.base, conf.paths.backendSrc),
......
...@@ -55,15 +55,15 @@ export default function goCommand(args, doneFn, envOverride) { ...@@ -55,15 +55,15 @@ export default function goCommand(args, doneFn, envOverride) {
} }
/** /**
* Spawns a Gofmt process after making sure all Go prerequisites are present. * Spawns a goimports process after making sure all Go prerequisites are present.
* *
* @param {!Array<string>} args - Arguments of the go command. * @param {!Array<string>} args - Arguments of the go command.
* @param {function(?Error=)} doneFn - Callback. * @param {function(?Error=)} doneFn - Callback.
* @param {!Object<string, string>=} [envOverride] optional environment variables overrides map. * @param {!Object<string, string>=} [envOverride] optional environment variables overrides map.
*/ */
export function gofmtCommand(args, doneFn, envOverride) { export function goimportsCommand(args, doneFn, envOverride) {
checkPrerequisites() checkPrerequisites()
.then(() => spawnGofmtProcess(args, envOverride)) .then(() => spawnGoimportsProcess(args, envOverride))
.then(doneFn) .then(doneFn)
.fail((error) => doneFn(error)); .fail((error) => doneFn(error));
} }
...@@ -205,13 +205,13 @@ function spawnGoProcess(args, envOverride) { ...@@ -205,13 +205,13 @@ function spawnGoProcess(args, envOverride) {
} }
/** /**
* Spawns gofmt process. * Spawns goimports process.
* Promises an error if the go command process fails. * Promises an error if the go command process fails.
* *
* @param {!Array<string>} args - Arguments of the go command. * @param {!Array<string>} args - Arguments of the go command.
* @param {!Object<string, string>=} [envOverride] optional environment variables overrides map. * @param {!Object<string, string>=} [envOverride] optional environment variables overrides map.
* @return {Q.Promise} A promise object. * @return {Q.Promise} A promise object.
*/ */
function spawnGofmtProcess(args, envOverride) { function spawnGoimportsProcess(args, envOverride) {
return spawnProcess('gofmt', args, envOverride); return spawnProcess('goimports', args, envOverride);
} }
...@@ -173,7 +173,7 @@ $ gulp check-javascript-format ...@@ -173,7 +173,7 @@ $ gulp check-javascript-format
Before committing any changes, please link/copy the pre-commit hook into your .git directory. This will keep you from accidentally committing non formatted code. Before committing any changes, please link/copy the pre-commit hook into your .git directory. This will keep you from accidentally committing non formatted code.
The hook requires gofmt to be in your PATH. The hook requires goimports to be in your PATH.
```shell ```shell
cd <dashboard_home>/.git/hooks/ cd <dashboard_home>/.git/hooks/
......
...@@ -5,7 +5,7 @@ readonly red=$(tput bold; tput setaf 1) ...@@ -5,7 +5,7 @@ readonly red=$(tput bold; tput setaf 1)
readonly green=$(tput bold; tput setaf 2) readonly green=$(tput bold; tput setaf 2)
exit_code=0 exit_code=0
gofmt_available=false goimports_available=false
gulp_available=false gulp_available=false
# Pre checks # Pre checks
...@@ -20,13 +20,13 @@ else ...@@ -20,13 +20,13 @@ else
fi fi
echo "${reset}" echo "${reset}"
echo -ne "Checking if gofmt is available in your PATH... " echo -ne "Checking if goimports is available in your PATH... "
if ! OUT=$(which gofmt 2>&1); then if ! OUT=$(which goimports 2>&1); then
echo "${red}ERROR!" echo "${red}ERROR!"
echo "Please add gofmt to your PATH" echo "Please add goimports to your PATH"
exit_code=1 exit_code=1
else else
gofmt_available=true goimports_available=true
echo "${green}OK" echo "${green}OK"
fi fi
...@@ -44,15 +44,15 @@ if ${gulp_available}; then ...@@ -44,15 +44,15 @@ if ${gulp_available}; then
fi fi
fi fi
if ${gofmt_available}; then if ${goimports_available}; then
echo "${reset}" echo "${reset}"
echo -ne "Checking go files formatting... " echo -ne "Checking go files formatting... "
unformatted=$(gofmt -l src/app/backend) unformatted=$(goimports -l src/app/backend)
if [ ! -z "$unformatted" ]; then if [ ! -z "$unformatted" ]; then
echo "${red}ERROR!" echo "${red}ERROR!"
echo "There is an issue with file formatting." echo "There is an issue with file formatting."
echo "To format go files run:" echo "To format go files run:"
echo " gofmt -w src/app/backend" echo " goimports -w src/app/backend"
exit_code=1 exit_code=1
else else
echo "${green}OK" echo "${green}OK"
......
...@@ -20,7 +20,7 @@ import ( ...@@ -20,7 +20,7 @@ import (
"log" "log"
"strings" "strings"
"github.com/emicklei/go-restful" restful "github.com/emicklei/go-restful"
"k8s.io/client-go/kubernetes" "k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest" "k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd" "k8s.io/client-go/tools/clientcmd"
......
...@@ -18,7 +18,7 @@ import ( ...@@ -18,7 +18,7 @@ import (
"net/http" "net/http"
"testing" "testing"
"github.com/emicklei/go-restful" restful "github.com/emicklei/go-restful"
) )
func TestNewClientManager(t *testing.T) { func TestNewClientManager(t *testing.T) {
......
...@@ -20,7 +20,7 @@ import ( ...@@ -20,7 +20,7 @@ import (
"strconv" "strconv"
"strings" "strings"
"github.com/emicklei/go-restful" restful "github.com/emicklei/go-restful"
"github.com/kubernetes/dashboard/src/app/backend/api" "github.com/kubernetes/dashboard/src/app/backend/api"
"github.com/kubernetes/dashboard/src/app/backend/client" "github.com/kubernetes/dashboard/src/app/backend/client"
"github.com/kubernetes/dashboard/src/app/backend/integration" "github.com/kubernetes/dashboard/src/app/backend/integration"
......
...@@ -22,7 +22,7 @@ import ( ...@@ -22,7 +22,7 @@ import (
"reflect" "reflect"
"strings" "strings"
"github.com/emicklei/go-restful" restful "github.com/emicklei/go-restful"
"github.com/kubernetes/dashboard/src/app/backend/client" "github.com/kubernetes/dashboard/src/app/backend/client"
) )
......
...@@ -23,7 +23,7 @@ import ( ...@@ -23,7 +23,7 @@ import (
"strings" "strings"
"time" "time"
"github.com/emicklei/go-restful" restful "github.com/emicklei/go-restful"
"github.com/kubernetes/dashboard/src/app/backend/client" "github.com/kubernetes/dashboard/src/app/backend/client"
"golang.org/x/net/xsrftoken" "golang.org/x/net/xsrftoken"
utilnet "k8s.io/apimachinery/pkg/util/net" utilnet "k8s.io/apimachinery/pkg/util/net"
......
...@@ -17,7 +17,7 @@ package integration ...@@ -17,7 +17,7 @@ package integration
import ( import (
"net/http" "net/http"
"github.com/emicklei/go-restful" restful "github.com/emicklei/go-restful"
"github.com/kubernetes/dashboard/src/app/backend/integration/api" "github.com/kubernetes/dashboard/src/app/backend/integration/api"
) )
......
...@@ -17,7 +17,7 @@ package integration ...@@ -17,7 +17,7 @@ package integration
import ( import (
"testing" "testing"
"github.com/emicklei/go-restful" restful "github.com/emicklei/go-restful"
) )
func TestIntegrationHandler_Install(t *testing.T) { func TestIntegrationHandler_Install(t *testing.T) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册