Ian Wienand c977b0827d Add a [[ checker
This adds a basic check for [[ when using non-POSIX comparisions such
as =~, <, >.  This is a fairly common typo often not picked up until
runtime.  Since it's usually part of an "if [ $foo =~ bar ]; then"
statement it doesn't trigger "-e" and the failure just falls through.

As mentioned in the code; this is one of those things that starts
requiring a complete bash parser to get 100% right.  However, I
believe this detects the most common failures without setting off
false alarms.

Change-Id: I5478032800cdf175cb10ce25dc8b6afce6ebd0dd
2017-08-29 14:14:31 +10:00
2017-08-29 14:14:31 +10:00
2017-07-21 08:43:47 +02:00
2014-07-15 21:02:59 -05:00
2014-04-23 00:06:39 -05:00
2014-04-23 00:06:39 -05:00
2014-04-23 00:06:39 -05:00
2014-10-14 10:22:25 +11:00
2017-08-29 14:14:31 +10:00
2017-07-21 08:43:47 +02:00
2017-07-21 08:54:46 +02:00
2016-01-05 08:38:31 +01:00
2017-04-06 09:20:27 -05:00

bashate

A pep8 equivalent for bash scripts

This program attempts to be an automated style checker for bash scripts to fill the same part of code review that pep8 does in most OpenStack projects. It started from humble beginnings in the DevStack project, and will continue to evolve over time.

Currently Supported Checks

Errors

Basic white space errors, for consistent indenting

  • E001: check that lines do not end with trailing whitespace
  • E002: ensure that indents are only spaces, and not hard tabs
  • E003: ensure all indents are a multiple of 4 spaces
  • E004: file did not end with a newline
  • E005: file does not begin with #! or have a .sh prefix
  • E006: check for lines longer than 79 columns

Structure Errors

A set of rules that help keep things consistent in control blocks. These are ignored on long lines that have a continuation, because unrolling that is kind of "interesting"

  • E010: do not on the same line as for
  • E011: then not on the same line as if or elif
  • E012: heredoc didn't end before EOF
  • E020: Function declaration not in format ^function name {$

Obsolete, deprecated or unsafe syntax

Rules to identify obsolete, deprecated or unsafe syntax that should not be used

  • E040: Syntax errors reported by bash -n
  • E041: Usage of $[ for arithmetic is deprecated for $((
  • E042: local declaration hides errors
  • E043: arithmetic compound has inconsistent return semantics
  • E044: Use [[ for =~,<,> comparisions

See also

See also /man/bashate.

Description
Code style enforcement for bash programs.
Readme 1.6 MiB
Languages
Python 90.5%
Shell 9.5%