Enforce function declaration format in bash8
Check that function calls look like ^function foo {$ in bash8, and fix
all existing failures of that check. Add a note to HACKING.rst
Change-Id: Ic19eecb39e0b20273d1bcd551a42fe400d54e938
(cherry picked from commit aee18c749b0e3a1a3a6907a33db76ae83b8d41d9)
This commit is contained in:
committed by
Mathew Odden
parent
5e4f348a07
commit
c3da6319ec
16
bash8.py
16
bash8.py
@@ -102,6 +102,21 @@ def check_indents(line):
|
||||
if (len(m.group('indent')) % 4) != 0:
|
||||
print_error('E003: Indent not multiple of 4', line)
|
||||
|
||||
def check_function_decl(line):
|
||||
failed = False
|
||||
if line.startswith("function"):
|
||||
if not re.search('^function [\w-]* \{$', line):
|
||||
failed = True
|
||||
else:
|
||||
# catch the case without "function", e.g.
|
||||
# things like '^foo() {'
|
||||
if re.search('^\s*?\(\)\s*?\{', line):
|
||||
failed = True
|
||||
|
||||
if failed:
|
||||
print_error('E020: Function declaration not in format '
|
||||
' "^function name {$"', line)
|
||||
|
||||
|
||||
def starts_multiline(line):
|
||||
m = re.search("[^<]<<\s*(?P<token>\w+)", line)
|
||||
@@ -169,6 +184,7 @@ def check_files(files, verbose):
|
||||
check_indents(logical_line)
|
||||
check_for_do(logical_line)
|
||||
check_if_then(logical_line)
|
||||
check_function_decl(logical_line)
|
||||
|
||||
prev_line = logical_line
|
||||
prev_lineno = fileinput.filelineno()
|
||||
|
||||
Reference in New Issue
Block a user