Inspections of BashSupport Pro

BashSupport Pro provides a set of inspections to help you write better Bash.

Additionally, ShellCheck is executed to highlight the most common problems of your scripts. Please refer to ShellCheck integration to learn more about it.

BashSupport Pro

Shebang in plain text files

Highlights plain text files, which have no extension, but a supported shebang line.

A quickfix allows to mark and open such a file as a shell script file.

Even if BashSupport Pro attempts to mark those files as shell scripts, the IDE sometimes associates files with the plain text file type.

Files:
Plain text files
Shebang in plain text files
Shebang in plain text files

Local use of variable

Highlights global variable declarations, which could be declared as local. Variable declarations are only highlighted, if there are no references to it outside the current function.

Comment to suppress warnings:
# bashsupport disable=BP2001
Local use of variable
Local use of variable

Unused local variable

This inspection marks local variables as unused, which are not referenced.

The message is displayed under these conditions:

  1. The variable is declared as local in a function
  2. It’s the first declaration of that variable in that function
  3. It’s not exported and there are no references to that variable in the function
Comment to suppress warnings:
# bashsupport disable=BP3001
Unused local variable
Unused local variable

Unused global variable

Marks global variable definitions, which appear unused. If a variable is exported, then it’s not highlighted.

Comment to suppress warnings:
# shellcheck disable=SC2034
Unused global variable
Unused global variable

Unused function argument

Highlights arguments in function calls, which are not used by that function.

Comment to suppress warnings:
# bashsupport disable=BP2002
Unused function argument
Unused function argument

Non-constant path of source directive

BashSupport Pro can’t follow dynamic path values. For example, "$PWD/included.sh" is a dynamic value. BashSupport Pro needs help here to understand which file should be used. It supports ShellCheck source directives.

Comment to suppress warnings:
# shellcheck disable=SC1090
Non-constant path of source directive
Non-constant path of source directive

Missing source file

Highlights file path values of source commands, which can’t be found on disk.

Comment to suppress warnings:
# shellcheck disable=SC1091
Missing source file
Missing source file

Modification of a read-only variable

Highlights modifications of variables, which were declared as read-only. Commands like readonly and declare -r mark a variable as read-only.

Operations, which don’t modify the value, e.g. export myVar, are not highlighted.

Comment to suppress warnings:
# bashsupport disable=BP3002
Modification of a read-only variable
Modification of a read-only variable

Incompatible line separators

Highlights files, which have line endings incompatible with Bash.

Comment to suppress warnings:
# bashsupport disable=BP1003
Incompatible line separators
Incompatible line separators

ShellCheck

Display the messages of ShellCheck in the editor.

ShellCheck is a shell script static analysis tool. It’s available at https://github.com/koalaman/shellcheck.

ShellCheck
ShellCheck

Function keyword

Marks a function keyword in POSIX shell scripts.

The function keyword is non-standard in POSIX shell and only supported by Bash and other shells with extended functionality.

Comment to suppress warnings:
# bashsupport disable=BP2003
Function keyword
Function keyword

File with shebang is not executable

Displays a warning for files, which have a shebang, but are not executable.

A quick fix is provided to make the file executable.

This inspection is turned off by default.

Comment to suppress warnings:
# bashsupport disable=BP1001
File with shebang is not executable
File with shebang is not executable

Executable file without shebang

Displays a warning for executable files, which don’t have a shebang.

A quick fix is provided to remove the executable flag of the file.

This inspection is turned off by default.

Comment to suppress warnings:
# bashsupport disable=BP1002
Executable file without shebang
Executable file without shebang

Unresolved variable

Highlights unresolved variables in shell scripts.

A variable reference is highlighted as unresolved under these conditions:

  • it was not previously declared in the file, in a sourced file or in a file sourcing the file containing the reference
  • it’s not a built-in or predefined variable. For example $PATH is a built-in variable and $HOME is a predefined variable.
  • it’s not included in the list of project variables
Comment to suppress warnings:
# shellcheck disable=SC2154
Unresolved variable
Unresolved variable

Google Code Style Guide

Missing main() function

Marks the first top-level command of a file, which should have a main() function instead.

Path:
BashSupport Pro → Google Shell Style Guide
Comment to suppress warnings:
# bashsupport disable=BP5001
Missing main() function
Missing main() function

Incorrect main() declaration

Marks incorrectly declared main() functions.

Path:
BashSupport Pro → Google Shell Style Guide
Comment to suppress warnings:
# bashsupport disable=BP5009
Incorrect main() declaration
Incorrect main() declaration

Inconsistent function keyword usage

Detect functions, which use the function keyword inconsistently.

Path:
BashSupport Pro → Google Shell Style Guide
Comment to suppress warnings:
# bashsupport disable=BP5002
Inconsistent function keyword usage
Inconsistent function keyword usage

Inconsistent function parentheses usage

Detect functions, which use the parentheses after the name inconsistently.

Path:
BashSupport Pro → Google Shell Style Guide
Comment to suppress warnings:
# bashsupport disable=BP5003
Inconsistent function parentheses usage
Inconsistent function parentheses usage

File name style

Detect files with names, which don’t follow the style guide. File names have to be lowercase with underscores to separate words.

Path:
BashSupport Pro → Google Shell Style Guide
Comment to suppress warnings:
# bashsupport disable=BP5004
File name style
File name style

Function name style

Detect functions with names, which don’t follow the style guide. Function have to be lowercase with underscores to separate words.

Separate library name and function name with ::, e.g. library::myFunction.

Path:
BashSupport Pro → Google Shell Style Guide
Comment to suppress warnings:
# bashsupport disable=BP5005
Function name style
Function name style

Variable name style

Detects variables and variable definitions with names, which don’t follow the style guide. Variables have to be lowercase with underscores to separate words.

Path:
BashSupport Pro → Google Shell Style Guide
Comment to suppress warnings:
# bashsupport disable=BP5006
Variable name style
Variable name style

Shebang definition

Detects incorrectly defined shebang lines. Executables must start with #!/bin/bash and a minimum number of flags.

Path:
BashSupport Pro → Google Shell Style Guide
Comment to suppress warnings:
# bashsupport disable=BP5007
Shebang definition
Shebang definition

Function comments

Detect functions with a missing function comment.

Path:
BashSupport Pro → Google Shell Style Guide
Comment to suppress warnings:
# bashsupport disable=BP5008
Function comments
Function comments

bats-core

Duplicate bats-core test

A single .bats bats-core file must not contain multiple tests of the same name.

Path:
BashSupport Pro → bats-core
Comment to suppress warnings:
# bashsupport disable=BP6001
Duplicate bats-core test
Duplicate bats-core test
© 2020–2024 Joachim Ansorg
Imprint
Privacy Policy
Legal