diff options
author | Aneesh Agrawal <aneeshusa@gmail.com> | 2016-08-04 15:16:04 -0400 |
---|---|---|
committer | Aneesh Agrawal <aneeshusa@gmail.com> | 2016-08-05 09:29:09 -0400 |
commit | 79ef9b4efc307aa0aebfbeb5b0c120a3ad525399 (patch) | |
tree | b551796547a19f22e2877c7a1ad7ad336c31d99b /python/tidy/servo_tidy/tidy.py | |
parent | 4bc629b369242d16675161ab6af8141dab0bb556 (diff) | |
download | servo-79ef9b4efc307aa0aebfbeb5b0c120a3ad525399.tar.gz servo-79ef9b4efc307aa0aebfbeb5b0c120a3ad525399.zip |
Add lint for backticks in shell scripts
The "$(some_command arg1 arg2)" form is preferred to the
`some_command arg1 arg2` form because it nests unambiguously.
Add a lint for this to tidy.
Diffstat (limited to 'python/tidy/servo_tidy/tidy.py')
-rw-r--r-- | python/tidy/servo_tidy/tidy.py | 27 |
1 files changed, 17 insertions, 10 deletions
diff --git a/python/tidy/servo_tidy/tidy.py b/python/tidy/servo_tidy/tidy.py index 34eea7f882a..d47aa0137a0 100644 --- a/python/tidy/servo_tidy/tidy.py +++ b/python/tidy/servo_tidy/tidy.py @@ -318,19 +318,23 @@ def check_shell(file_name, lines): shebang = "#!/usr/bin/env bash" required_options = {"set -o errexit", "set -o nounset", "set -o pipefail"} + did_shebang_check = False + if len(lines) == 0: yield (0, 'script is an empty file') - else: - if lines[0].rstrip() != shebang: - yield (1, 'script does not have shebang "{}"'.format(shebang)) + return + + if lines[0].rstrip() != shebang: + yield (1, 'script does not have shebang "{}"'.format(shebang)) - for idx in range(1, len(lines)): - stripped = lines[idx].rstrip() + for idx in range(1, len(lines)): + stripped = lines[idx].rstrip() + # Comments or blank lines are ignored. (Trailing whitespace is caught with a separate linter.) + if lines[idx].startswith("#") or stripped == "": + continue - # Comments or blank lines are ignored. (Trailing whitespace is caught with a separate linter.) - if lines[idx].startswith("#") or stripped == "": - continue - elif stripped in required_options: + if not did_shebang_check: + if stripped in required_options: required_options.remove(stripped) else: # The first non-comment, non-whitespace, non-option line is the first "real" line of the script. @@ -338,7 +342,10 @@ def check_shell(file_name, lines): if len(required_options) != 0: formatted = ['"{}"'.format(opt) for opt in required_options] yield (idx + 1, "script is missing options {}".format(", ".join(formatted))) - break + did_shebang_check = True + + if "`" in stripped: + yield (idx + 1, "script should not use backticks for command substitution") def check_rust(file_name, lines): |