Google Shell Style Guide Support
Google maintains a comprehensive shell style guide. It defines how to write Bash scripts at Google. For everyone else, it’s sound advice and a wonderful, clearly defined guide for better collaboration. If you want to establish a coding style for Bash scripts, then this is a great start.
BashSupport Pro provides a formatter preset and inspections to detect code not following the rules. All inspections provide quick fixes for the warnings they show in your editor. The coverage of the style guide will be extended in the future – for now the most important rules are implemented.
Enabling Google Style Guide Support
The support for the style guide is turned off by default. First, you need to enable it to use it. You can find the settings at Settings… → Editor → Code Style → BashSupport Pro.
Enabling the setting Follow Google Shell Style Guide turns on a formatter preset and also the inspections and quick fixes for the style guide.
Inspections
The following inspections are only active with the enabled Google Style Guide support.
If you want to use an inspection without turning on the code style, then you can disable the setting “Only with configured Google shell code style” for this particular inspection. This setting is available for each of the style guide inspections at Settings… → Editor → Inspections → BashSupport Pro → Google Shell Style Guide.
File Name Style
This inspection highlights incorrectly named files. A quick fix allows to automatically rename the file and all references to it.
Function Comments
This inspection highlights functions, which don’t have the required comments. A quick fix will automatically create it for you.
Function Name Style
This inspection highlights incorrectly named functions. A quick fix allows to rename the function and all references to it.
Inconsistent Function Keyword Usage
This inspection highlights inconsistent use of the function
keyword. A quick fix allows to add the keyword.
Inconsistent Function Parentheses Usage
This inspection highlights inconsistent use of the ()
parentheses after a function name. A quick fix allows to add the parentheses to the file.
Missing main() Function
This inspection highlights the first instruction at the top-level of a file, which should be wrapped into a main()
function.
The provided quick fix will automatically create a main()
function in the file and move all top-level instructions into it.
Incorrect main() Declaration
This inspection highlights declarations of main()
which are declared at the wrong position in a file.
A quick fix allows to move the declaration and all calls inside the file to the end of the file.
Shebang Definition
This inspection highlights incorrectly defined shebang lines. A quick fix allows to change the shebang line to the required #!/bin/bash
.
Variable Name Style
This inspection highlights bad variable names. A quick fix allows to change the variable name and all references to the required lowercase name.