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.

Turning on the Google code style support
Turning on the Google code style support

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.

File name inspection
File name inspection

Function Comments

This inspection highlights functions, which don’t have the required comments. A quick fix will automatically create it for you.

Function without the required comment
Function without the required comment

Function Name Style

This inspection highlights incorrectly named functions. A quick fix allows to rename the function and all references to it.

Incorrect function name
Incorrect function name

Inconsistent Function Keyword Usage

This inspection highlights inconsistent use of the function keyword. A quick fix allows to add the keyword.

Inconsistent use of the function keyword
Inconsistent use of the function 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.

Inconsistent use of ()
Inconsistent use of ()

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.

Instruction which should be inside main()
Instruction which should be inside main()

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.

main() declared at the wrong position
main() declared at the wrong position

Shebang Definition

This inspection highlights incorrectly defined shebang lines. A quick fix allows to change the shebang line to the required #!/bin/bash.

Wrong shebang line
Wrong shebang line

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.

Incorrectly named variable
Incorrectly named variable
© 2020–2024 Joachim Ansorg
Impressum
Datenschutz
Rechtliches