diff --git a/tools/lint/shell/__init__.py b/tools/lint/shell/__init__.py index cf9b2282d799..46a1b0927a4b 100644 --- a/tools/lint/shell/__init__.py +++ b/tools/lint/shell/__init__.py @@ -27,6 +27,7 @@ results = [] class ShellcheckProcess(ProcessHandlerMixin): def __init__(self, config, *args, **kwargs): self.config = config + kwargs['universal_newlines'] = True kwargs['processOutputLine'] = [self.process_line] ProcessHandlerMixin.__init__(self, *args, **kwargs) diff --git a/tools/lint/test/files/shellcheck/bad.sh b/tools/lint/test/files/shellcheck/bad.sh new file mode 100644 index 000000000000..b2eb195558af --- /dev/null +++ b/tools/lint/test/files/shellcheck/bad.sh @@ -0,0 +1,3 @@ +#!/bin/sh +hello="Hello world" +echo $1 diff --git a/tools/lint/test/files/shellcheck/good.sh b/tools/lint/test/files/shellcheck/good.sh new file mode 100644 index 000000000000..e61d50195572 --- /dev/null +++ b/tools/lint/test/files/shellcheck/good.sh @@ -0,0 +1,2 @@ +#!/bin/sh +echo "Hello world" diff --git a/tools/lint/test/python.ini b/tools/lint/test/python.ini index dce95103fa9a..546ad3d58074 100644 --- a/tools/lint/test/python.ini +++ b/tools/lint/test/python.ini @@ -12,3 +12,4 @@ skip-if = os == "win" [test_file_whitespace.py] [test_file_license.py] [test_lintpref.py] +[test_shellcheck.py] diff --git a/tools/lint/test/test_shellcheck.py b/tools/lint/test/test_shellcheck.py new file mode 100644 index 000000000000..c9456ad33214 --- /dev/null +++ b/tools/lint/test/test_shellcheck.py @@ -0,0 +1,24 @@ +import pytest +import mozunit +from mozfile import which + +LINTER = 'shellcheck' +pytestmark = pytest.mark.skipif(not which('shellcheck'), reason="shellcheck is not installed") + + +def test_basic(lint, paths): + results = lint(paths()) + print(results) + assert len(results) == 2 + + assert "hello appears unused" in results[0].message + assert results[0].level == "error" + assert results[0].relpath == "bad.sh" + + assert "Double quote to prevent" in results[1].message + assert results[1].level == "error" + assert results[1].relpath == "bad.sh" + + +if __name__ == '__main__': + mozunit.main()