Skip to content

Commit

Permalink
Enable staticcheck linter and solve issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Vasco Guita committed Nov 23, 2022
1 parent 8541bb8 commit 7177e97
Show file tree
Hide file tree
Showing 73 changed files with 299 additions and 244 deletions.
1 change: 0 additions & 1 deletion .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ linters:
- stylecheck # TODO: consider enabling the 'stylecheck' linter to enforce style rules.
- usestdlibvars # TODO: consider enabling the 'usestdlibvars' linter to detect the possibility to use variables/constants from the Go standard library.
- thelper # TODO: consider enabling the 'thelper' linter to detect golang test helpers without t.Helper() call and check the consistency of test helpers.
- staticcheck # TODO: consider enabling the 'staticcheck' linter to find bugs and performance issues, offer simplifications, and enforce style rules.
- predeclared # TODO: consider enabling the 'predeclared' linter to find code that shadows one of Go's predeclared identifiers.
- paralleltest # TODO: consider enabling the 'paralleltest' linter to detect missing usage of t.Parallel() method in Go test.
- ireturn # TODO: consider enabling the 'ireturn' linter to accept interfaces and return concrete types.
Expand Down
3 changes: 3 additions & 0 deletions changelog/unreleased/enhancement-staticcheck.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Enhancement: Enable staticcheck linter in golangci-lint and solve issues

https://github.com/cs3org/reva/pull/3487
10 changes: 5 additions & 5 deletions cmd/reva/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ package main
import (
"bufio"
"encoding/json"
"io/ioutil"
"os"
gouser "os/user"
"path"
"strings"
Expand Down Expand Up @@ -50,7 +50,7 @@ func getConfigFile() string {
}

func readConfig() (*config, error) {
data, err := ioutil.ReadFile(getConfigFile())
data, err := os.ReadFile(getConfigFile())
if err != nil {
return nil, err
}
Expand All @@ -68,7 +68,7 @@ func writeConfig(c *config) error {
if err != nil {
return err
}
return ioutil.WriteFile(getConfigFile(), data, 0600)
return os.WriteFile(getConfigFile(), data, 0600)
}

func getTokenFile() string {
Expand All @@ -81,15 +81,15 @@ func getTokenFile() string {
}

func readToken() (string, error) {
data, err := ioutil.ReadFile(getTokenFile())
data, err := os.ReadFile(getTokenFile())
if err != nil {
return "", err
}
return string(data), nil
}

func writeToken(token string) {
err := ioutil.WriteFile(getTokenFile(), []byte(token), 0600)
err := os.WriteFile(getTokenFile(), []byte(token), 0600)
if err != nil {
panic(err)
}
Expand Down
3 changes: 1 addition & 2 deletions cmd/revad/internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,14 @@ package config

import (
"io"
"io/ioutil"

"github.com/BurntSushi/toml"
"github.com/pkg/errors"
)

// Read reads the configuration from the reader.
func Read(r io.Reader) (map[string]interface{}, error) {
data, err := ioutil.ReadAll(r)
data, err := io.ReadAll(r)
if err != nil {
err = errors.Wrap(err, "config: error reading from reader")
return nil, err
Expand Down
9 changes: 4 additions & 5 deletions cmd/revad/internal/grace/grace.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ package grace

import (
"fmt"
"io/ioutil"
"net"
"os"
"os/signal"
Expand Down Expand Up @@ -108,7 +107,7 @@ func (w *Watcher) clean() error {
}

func (w *Watcher) readPID() (int, error) {
piddata, err := ioutil.ReadFile(w.pidFile)
piddata, err := os.ReadFile(w.pidFile)
if err != nil {
return 0, err
}
Expand All @@ -123,7 +122,7 @@ func (w *Watcher) readPID() (int, error) {
// GetProcessFromFile reads the pidfile and returns the running process or error if the process or file
// are not available.
func GetProcessFromFile(pfile string) (*os.Process, error) {
data, err := ioutil.ReadFile(pfile)
data, err := os.ReadFile(pfile)
if err != nil {
return nil, err
}
Expand All @@ -144,7 +143,7 @@ func GetProcessFromFile(pfile string) (*os.Process, error) {
// WritePID writes the pid to the configured pid file.
func (w *Watcher) WritePID() error {
// Read in the pid file as a slice of bytes.
if piddata, err := ioutil.ReadFile(w.pidFile); err == nil {
if piddata, err := os.ReadFile(w.pidFile); err == nil {
// Convert the file contents to an integer.
if pid, err := strconv.Atoi(string(piddata)); err == nil {
// Look for the pid in the process list.
Expand Down Expand Up @@ -174,7 +173,7 @@ func (w *Watcher) WritePID() error {

// If we get here, then the pidfile didn't exist or we are are in graceful reload and thus we overwrite
// or the pid in it doesn't belong to the user running this app.
err := ioutil.WriteFile(w.pidFile, []byte(fmt.Sprintf("%d", os.Getpid())), 0664)
err := os.WriteFile(w.pidFile, []byte(fmt.Sprintf("%d", os.Getpid())), 0664)
if err != nil {
return err
}
Expand Down
12 changes: 10 additions & 2 deletions cmd/revad/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ package main
import (
"flag"
"fmt"
"io/ioutil"
"io/fs"
"os"
"path"
"regexp"
Expand Down Expand Up @@ -163,10 +163,18 @@ func getConfigs() ([]map[string]interface{}, error) {
}

func getConfigsFromDir(dir string) (confs []string, err error) {
files, err := ioutil.ReadDir(*dirFlag)
entries, err := os.ReadDir(*dirFlag)
if err != nil {
return nil, err
}
files := make([]fs.FileInfo, 0, len(entries))
for _, entry := range entries {
info, err := entry.Info()
if err != nil {
return nil, err
}
files = append(files, info)
}

for _, value := range files {
if !value.IsDir() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ description: >
# _struct: config_

{{% dir name="mime_types" type="[]string" default=nil %}}
A list of mime types supported by this app. [[Ref]](https://github.com/cs3org/reva/tree/master/internal/grpc/services/appprovider/appprovider.go#L63)
A list of mime types supported by this app. [[Ref]](https://github.com/cs3org/reva/tree/master/internal/grpc/services/appprovider/appprovider.go#L62)
{{< highlight toml >}}
[grpc.services.appprovider]
mime_types = nil
{{< /highlight >}}
{{% /dir %}}

{{% dir name="custom_mime_types_json" type="string" default="nil" %}}
An optional mapping file with the list of supported custom file extensions and corresponding mime types. [[Ref]](https://github.com/cs3org/reva/tree/master/internal/grpc/services/appprovider/appprovider.go#L64)
An optional mapping file with the list of supported custom file extensions and corresponding mime types. [[Ref]](https://github.com/cs3org/reva/tree/master/internal/grpc/services/appprovider/appprovider.go#L63)
{{< highlight toml >}}
[grpc.services.appprovider]
custom_mime_types_json = "nil"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,31 @@ description: >
# _struct: config_

{{% dir name="mount_path" type="string" default="/" %}}
The path where the file system would be mounted. [[Ref]](https://github.com/cs3org/reva/tree/master/internal/grpc/services/storageprovider/storageprovider.go#L58)
The path where the file system would be mounted. [[Ref]](https://github.com/cs3org/reva/tree/master/internal/grpc/services/storageprovider/storageprovider.go#L57)
{{< highlight toml >}}
[grpc.services.storageprovider]
mount_path = "/"
{{< /highlight >}}
{{% /dir %}}

{{% dir name="mount_id" type="string" default="-" %}}
The ID of the mounted file system. [[Ref]](https://github.com/cs3org/reva/tree/master/internal/grpc/services/storageprovider/storageprovider.go#L59)
The ID of the mounted file system. [[Ref]](https://github.com/cs3org/reva/tree/master/internal/grpc/services/storageprovider/storageprovider.go#L58)
{{< highlight toml >}}
[grpc.services.storageprovider]
mount_id = "-"
{{< /highlight >}}
{{% /dir %}}

{{% dir name="driver" type="string" default="localhome" %}}
The storage driver to be used. [[Ref]](https://github.com/cs3org/reva/tree/master/internal/grpc/services/storageprovider/storageprovider.go#L60)
The storage driver to be used. [[Ref]](https://github.com/cs3org/reva/tree/master/internal/grpc/services/storageprovider/storageprovider.go#L59)
{{< highlight toml >}}
[grpc.services.storageprovider]
driver = "localhome"
{{< /highlight >}}
{{% /dir %}}

{{% dir name="drivers" type="map[string]map[string]interface{}" default="localhome" %}}
[[Ref]](https://github.com/cs3org/reva/tree/master/internal/grpc/services/storageprovider/storageprovider.go#L61)
[[Ref]](https://github.com/cs3org/reva/tree/master/internal/grpc/services/storageprovider/storageprovider.go#L60)
{{< highlight toml >}}
[grpc.services.storageprovider.drivers.localhome]
root = "/var/tmp/reva/"
Expand All @@ -44,39 +44,39 @@ user_layout = "{{.Username}}"
{{% /dir %}}

{{% dir name="tmp_folder" type="string" default="/var/tmp" %}}
Path to temporary folder. [[Ref]](https://github.com/cs3org/reva/tree/master/internal/grpc/services/storageprovider/storageprovider.go#L62)
Path to temporary folder. [[Ref]](https://github.com/cs3org/reva/tree/master/internal/grpc/services/storageprovider/storageprovider.go#L61)
{{< highlight toml >}}
[grpc.services.storageprovider]
tmp_folder = "/var/tmp"
{{< /highlight >}}
{{% /dir %}}

{{% dir name="data_server_url" type="string" default="http://localhost/data" %}}
The URL for the data server. [[Ref]](https://github.com/cs3org/reva/tree/master/internal/grpc/services/storageprovider/storageprovider.go#L63)
The URL for the data server. [[Ref]](https://github.com/cs3org/reva/tree/master/internal/grpc/services/storageprovider/storageprovider.go#L62)
{{< highlight toml >}}
[grpc.services.storageprovider]
data_server_url = "http://localhost/data"
{{< /highlight >}}
{{% /dir %}}

{{% dir name="expose_data_server" type="bool" default=false %}}
Whether to expose data server. [[Ref]](https://github.com/cs3org/reva/tree/master/internal/grpc/services/storageprovider/storageprovider.go#L64)
Whether to expose data server. [[Ref]](https://github.com/cs3org/reva/tree/master/internal/grpc/services/storageprovider/storageprovider.go#L63)
{{< highlight toml >}}
[grpc.services.storageprovider]
expose_data_server = false
{{< /highlight >}}
{{% /dir %}}

{{% dir name="available_checksums" type="map[string]uint32" default=nil %}}
List of available checksums. [[Ref]](https://github.com/cs3org/reva/tree/master/internal/grpc/services/storageprovider/storageprovider.go#L65)
List of available checksums. [[Ref]](https://github.com/cs3org/reva/tree/master/internal/grpc/services/storageprovider/storageprovider.go#L64)
{{< highlight toml >}}
[grpc.services.storageprovider]
available_checksums = nil
{{< /highlight >}}
{{% /dir %}}

{{% dir name="custom_mime_types_json" type="string" default="nil" %}}
An optional mapping file with the list of supported custom file extensions and corresponding mime types. [[Ref]](https://github.com/cs3org/reva/tree/master/internal/grpc/services/storageprovider/storageprovider.go#L66)
An optional mapping file with the list of supported custom file extensions and corresponding mime types. [[Ref]](https://github.com/cs3org/reva/tree/master/internal/grpc/services/storageprovider/storageprovider.go#L65)
{{< highlight toml >}}
[grpc.services.storageprovider]
custom_mime_types_json = "nil"
Expand Down
24 changes: 12 additions & 12 deletions docs/content/en/docs/config/packages/app/provider/wopi/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,80 +8,80 @@ description: >

# _struct: config_

{{% dir name="mime_types" type="[]string" default= %}}
Inherited from the appprovider. [[Ref]](https://github.com/cs3org/reva/tree/master/pkg/app/provider/wopi/wopi.go#L59)
{{% dir name="mime_types" type="[]string" default=nil %}}
Inherited from the appprovider. [[Ref]](https://github.com/cs3org/reva/tree/master/pkg/app/provider/wopi/wopi.go#L58)
{{< highlight toml >}}
[app.provider.wopi]
mime_types =
mime_types = nil
{{< /highlight >}}
{{% /dir %}}

{{% dir name="iop_secret" type="string" default="" %}}
The IOP secret used to connect to the wopiserver. [[Ref]](https://github.com/cs3org/reva/tree/master/pkg/app/provider/wopi/wopi.go#L60)
The IOP secret used to connect to the wopiserver. [[Ref]](https://github.com/cs3org/reva/tree/master/pkg/app/provider/wopi/wopi.go#L59)
{{< highlight toml >}}
[app.provider.wopi]
iop_secret = ""
{{< /highlight >}}
{{% /dir %}}

{{% dir name="wopi_url" type="string" default="" %}}
The wopiserver's URL. [[Ref]](https://github.com/cs3org/reva/tree/master/pkg/app/provider/wopi/wopi.go#L61)
The wopiserver's URL. [[Ref]](https://github.com/cs3org/reva/tree/master/pkg/app/provider/wopi/wopi.go#L60)
{{< highlight toml >}}
[app.provider.wopi]
wopi_url = ""
{{< /highlight >}}
{{% /dir %}}

{{% dir name="app_name" type="string" default="" %}}
The App user-friendly name. [[Ref]](https://github.com/cs3org/reva/tree/master/pkg/app/provider/wopi/wopi.go#L62)
The App user-friendly name. [[Ref]](https://github.com/cs3org/reva/tree/master/pkg/app/provider/wopi/wopi.go#L61)
{{< highlight toml >}}
[app.provider.wopi]
app_name = ""
{{< /highlight >}}
{{% /dir %}}

{{% dir name="app_icon_uri" type="string" default="" %}}
A URI to a static asset which represents the app icon. [[Ref]](https://github.com/cs3org/reva/tree/master/pkg/app/provider/wopi/wopi.go#L63)
A URI to a static asset which represents the app icon. [[Ref]](https://github.com/cs3org/reva/tree/master/pkg/app/provider/wopi/wopi.go#L62)
{{< highlight toml >}}
[app.provider.wopi]
app_icon_uri = ""
{{< /highlight >}}
{{% /dir %}}

{{% dir name="app_url" type="string" default="" %}}
The App URL. [[Ref]](https://github.com/cs3org/reva/tree/master/pkg/app/provider/wopi/wopi.go#L64)
The App URL. [[Ref]](https://github.com/cs3org/reva/tree/master/pkg/app/provider/wopi/wopi.go#L63)
{{< highlight toml >}}
[app.provider.wopi]
app_url = ""
{{< /highlight >}}
{{% /dir %}}

{{% dir name="app_int_url" type="string" default="" %}}
The internal app URL in case of dockerized deployments. Defaults to AppURL [[Ref]](https://github.com/cs3org/reva/tree/master/pkg/app/provider/wopi/wopi.go#L65)
The internal app URL in case of dockerized deployments. Defaults to AppURL [[Ref]](https://github.com/cs3org/reva/tree/master/pkg/app/provider/wopi/wopi.go#L64)
{{< highlight toml >}}
[app.provider.wopi]
app_int_url = ""
{{< /highlight >}}
{{% /dir %}}

{{% dir name="app_api_key" type="string" default="" %}}
The API key used by the app, if applicable. [[Ref]](https://github.com/cs3org/reva/tree/master/pkg/app/provider/wopi/wopi.go#L66)
The API key used by the app, if applicable. [[Ref]](https://github.com/cs3org/reva/tree/master/pkg/app/provider/wopi/wopi.go#L65)
{{< highlight toml >}}
[app.provider.wopi]
app_api_key = ""
{{< /highlight >}}
{{% /dir %}}

{{% dir name="jwt_secret" type="string" default="" %}}
The JWT secret to be used to retrieve the token TTL. [[Ref]](https://github.com/cs3org/reva/tree/master/pkg/app/provider/wopi/wopi.go#L67)
The JWT secret to be used to retrieve the token TTL. [[Ref]](https://github.com/cs3org/reva/tree/master/pkg/app/provider/wopi/wopi.go#L66)
{{< highlight toml >}}
[app.provider.wopi]
jwt_secret = ""
{{< /highlight >}}
{{% /dir %}}

{{% dir name="app_desktop_only" type="bool" default=false %}}
Specifies if the app can be opened only on desktop. [[Ref]](https://github.com/cs3org/reva/tree/master/pkg/app/provider/wopi/wopi.go#L68)
Specifies if the app can be opened only on desktop. [[Ref]](https://github.com/cs3org/reva/tree/master/pkg/app/provider/wopi/wopi.go#L67)
{{< highlight toml >}}
[app.provider.wopi]
app_desktop_only = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,16 +167,15 @@ package main

import (
"fmt"
"io/ioutil"
"os"
)

func main() {
err := ioutil.WriteFile("file1", []byte(""), 0600)
err := os.WriteFile("file1", []byte(""), 0600)
if err != nil {
os.Exit(1)
}
err = ioutil.WriteFile("file2", []byte(""), 0600)
err = os.WriteFile("file2", []byte(""), 0600)
if err != nil {
os.Exit(1)
}
Expand Down Expand Up @@ -208,16 +207,15 @@ package main

import (
"fmt"
"io/ioutil"
"os"
)

func main() {
err := ioutil.WriteFile("file1", []byte(""), 0600)
err := os.WriteFile("file1", []byte(""), 0600)
if err != nil {
os.Exit(1)
}
err = ioutil.WriteFile("file2", []byte(""), 0600)
err = os.WriteFile("file2", []byte(""), 0600)
if err != nil {
os.Exit(1)
}
Expand Down
4 changes: 2 additions & 2 deletions examples/plugin/json/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"context"
"encoding/json"
"errors"
"io/ioutil"
"os"
"strings"

userpb "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1"
Expand Down Expand Up @@ -63,7 +63,7 @@ func (m *Manager) Configure(ml map[string]interface{}) error {
return err
}

f, err := ioutil.ReadFile(c.Users)
f, err := os.ReadFile(c.Users)
if err != nil {
return err
}
Expand Down
Loading

0 comments on commit 7177e97

Please sign in to comment.