Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upAdd linting for shell scripts #12295
Conversation
highfive
commented
Jul 6, 2016
|
Heads up! This PR modifies the following files:
|
|
I'd appreciate it if someone took a particularly close look at my changes to |
|
R? @aneeshusa |
| TARGET_DIR="${OUT_DIR}/../../.." | ||
| arm-linux-androideabi-gcc "$@" \ | ||
| "${LDFLAGS}" \ | ||
| -lc \ |
This comment has been minimized.
This comment has been minimized.
aneeshusa
Jul 18, 2016
Member
Let's put the LDFLAGS, lc and shared flags on the same line since they're all linker arguments.
| "${LDFLAGS}" \ | ||
| -lc \ | ||
| -o "${TARGET_DIR}/libservo.so" \ | ||
| -shared && touch "${TARGET_DIR}/servo" |
This comment has been minimized.
This comment has been minimized.
aneeshusa
Jul 18, 2016
Member
The touch can be on a separate line as a separate command (without the && in between), as the set -o errexit will handle not running the command if gcc fails.
| # Make sure listed files do not contain "unwrap" | ||
|
|
||
| set -o errexit | ||
| set -o nounset | ||
| set -o pipefail | ||
|
|
||
| cd "$(git rev-parse --show-toplevel)" # cd into repo root so make sure paths works in any case | ||
| # cd into repo root to make sure paths works in any case |
This comment has been minimized.
This comment has been minimized.
|
|
||
| for idx, line in enumerate(lines): | ||
| if idx == 0: | ||
| if not line.startswith(shebang): |
This comment has been minimized.
This comment has been minimized.
| for idx, line in enumerate(lines): | ||
| if idx == 0: | ||
| if not line.startswith(shebang): | ||
| yield (idx + 1, 'script does not start with "{}"'.format(shebang)) |
This comment has been minimized.
This comment has been minimized.
| else: | ||
| # The first non-comment, non-whitespace, non-option line is the first "real" line of the script. | ||
| # The shebang, options, etc. must come before this. | ||
| found_script_statement = True |
This comment has been minimized.
This comment has been minimized.
aneeshusa
Jul 18, 2016
Member
I think you can get rid of found_script_statement and just break after the if len(required_options) != 0 block, instead of doing it on the next iteration.
| found_script_statement = False | ||
|
|
||
| for idx, line in enumerate(lines): | ||
| if idx == 0: |
This comment has been minimized.
This comment has been minimized.
aneeshusa
Jul 18, 2016
Member
I think it would be cleaner to check the first line outside (before) the loop; that takes away a level of nesting inside the for and means we don't need enumerate anymore.
| formatted = [] | ||
|
|
||
| for opt in required_options: | ||
| formatted.append('"{}"'.format(opt)) |
This comment has been minimized.
This comment has been minimized.
This makes the changes suggested in servo#12295. The python code to lint shell scripts is cleans up generally and some shell scripts are changed to be more readable.
|
No merge commits, please. Use rebase instead. |
fe73796
to
2206ee6
|
Cool, I've gone ahead and rebased. |
| @@ -16,7 +20,8 @@ cp etc/doc.servo.org/* target/doc/ | |||
|
|
|||
| python components/style/properties/build.py servo html | |||
|
|
|||
| OUT_DIR="`pwd`/target/doc/servo" make -f makefile.cargo -C components/script dom_docs | |||
| OUT_DIR="`pwd`/target/doc/servo" \ | |||
This comment has been minimized.
This comment has been minimized.
| shebang = "#!/usr/bin/env bash" | ||
| required_options = {"set -o errexit", "set -o nounset", "set -o pipefail"} | ||
|
|
||
| if lines[0].strip() != shebang: |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
| # The shebang, options, etc. must come before this. | ||
| if len(required_options) != 0: | ||
| formatted = ['"{}"'.format(opt) for opt in required_options] | ||
|
|
This comment has been minimized.
This comment has been minimized.
Add linting for shell scripts <!-- Please describe your changes on the following line: --> This changes tidy to check shell scripts for the proper shebang and options. It does not check that variables are formatted correctly. It also adds a check for the MPL 2.0 license in shell scripts. --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [X] These changes fix #12158 (github issue number if applicable). <!-- Either: --> - [X] There are tests for these changes OR - [ ] These changes do not require tests because _____ <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/12295) <!-- Reviewable:end -->
|
|
|
|
||
| TARGET_DIR="${OUT_DIR}/../../.." | ||
| arm-linux-androideabi-gcc "$@" \ | ||
| "${LDFLAGS}" -lc -shared \ |
This comment has been minimized.
This comment has been minimized.
aneeshusa
Jul 22, 2016
Member
LDFLAGS is not always set, so we need to give it a default value if it isn't. A bash parameter expansion should do the trick.
This comment has been minimized.
This comment has been minimized.
This changes tidy to check shell scripts for the proper shebang and options. It does not check that variables are formatted correctly. It also adds a check for the MPL 2.0 license in shell scripts.
8800af2
to
7952bd0
|
@bors-servo r=aneeshusa |
|
|
Add linting for shell scripts <!-- Please describe your changes on the following line: --> This changes tidy to check shell scripts for the proper shebang and options. It does not check that variables are formatted correctly. It also adds a check for the MPL 2.0 license in shell scripts. --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [X] These changes fix #12158 (github issue number if applicable). <!-- Either: --> - [X] There are tests for these changes OR - [ ] These changes do not require tests because _____ <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/12295) <!-- Reviewable:end -->
|
|
|
@bors-servo retry
|
Add linting for shell scripts <!-- Please describe your changes on the following line: --> This changes tidy to check shell scripts for the proper shebang and options. It does not check that variables are formatted correctly. It also adds a check for the MPL 2.0 license in shell scripts. --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [X] These changes fix #12158 (github issue number if applicable). <!-- Either: --> - [X] There are tests for these changes OR - [ ] These changes do not require tests because _____ <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/12295) <!-- Reviewable:end -->
|
|
jimberlage commentedJul 6, 2016
•
edited
This changes tidy to check shell scripts for the proper shebang and
options. It does not check that variables are formatted correctly. It
also adds a check for the MPL 2.0 license in shell scripts.
./mach build -ddoes not report any errors./mach test-tidydoes not report any errorsThis change is