frouioui/tagenal

View on GitHub

Showing 43 of 43 total issues

exported function ArticleFromID should have comment or be unexported
Open

func ArticleFromID(c echo.Context, ID int) (article *models.Article, err error) {
Severity: Minor
Found in frontend/client/articles.go by golint

Quote this to prevent word splitting.
Open

yq w -i vitess_vtgate_grpc_ingress_route.yaml "spec.routes[0].services[0].name" $(kubectl get service --namespace=vitess -l planetscale.com/component=vtgate,planetscale.com/cell=zone1  -o custom-columns=":metadata.name" | head -n2)

Quote this to prevent word splitting

Problematic code:

ls -l $(getfilename)

Correct code:

# getfilename outputs 1 file
ls -l "$(getfilename)"

# getfilename outputs multiple files, linefeed separated
getfilename | while IFS='' read -r line
do
  ls -l "$line"
done

Rationale:

When command expansions are unquoted, word splitting and globbing will occur. This often manifests itself by breaking when filenames contain spaces.

Trying to fix it by adding quotes or escapes to the data will not work. Instead, quote the command substitution itself.

If the command substitution outputs multiple pieces of data, use a loop instead.

Exceptions

In rare cases you actually want word splitting, such as in

gcc $(pkg-config --libs openssl) client.c

This is because pkg-config outputs -lssl -lcrypto, which you want to break up by spaces into -lssl and -lcrypto. An alternative is to put the variables to an array and expand it:

args=( $(pkg-config --libs openssl) )
gcc "${args[@]}" client.c

The power of using an array becomes evident when you want to combine, for example, the command result with user-provided arguments:

compile () {
    args=( $(pkg-config --libs openssl) "${@}" )
    gcc "${args[@]}" client.c
}
compile -DDEBUG
+ gcc -lssl -lcrypto -DDEBUG client.c

Notice

Original content from the ShellCheck https://github.com/koalaman/shellcheck/wiki.

exported function InitArticlesGRPC should have comment or be unexported
Open

func InitArticlesGRPC() (err error) {
Severity: Minor
Found in frontend/client/articles.go by golint

exported function ArticlesFromCategory should have comment or be unexported
Open

func ArticlesFromCategory(c echo.Context, category string) (articles []models.Article, err error) {
Severity: Minor
Found in frontend/client/articles.go by golint

exported function ArticlesFromRegion should have comment or be unexported
Open

func ArticlesFromRegion(c echo.Context, regionID int) (articles []models.Article, err error) {
Severity: Minor
Found in frontend/client/articles.go by golint

exported function InitGRPCClient should have comment or be unexported
Open

func InitGRPCClient() (err error) {
Severity: Minor
Found in frontend/client/client.go by golint

Quote this to prevent word splitting.
Open

yq w -i vitess_vtctld_ingress_route.yaml "spec.routes[0].services[0].name" $(kubectl get service --namespace=vitess --selector="planetscale.com/component=vtctld" -o custom-columns=":metadata.name" | head -n2)

Quote this to prevent word splitting

Problematic code:

ls -l $(getfilename)

Correct code:

# getfilename outputs 1 file
ls -l "$(getfilename)"

# getfilename outputs multiple files, linefeed separated
getfilename | while IFS='' read -r line
do
  ls -l "$line"
done

Rationale:

When command expansions are unquoted, word splitting and globbing will occur. This often manifests itself by breaking when filenames contain spaces.

Trying to fix it by adding quotes or escapes to the data will not work. Instead, quote the command substitution itself.

If the command substitution outputs multiple pieces of data, use a loop instead.

Exceptions

In rare cases you actually want word splitting, such as in

gcc $(pkg-config --libs openssl) client.c

This is because pkg-config outputs -lssl -lcrypto, which you want to break up by spaces into -lssl and -lcrypto. An alternative is to put the variables to an array and expand it:

args=( $(pkg-config --libs openssl) )
gcc "${args[@]}" client.c

The power of using an array becomes evident when you want to combine, for example, the command result with user-provided arguments:

compile () {
    args=( $(pkg-config --libs openssl) "${@}" )
    gcc "${args[@]}" client.c
}
compile -DDEBUG
+ gcc -lssl -lcrypto -DDEBUG client.c

Notice

Original content from the ShellCheck https://github.com/koalaman/shellcheck/wiki.

exported function InitUsersGRPC should have comment or be unexported
Open

func InitUsersGRPC() (err error) {
Severity: Minor
Found in frontend/client/users.go by golint

exported type Popularity should have comment or be unexported
Open

type Popularity struct {
Severity: Minor
Found in jobs/popularity/main.go by golint

Tips depend on target shell and yours is unknown. Add a shebang.
Open

kubectl exec -n redis -it redis-cluster-0 -- redis-cli --cluster create --cluster-replicas 1 $(kubectl get pods -n redis -l app=redis-cluster -o jsonpath='{range.items[*]}{.status.podIP}:6379 ')
Severity: Minor
Found in kubernetes/redis/setup.sh by shellcheck

Tips depend on target shell and yours is unknown. Add a shebang.

Problematic code:

echo "$RANDOM"   # Does this work?

Correct code:

#!/bin/sh
echo "$RANDOM"  # Unsupported in sh. Produces warning.

or

#!/bin/bash
echo "$RANDOM"  # Supported in bash. No warnings.

Rationale:

Different shells support different features. To give effective advice, ShellCheck needs to know which shell your script is going to run on. You will get a different numbers of warnings about different things depending on your target shell.

ShellCheck normally determines your target shell from the shebang (having e.g. #!/bin/sh as the first line). The shell can also be specified from the CLI with -s, e.g. shellcheck -s sh file.

If you don't specify shebang nor -s, ShellCheck gives this message and proceeds with some default (bash).

Note that this error can not be ignored with a [[directive]]. It is not a suggestion to improve your script, but a warning that ShellCheck lacks information it needs to be helpful.

Exceptions

None. Please either add a shebang or use -s.

Notice

Original content from the ShellCheck https://github.com/koalaman/shellcheck/wiki.

exported function ArticlesFromCategoryGRPC should have comment or be unexported
Open

func ArticlesFromCategoryGRPC(c echo.Context, category string) (articles []models.Article, err error) {
Severity: Minor
Found in frontend/client/articles.go by golint

exported method Article.GetText should have comment or be unexported
Open

func (art *Article) GetText() (string, error) {
Severity: Minor
Found in frontend/models/articles.go by golint

exported function GetDefaultServicesInfos should have comment or be unexported
Open

func GetDefaultServicesInfos() []ServiceInfo {
Severity: Minor
Found in frontend/models/info.go by golint

Use 'cd ... || exit' or 'cd ... || return' in case cd fails.
Open

cd "${0%/*}"
Severity: Minor
Found in monitoring/build.sh by shellcheck

Use cd ... || exit in case cd fails.

Problematic code:

cd generated_files
rm -r *.c

func(){
  cd foo
  do_something
}

Correct code:

cd generated_files || exit
rm -r *.c

# For functions, you may want to use return:
func(){
  cd foo || return
  do_something
}

Rationale:

cd can fail for a variety of reasons: misspelled paths, missing directories, missing permissions, broken symlinks and more.

If/when it does, the script will keep going and do all its operations in the wrong directory. This can be messy, especially if the operations involve creating or deleting a lot of files.

To avoid this, make sure you handle the cases when cd fails. Ways to do this include

  • cd foo || exit as suggested to just abort immediately
  • if cd foo; then echo "Ok"; else echo "Fail"; fi for custom handling
  • <(cd foo && cmd) as an alternative to <(cd foo || exit; cmd) in <(..), $(..) or ( )

Exceptions:

ShellCheck does not give this warning when cd is on the left of a || or &&, or the condition of a if, while or until loop. Having a set -e command anywhere in the script will disable this message, even though it won't necessarily prevent the issue.

If you are accounting for cd failures in a way shellcheck doesn't realize, you can disable this message with a [[directive]].

Notice

Original content from the ShellCheck https://github.com/koalaman/shellcheck/wiki.

Quote this to prevent word splitting.
Open

yq w -i vitess_vtctld_client_ingress_route.yaml "spec.routes[0].services[0].name" $(kubectl get service --namespace=vitess --selector="planetscale.com/component=vtctld" -o custom-columns=":metadata.name" | head -n2)

Quote this to prevent word splitting

Problematic code:

ls -l $(getfilename)

Correct code:

# getfilename outputs 1 file
ls -l "$(getfilename)"

# getfilename outputs multiple files, linefeed separated
getfilename | while IFS='' read -r line
do
  ls -l "$line"
done

Rationale:

When command expansions are unquoted, word splitting and globbing will occur. This often manifests itself by breaking when filenames contain spaces.

Trying to fix it by adding quotes or escapes to the data will not work. Instead, quote the command substitution itself.

If the command substitution outputs multiple pieces of data, use a loop instead.

Exceptions

In rare cases you actually want word splitting, such as in

gcc $(pkg-config --libs openssl) client.c

This is because pkg-config outputs -lssl -lcrypto, which you want to break up by spaces into -lssl and -lcrypto. An alternative is to put the variables to an array and expand it:

args=( $(pkg-config --libs openssl) )
gcc "${args[@]}" client.c

The power of using an array becomes evident when you want to combine, for example, the command result with user-provided arguments:

compile () {
    args=( $(pkg-config --libs openssl) "${@}" )
    gcc "${args[@]}" client.c
}
compile -DDEBUG
+ gcc -lssl -lcrypto -DDEBUG client.c

Notice

Original content from the ShellCheck https://github.com/koalaman/shellcheck/wiki.

exported function ArticlesFromRegionGRPC should have comment or be unexported
Open

func ArticlesFromRegionGRPC(c echo.Context, regionID int) (articles []models.Article, err error) {
Severity: Minor
Found in frontend/client/articles.go by golint

exported function UsersFromIDGRPC should have comment or be unexported
Open

func UsersFromIDGRPC(c echo.Context, ID int) (user *models.User, err error) {
Severity: Minor
Found in frontend/client/users.go by golint

2: cannot find package "github.com/go-sql-driver/mysql" in any of:
Open

    _ "github.com/go-sql-driver/mysql"
Severity: Minor
Found in api/articles/db/db.go by govet

Use 'cd ... || exit' or 'cd ... || return' in case cd fails.
Open

cd kube-prometheus
Severity: Minor
Found in lib/get-kube-prom.sh by shellcheck

Use cd ... || exit in case cd fails.

Problematic code:

cd generated_files
rm -r *.c

func(){
  cd foo
  do_something
}

Correct code:

cd generated_files || exit
rm -r *.c

# For functions, you may want to use return:
func(){
  cd foo || return
  do_something
}

Rationale:

cd can fail for a variety of reasons: misspelled paths, missing directories, missing permissions, broken symlinks and more.

If/when it does, the script will keep going and do all its operations in the wrong directory. This can be messy, especially if the operations involve creating or deleting a lot of files.

To avoid this, make sure you handle the cases when cd fails. Ways to do this include

  • cd foo || exit as suggested to just abort immediately
  • if cd foo; then echo "Ok"; else echo "Fail"; fi for custom handling
  • <(cd foo && cmd) as an alternative to <(cd foo || exit; cmd) in <(..), $(..) or ( )

Exceptions:

ShellCheck does not give this warning when cd is on the left of a || or &&, or the condition of a if, while or until loop. Having a set -e command anywhere in the script will disable this message, even though it won't necessarily prevent the issue.

If you are accounting for cd failures in a way shellcheck doesn't realize, you can disable this message with a [[directive]].

Notice

Original content from the ShellCheck https://github.com/koalaman/shellcheck/wiki.

exported type ServiceInfo should have comment or be unexported
Open

type ServiceInfo struct {
Severity: Minor
Found in frontend/models/info.go by golint
Severity
Category
Status
Source
Language