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.

文件:
普通文本文件
纯文本文件中的Shebang
纯文本文件中的Shebang

局部使用变量

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:

  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
注释来抑制警告:
# 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.

ShellCheck
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 的文件不可执行
包含 shebang 的文件不可执行

可执行文件不包含 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
可执行文件不包含 shebang
可执行文件不包含 shebang

变量无法解析

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() 函数
缺失 main() 函数

main() 声明不正确

Marks incorrectly declared main() functions.

路径:
BashSupport Pro → 谷歌 Shell 编程风格
注释来抑制警告:
# bashsupport disable=BP5009
main() 声明不正确
main() 声明不正确

不一致的函数关键字调用

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
Shebang 定义
Shebang 定义

函数注释

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
雷同的bats-core测试
雷同的bats-core测试
© 2020–2024 Joachim Ansorg
声明
隐私政策
许可条款