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

RFC: Various changes to CI linting #2855

Closed
wants to merge 10 commits into from
20 changes: 7 additions & 13 deletions .github/workflows/static_analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,20 @@ jobs:

- name: Get dependencies
run: |
sudo apt-get update && sudo apt-get install gcc libgl1-mesa-dev libegl1-mesa-dev libgles2-mesa-dev libx11-dev xorg-dev
go install golang.org/x/tools/cmd/goimports@latest
go install github.com/fzipp/gocyclo/cmd/gocyclo@latest
go install golang.org/x/lint/golint@latest
sudo apt-get update
sudo apt-get install gcc libgl1-mesa-dev libegl1-mesa-dev libgles2-mesa-dev libx11-dev xorg-dev
go install github.com/fzipp/gocyclo/cmd/gocyclo@v0.4.0
go install mvdan.cc/gofumpt@v0.3.0
go install honnef.co/go/tools/cmd/staticcheck@v0.2.2

- name: Cleanup repository
run: rm -rf vendor/

- name: Vet
run: go vet -tags ci ./...

- name: Goimports
run: test -z $(goimports -e -d . | tee /dev/stderr)
- name: Gofumpt
run: test -z $(gofumpt -d -e . | tee /dev/stderr)

- name: Gocyclo
run: gocyclo -over 30 .

- name: Golint
run: golint -set_exit_status $(go list -tags ci ./...)

- name: Staticcheck
run: staticcheck -go 1.14 ./...
Copy link
Member Author

Choose a reason for hiding this comment

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

FYI, this was removed as it picks it up from the module by default.

run: staticcheck ./...
1 change: 1 addition & 0 deletions app/app_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ bool isBundled();
void sendNotification(char *title, char *content);
*/
import "C"

import (
"fmt"
"strings"
Expand Down
1 change: 1 addition & 0 deletions app/app_desktop_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ bool isDarkMode();
void watchTheme();
*/
import "C"

import (
"net/url"
"os"
Expand Down
1 change: 1 addition & 0 deletions app/app_mobile_and.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ void openURL(uintptr_t java_vm, uintptr_t jni_env, uintptr_t ctx, char *url);
void sendNotification(uintptr_t java_vm, uintptr_t jni_env, uintptr_t ctx, char *title, char *content);
*/
import "C"

import (
"log"
"net/url"
Expand Down
1 change: 1 addition & 0 deletions app/app_mobile_ios.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ void openURL(char *urlStr);
void sendNotification(char *title, char *content);
*/
import "C"

import (
"net/url"
"path/filepath"
Expand Down
3 changes: 2 additions & 1 deletion app/app_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func runScript(name, script string) {
fileName := fmt.Sprintf("fyne-%s-%s-%d.ps1", appID, name, scriptNum)

tmpFilePath := filepath.Join(os.TempDir(), fileName)
err := ioutil.WriteFile(tmpFilePath, []byte(script), 0600)
err := ioutil.WriteFile(tmpFilePath, []byte(script), 0o600)
if err != nil {
fyne.LogError("Could not write script to show notification", err)
return
Expand All @@ -121,6 +121,7 @@ func runScript(name, script string) {
fyne.LogError("Failed to launch windows notify script", err)
}
}

func watchTheme() {
// TODO monitor the Windows theme
}
4 changes: 2 additions & 2 deletions app/preferences.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func (p *preferences) saveToFile(path string) error {
p.savedRecently = true
p.prefLock.Unlock()
defer p.resetSavedRecently()
err := os.MkdirAll(filepath.Dir(path), 0700)
err := os.MkdirAll(filepath.Dir(path), 0o700)
if err != nil { // this is not an exists error according to docs
return err
}
Expand Down Expand Up @@ -89,7 +89,7 @@ func (p *preferences) loadFromFile(path string) (err error) {
file, err := os.Open(path) // #nosec
if err != nil {
if os.IsNotExist(err) {
if err := os.MkdirAll(filepath.Dir(path), 0700); err != nil {
if err := os.MkdirAll(filepath.Dir(path), 0o700); err != nil {
return err
}
return nil
Expand Down
2 changes: 1 addition & 1 deletion app/settings_desktop.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func ensureDirExists(dir string) {
return
}

err := os.MkdirAll(dir, 0700)
err := os.MkdirAll(dir, 0o700)
if err != nil {
fyne.LogError("Unable to create settings storage:", err)
}
Expand Down
2 changes: 1 addition & 1 deletion app/settings_desktop_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func TestWatchFile(t *testing.T) {
watchFile(path, func() {
called <- true
})
file, _ := os.OpenFile(path, os.O_APPEND|os.O_WRONLY, 0644)
file, _ := os.OpenFile(path, os.O_APPEND|os.O_WRONLY, 0o644)
file.WriteString(" ")
file.Close()

Expand Down
15 changes: 10 additions & 5 deletions canvas/animation.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,12 @@ func NewColorRGBAAnimation(start, stop color.Color, d time.Duration, fn func(col
return &fyne.Animation{
Duration: d,
Tick: func(done float32) {
fn(color.RGBA{R: scaleChannel(rStart, rDelta, done), G: scaleChannel(gStart, gDelta, done),
B: scaleChannel(bStart, bDelta, done), A: scaleChannel(aStart, aDelta, done)})
}}
fn(color.RGBA{
R: scaleChannel(rStart, rDelta, done), G: scaleChannel(gStart, gDelta, done),
B: scaleChannel(bStart, bDelta, done), A: scaleChannel(aStart, aDelta, done),
})
},
}
}

// NewPositionAnimation sets up a new animation that will transition from the start to stop Position over
Expand All @@ -58,7 +61,8 @@ func NewPositionAnimation(start, stop fyne.Position, d time.Duration, fn func(fy
Duration: d,
Tick: func(done float32) {
fn(fyne.NewPos(scaleVal(start.X, xDelta, done), scaleVal(start.Y, yDelta, done)))
}}
},
}
}

// NewSizeAnimation sets up a new animation that will transition from the start to stop Size over
Expand All @@ -74,7 +78,8 @@ func NewSizeAnimation(start, stop fyne.Size, d time.Duration, fn func(fyne.Size)
Duration: d,
Tick: func(done float32) {
fn(fyne.NewSize(scaleVal(start.Width, widthDelta, done), scaleVal(start.Height, heightDelta, done)))
}}
},
}
}

func scaleChannel(start int, diff, done float32) uint8 {
Expand Down
1 change: 0 additions & 1 deletion canvas/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ type Image struct {
Translucency float64 // Set a translucency value > 0.0 to fade the image
FillMode ImageFill // Specify how the image should expand to fill or fit the available space
ScaleMode ImageScale // Specify the type of scaling interpolation applied to the image

}

// Alpha is a convenience function that returns the alpha value for an image
Expand Down
2 changes: 1 addition & 1 deletion cmd/fyne/commands/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ type Command interface {
Run(args []string)
}

//Getter is the command that can handle downloading and installing Fyne apps to the current platform.
// Getter is the command that can handle downloading and installing Fyne apps to the current platform.
type Getter = commands.Getter

// NewGetter returns a command that can handle the download and install of GUI apps built using Fyne.
Expand Down
3 changes: 2 additions & 1 deletion cmd/fyne/internal/commands/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ func Test_CheckGoVersionValidValue(t *testing.T) {
{
expectedValue: expectedValue{args: []string{"version"}},
mockReturn: mockReturn{ret: []byte("go version go1.17.6 linux/amd64")},
}}
},
}

versionOk := &testCommandRuns{runs: expected, t: t}
assert.Nil(t, checkGoVersion(versionOk, version.NewConstrainGroupFromString(">=1.17")))
Expand Down
4 changes: 2 additions & 2 deletions cmd/fyne/internal/commands/bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func (b *Bundler) Run(args []string) {
fileModes = os.O_RDWR | os.O_APPEND
}

f, err := os.OpenFile(b.out, fileModes, 0666)
f, err := os.OpenFile(b.out, fileModes, 0o666)
if err == nil {
outFile = f
} else {
Expand Down Expand Up @@ -221,7 +221,7 @@ func openOutputFile(filePath string, noheader bool) (file *os.File, close func()
fileModes = os.O_RDWR | os.O_APPEND
}

f, err := os.OpenFile(filePath, fileModes, 0666)
f, err := os.OpenFile(filePath, fileModes, 0o666)
if err != nil {
if !os.IsNotExist(err) {
fyne.LogError("Unable to open output file", err)
Expand Down
1 change: 0 additions & 1 deletion cmd/fyne/internal/commands/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ func (g *Getter) Run(args []string) {
func goPath() string {
cmd := execabs.Command("go", "env", "GOPATH")
out, err := cmd.CombinedOutput()

if err != nil {
home, _ := os.UserHomeDir()
return filepath.Join(home, "go")
Expand Down
6 changes: 4 additions & 2 deletions cmd/fyne/internal/commands/package-darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ func (p *Packager) packageDarwin() (err error) {
}
}()

tplData := darwinData{Name: p.name, ExeName: exeName, AppID: p.appID, Version: p.appVersion, Build: p.appBuild,
Category: strings.ToLower(p.category)}
tplData := darwinData{
Name: p.name, ExeName: exeName, AppID: p.appID, Version: p.appVersion, Build: p.appBuild,
Category: strings.ToLower(p.category),
}
if err := templates.InfoPlistDarwin.Execute(infoFile, tplData); err != nil {
return fmt.Errorf("failed to write plist template: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/fyne/internal/commands/package-mobile.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func (p *Packager) packageIOS(target string) error {
"author" : "xcode",
"version" : 1
}
}`), 0644)
}`), 0o644)
if err != nil {
fyne.LogError("Content err", err)
}
Expand Down
27 changes: 16 additions & 11 deletions cmd/fyne/internal/commands/package-util-mock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,24 @@ import (
"github.com/stretchr/testify/require"
)

var utilExistsMock func(path string) bool
var utilCopyFileMock func(source string, target string) error
var utilCopyExeFileMock func(src, tgt string) error
var utilWriteFileMock func(target string, data []byte) error
var utilEnsureSubDirMock func(parent, name string) string
var (
utilExistsMock func(path string) bool
utilCopyFileMock func(source string, target string) error
utilCopyExeFileMock func(src, tgt string) error
utilWriteFileMock func(target string, data []byte) error
utilEnsureSubDirMock func(parent, name string) string
)

var utilRequireAndroidSDKMock func() error
var utilAndroidBuildToolsPathMock func() string
var (
utilRequireAndroidSDKMock func() error
utilAndroidBuildToolsPathMock func() string
)

var utilIsAndroidMock func(os string) bool
var utilIsIOSMock func(os string) bool
var utilIsMobileMock func(os string) bool
var (
utilIsAndroidMock func(os string) bool
utilIsIOSMock func(os string) bool
utilIsMobileMock func(os string) bool
)

type mockUtil struct{}

Expand Down Expand Up @@ -75,7 +81,6 @@ func (m *mockCopyFileRuns) verifyExpectation(t *testing.T, executable bool, sour
assert.Equal(t, m.expected[m.current].executable, executable)

return m.expected[m.current].ret

}

func (m mockUtil) CopyFile(source string, target string) error {
Expand Down
2 changes: 1 addition & 1 deletion cmd/fyne/internal/commands/package-util.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func (d defaultUtil) CopyExeFile(src, tgt string) error {
}

func (d defaultUtil) WriteFile(target string, data []byte) error {
return ioutil.WriteFile(target, data, 0644)
return ioutil.WriteFile(target, data, 0o644)
}

func (d defaultUtil) EnsureSubDir(parent, name string) string {
Expand Down
4 changes: 2 additions & 2 deletions cmd/fyne/internal/commands/release.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ func (r *Releaser) packageIOSRelease() error {
}

payload := filepath.Join(r.dir, "Payload")
_ = os.Mkdir(payload, 0750)
_ = os.Mkdir(payload, 0o750)
defer os.RemoveAll(payload)
appName := mobile.AppOutputName(r.os, r.name)
payloadAppDir := filepath.Join(payload, appName)
Expand Down Expand Up @@ -324,7 +324,7 @@ func (r *Releaser) packageMacOSRelease() error {

func (r *Releaser) packageWindowsRelease(outFile string) error {
payload := filepath.Join(r.dir, "Payload")
_ = os.Mkdir(payload, 0750)
_ = os.Mkdir(payload, 0o750)
defer os.RemoveAll(payload)

manifestPath := filepath.Join(payload, "appxmanifest.xml")
Expand Down
2 changes: 1 addition & 1 deletion cmd/fyne/internal/mobile/binres/binres.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func errWrongType(have ResType, want ...ResType) error {
return fmt.Errorf("wrong resource type %s, want one of %v", have, want)
}

//ResType is the type of a resource
// ResType is the type of a resource
type ResType uint16

// IsSupported returns if a type is supported
Expand Down
2 changes: 1 addition & 1 deletion cmd/fyne/internal/mobile/binres/genarsc.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions cmd/fyne/internal/mobile/binres/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@ func NewMipmapTable(pkgname string) (*Table, string) {

pkg.specs = append(pkg.specs,
&TypeSpec{
id: uint8(attr) + 1, //1,
id: uint8(attr) + 1, // 1,
},
&TypeSpec{
id: uint8(mipmap) + 1, //2,
id: uint8(mipmap) + 1, // 2,
entryCount: 1,
entries: []uint32{uint32(icon)}, // {0}
types: []*Type{typ},
Expand Down
3 changes: 2 additions & 1 deletion cmd/fyne/internal/mobile/build_androidapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ import (
)

func goAndroidBuild(pkg *packages.Package, bundleID string, androidArchs []string,
iconPath, appName, version string, build, target int, release bool) (map[string]bool, error) {
iconPath, appName, version string, build, target int, release bool,
) (map[string]bool, error) {
ndkRoot, err := ndkRoot()
if err != nil {
return nil, err
Expand Down
5 changes: 3 additions & 2 deletions cmd/fyne/internal/mobile/build_iosapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ import (
)

func goIOSBuild(pkg *packages.Package, bundleID string, archs []string,
appName, version string, build int, release bool, cert, profile string) (map[string]bool, error) {
appName, version string, build int, release bool, cert, profile string,
) (map[string]bool, error) {
src := pkg.PkgPath
buildO = rfc1034Label(appName) + ".app"
// Detect the team ID
Expand Down Expand Up @@ -76,7 +77,7 @@ func goIOSBuild(pkg *packages.Package, bundleID string, archs []string,
printcmd("echo \"%s\" > %s", file.contents, file.name)
}
if !buildN {
if err := ioutil.WriteFile(file.name, file.contents, 0600); err != nil {
if err := ioutil.WriteFile(file.name, file.contents, 0o600); err != nil {
return nil, err
}
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/fyne/internal/mobile/gendex/gendex.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func gendex() error {
if androidHome == "" {
return errors.New("ANDROID_HOME not set")
}
if err := os.MkdirAll(tmpdir+"/work/org/golang/app", 0775); err != nil {
if err := os.MkdirAll(tmpdir+"/work/org/golang/app", 0o775); err != nil {
return err
}
javaFiles, err := filepath.Glob("../../../../internal/driver/mobile/app/*.java")
Expand Down
8 changes: 3 additions & 5 deletions cmd/fyne/internal/mobile/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ import (
"golang.org/x/sys/execabs"
)

var (
goos = runtime.GOOS
)
var goos = runtime.GOOS

func mkdir(dir string) error {
if buildX || buildN {
Expand All @@ -26,7 +24,7 @@ func mkdir(dir string) error {
if buildN {
return nil
}
return os.MkdirAll(dir, 0750)
return os.MkdirAll(dir, 0o750)
}

func removeAll(path string) error {
Expand Down Expand Up @@ -55,7 +53,7 @@ func resetReadOnlyFlagAll(path string) error {
return err
}
if !fi.IsDir() {
return os.Chmod(path, 0600)
return os.Chmod(path, 0o600)
}
fd, err := os.Open(filepath.Clean(path))
if err != nil {
Expand Down