summaryrefslogtreecommitdiff
path: root/usr/src/tools
diff options
context:
space:
mode:
authorAndy Fiddaman <omnios@citrus-it.co.uk>2021-01-25 15:52:15 +0000
committerAndy Fiddaman <omnios@citrus-it.co.uk>2021-02-05 10:49:19 +0000
commit13904da86c95bce026575f75b430075604bb28e4 (patch)
treebea4411aa6193c49bcf559dc57141f057d2da5fe /usr/src/tools
parent3c2328bf3bf6527c6b28445336d32183a277b1e1 (diff)
downloadillumos-joyent-13904da86c95bce026575f75b430075604bb28e4.tar.gz
13474 pbchk could lint shell scripts
Reviewed by: Toomas Soome <tsoome@me.com> Reviewed by: Alexander Eremin <aeremin@tintri.com> Approved by: Robert Mustacchi <rm@fingolfin.org>
Diffstat (limited to 'usr/src/tools')
-rw-r--r--usr/src/tools/onbld/Checks/Makefile.com3
-rw-r--r--usr/src/tools/onbld/Checks/ShellLint.py42
-rw-r--r--usr/src/tools/onbld/Checks/__init__.py2
-rw-r--r--usr/src/tools/scripts/git-pbchk.py25
4 files changed, 70 insertions, 2 deletions
diff --git a/usr/src/tools/onbld/Checks/Makefile.com b/usr/src/tools/onbld/Checks/Makefile.com
index e8872e8ca8..74f5e2dbfe 100644
--- a/usr/src/tools/onbld/Checks/Makefile.com
+++ b/usr/src/tools/onbld/Checks/Makefile.com
@@ -26,7 +26,7 @@
# Copyright 2010, Richard Lowe
# Copyright 2014 Garrett D'Amore <garrett@damore.org>
# Copyright 2016, Joyent, Inc.
-# Copyright 2018 OmniOS Community Edition (OmniOSce) Association.
+# Copyright 2021 OmniOS Community Edition (OmniOSce) Association.
include $(SRC)/Makefile.master
include ../../../Makefile.tools
@@ -47,6 +47,7 @@ PYSRCS = \
ManLint.py \
Mapfile.py \
ProcessCheck.py \
+ ShellLint.py \
SpellCheck.py \
WsCheck.py \
__init__.py
diff --git a/usr/src/tools/onbld/Checks/ShellLint.py b/usr/src/tools/onbld/Checks/ShellLint.py
new file mode 100644
index 0000000000..06d06f92c8
--- /dev/null
+++ b/usr/src/tools/onbld/Checks/ShellLint.py
@@ -0,0 +1,42 @@
+#
+# This file and its contents are supplied under the terms of the
+# Common Development and Distribution License ("CDDL"), version 1.0.
+# You may only use this file in accordance with the terms of version
+# 1.0 of the CDDL.
+#
+# A full copy of the text of the CDDL should have accompanied this
+# source. A copy of the CDDL is also available via the Internet at
+# http://www.illumos.org/license/CDDL.
+#
+
+#
+# Copyright 2021 OmniOS Community Edition (OmniOSce) Association.
+#
+
+#
+# ShellLint, wrap the 'shcomp -n' tool in a python API
+#
+
+import sys
+from onbld.Checks.ProcessCheck import processcheck
+
+def lint(fh, filename=None, output=sys.stderr, **opts):
+ if not filename:
+ filename = fh.name
+
+ options = ['-n', '/dev/stdin', '/dev/null']
+
+ ret, tmpfile = processcheck('shcomp', options, fh, output)
+
+ if tmpfile:
+ for line in tmpfile:
+ if '`...` obsolete' in line:
+ continue
+ ret = 1
+
+ line = line.replace('/dev/stdin', filename)
+ line = line.replace('warning: ', '')
+ output.write(line)
+
+ tmpfile.close()
+ return ret
diff --git a/usr/src/tools/onbld/Checks/__init__.py b/usr/src/tools/onbld/Checks/__init__.py
index 9f0611d969..775c5a6e66 100644
--- a/usr/src/tools/onbld/Checks/__init__.py
+++ b/usr/src/tools/onbld/Checks/__init__.py
@@ -27,6 +27,7 @@
# Copyright 2010, Richard Lowe
# Copyright 2014 Garrett D'Amore <garrett@damore.org>
+# Copyright 2021 OmniOS Community Edition (OmniOSce) Association.
#
# The 'checks' package contains various checks that may be run
@@ -42,5 +43,6 @@ __all__ = [
'Keywords',
'ManLint',
'Mapfile',
+ 'ShellLint',
'SpellCheck',
'WsCheck']
diff --git a/usr/src/tools/scripts/git-pbchk.py b/usr/src/tools/scripts/git-pbchk.py
index ec01255c6e..fc9f82b816 100644
--- a/usr/src/tools/scripts/git-pbchk.py
+++ b/usr/src/tools/scripts/git-pbchk.py
@@ -21,7 +21,7 @@
# Copyright (c) 2015, 2016 by Delphix. All rights reserved.
# Copyright 2016 Nexenta Systems, Inc.
# Copyright (c) 2019, Joyent, Inc.
-# Copyright 2020 OmniOS Community Edition (OmniOSce) Association.
+# Copyright 2021 OmniOS Community Edition (OmniOSce) Association.
#
from __future__ import print_function
@@ -57,6 +57,7 @@ sys.path.insert(2, os.path.join(os.path.dirname(__file__), ".."))
from onbld.Scm import Ignore
from onbld.Checks import Comments, Copyright, CStyle, HdrChk, WsCheck
from onbld.Checks import JStyle, Keywords, ManLint, Mapfile, SpellCheck
+from onbld.Checks import ShellLint
class GitError(Exception):
pass
@@ -294,6 +295,26 @@ def manlint(root, parent, flist, output):
ret |= SpellCheck.spellcheck(fh, output=output)
return ret
+def shelllint(root, parent, flist, output):
+ ret = 0
+ output.write("Shell lint:\n")
+
+ def isshell(x):
+ (_, ext) = os.path.splitext(x)
+ if ext in ['.sh', '.ksh']:
+ return True
+ if ext == '':
+ with io.open(x, mode='r', errors='ignore') as fh:
+ if re.match(r'^#.*\bk?sh\b', fh.readline()):
+ return True
+ return False
+
+ for f in flist(isshell):
+ with io.open(f, mode='rb') as fh:
+ ret |= ShellLint.lint(fh, output=output)
+
+ return ret
+
def keywords(root, parent, flist, output):
ret = 0
output.write("SCCS Keywords:\n")
@@ -399,6 +420,7 @@ def nits(root, parent, paths):
keywords,
manlint,
mapfilechk,
+ shelllint,
winnames,
wscheck]
scmds = [symlinks]
@@ -413,6 +435,7 @@ def pbchk(root, parent, paths):
keywords,
manlint,
mapfilechk,
+ shelllint,
winnames,
wscheck]
scmds = [symlinks]