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
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.
- 文件:
- 普通文本文件
局部使用变量
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.
- 注释来抑制警告:
# bashsupport disable=BP2001
未使用的局部变量
This inspection marks local variables as unused, which are not referenced.
The message is displayed under these conditions:
- The variable is declared as
local
in a function - It’s the first declaration of that variable in that function
- It’s not exported and there are no references to that variable in the function
- 注释来抑制警告:
# bashsupport disable=BP3001
未使用的全局变量
Marks global variable definitions, which appear unused. If a variable is exported, then it’s not highlighted.
- 注释来抑制警告:
# shellcheck disable=SC2034
函数参数未使用
Highlights arguments in function calls, which are not used by that function.
- 注释来抑制警告:
# bashsupport disable=BP2002
源文件指令不是固定路径
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.
- 注释来抑制警告:
# shellcheck disable=SC1090
缺少源文件
Highlights file path values of source
commands, which can’t be found on disk.
- 注释来抑制警告:
# shellcheck disable=SC1091
修改只读变量
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.
- 注释来抑制警告:
# bashsupport disable=BP3002
换行符不兼容
Highlights files, which have line endings incompatible with Bash.
- 注释来抑制警告:
# bashsupport disable=BP1003
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.
函数关键字
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.
- 注释来抑制警告:
# bashsupport disable=BP2003
包含 shebang 的文件不可执行
Displays a warning for files, which have a shebang, but are not executable.
A quick fix is provided to make the file executable.
此检查默认是关闭状态的。
- 注释来抑制警告:
# bashsupport disable=BP1001
可执行文件不包含 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.
此检查默认是关闭状态的。
- 注释来抑制警告:
# bashsupport disable=BP1002
变量无法解析
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
- 注释来抑制警告:
# shellcheck disable=SC2154
Google代码风格指南
缺失 main() 函数
Marks the first top-level command of a file, which should have a main()
function instead.
- 路径:
- BashSupport Pro → 谷歌 Shell 编程风格
- 注释来抑制警告:
# bashsupport disable=BP5001
main() 声明不正确
Marks incorrectly declared main()
functions.
- 路径:
- BashSupport Pro → 谷歌 Shell 编程风格
- 注释来抑制警告:
# bashsupport disable=BP5009
不一致的函数关键字调用
Detect functions, which use the function keyword inconsistently.
- 路径:
- BashSupport Pro → 谷歌 Shell 编程风格
- 注释来抑制警告:
# bashsupport disable=BP5002
不一致的函数调用圆括号
Detect functions, which use the parentheses after the name inconsistently.
- 路径:
- BashSupport Pro → 谷歌 Shell 编程风格
- 注释来抑制警告:
# bashsupport disable=BP5003
文件名风格
Detect files with names, which don’t follow the style guide. File names have to be lowercase with underscores to separate words.
- 路径:
- BashSupport Pro → 谷歌 Shell 编程风格
- 注释来抑制警告:
# bashsupport disable=BP5004
函数名风格
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
.
- 路径:
- BashSupport Pro → 谷歌 Shell 编程风格
- 注释来抑制警告:
# bashsupport disable=BP5005
变量名风格
Detects variables and variable definitions with names, which don’t follow the style guide. Variables have to be lowercase with underscores to separate words.
- 路径:
- BashSupport Pro → 谷歌 Shell 编程风格
- 注释来抑制警告:
# bashsupport disable=BP5006
Shebang 定义
Detects incorrectly defined shebang lines.
Executables must start with #!/bin/bash
and a minimum number of flags.
- 路径:
- BashSupport Pro → 谷歌 Shell 编程风格
- 注释来抑制警告:
# bashsupport disable=BP5007
函数注释
Detect functions with a missing function comment.
- 路径:
- BashSupport Pro → 谷歌 Shell 编程风格
- 注释来抑制警告:
# bashsupport disable=BP5008
bats-core
雷同的bats-core测试
A single .bats
bats-core file must not contain multiple tests of the same name.
- 路径:
- BashSupport Pro → bats-core
- 注释来抑制警告:
# bashsupport disable=BP6001