Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add linting for shell scripts #12295

Merged
merged 1 commit into from Aug 4, 2016
Merged

Conversation

@jimberlage
Copy link
Contributor

jimberlage commented Jul 6, 2016

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 -d does not report any errors
  • ./mach test-tidy does not report any errors
  • These changes fix #12158 (github issue number if applicable).
  • There are tests for these changes OR
  • These changes do not require tests because _____

This change is Reviewable

@highfive
Copy link

highfive commented Jul 6, 2016

Heads up! This PR modifies the following files:

  • @wafflespeanut: python/tidy/servo_tidy_tests/test_tidy.py, python/tidy/servo_tidy/licenseck.py, python/tidy/servo_tidy/tidy.py, python/tidy/servo_tidy_tests/shell_tidy.sh
  • @aneeshusa: etc/ci/check_no_unwrap.sh, etc/ci/manifest_changed.sh, etc/ci/upload_docs.sh, etc/ci/upload_nightly.sh, etc/ci/lockfile_changed.sh
@jimberlage
Copy link
Contributor Author

jimberlage commented Jul 6, 2016

I'd appreciate it if someone took a particularly close look at my changes to components/servo/fake-ld.sh; I don't have the bash expertise to tell if those changes are totally correct.

@jimberlage jimberlage mentioned this pull request Jul 6, 2016
3 of 5 tasks complete
@jimberlage
Copy link
Contributor Author

jimberlage commented Jul 10, 2016

@Ms2ger could you re-run tests on this? They failed the first time because tidy was changed in between my initial checkout and this PR to test a few more files, and that exposed some out-of-spec shell scripts. That's since been fixed in #12299.

@Ms2ger Ms2ger closed this Jul 10, 2016
@Ms2ger Ms2ger reopened this Jul 10, 2016
@Ms2ger
Copy link
Contributor

Ms2ger commented Jul 10, 2016

@aneeshusa aneeshusa assigned aneeshusa and unassigned Ms2ger Jul 11, 2016
TARGET_DIR="${OUT_DIR}/../../.."
arm-linux-androideabi-gcc "$@" \
"${LDFLAGS}" \
-lc \

This comment has been minimized.

@aneeshusa

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.

@aneeshusa

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.

@aneeshusa

aneeshusa Jul 18, 2016

Member

grammar: works -> work


for idx, line in enumerate(lines):
if idx == 0:
if not line.startswith(shebang):

This comment has been minimized.

@aneeshusa

aneeshusa Jul 18, 2016

Member

I think we could use != instead of not and startswith here.

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.

@aneeshusa

aneeshusa Jul 18, 2016

Member

does not start with -> does not have shebang

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.

@aneeshusa

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.

@aneeshusa

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.

@aneeshusa

aneeshusa Jul 18, 2016

Member

Use a list comprehension to inline the loop.

jimberlage pushed a commit to jimberlage/servo that referenced this pull request Jul 22, 2016
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.
@KiChjang
Copy link
Member

KiChjang commented Jul 22, 2016

No merge commits, please. Use rebase instead.

@jimberlage jimberlage force-pushed the jimberlage:12158/shell-linting branch from fe73796 to 2206ee6 Jul 22, 2016
@jimberlage
Copy link
Contributor Author

jimberlage commented Jul 22, 2016

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.

@aneeshusa

aneeshusa Jul 22, 2016

Member

Can you update this to use $(pwd) per the style guide?

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.

@aneeshusa

aneeshusa Jul 22, 2016

Member

Handle the case of an empty file (i.e. lines is empty).

This comment has been minimized.

@aneeshusa

aneeshusa Jul 22, 2016

Member

Also, use rstrip() instead of strip().

# 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.

@aneeshusa

aneeshusa Jul 22, 2016

Member

Remove the empty line.

@bors-servo
Copy link
Contributor

bors-servo commented Jul 22, 2016

Testing commit 8800af2 with merge 7b209e8...

bors-servo added a commit that referenced this pull request Jul 22, 2016
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
Copy link
Contributor

bors-servo commented Jul 22, 2016

💔 Test failed - android


TARGET_DIR="${OUT_DIR}/../../.."
arm-linux-androideabi-gcc "$@" \
"${LDFLAGS}" -lc -shared \

This comment has been minimized.

@aneeshusa

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.

@aneeshusa

aneeshusa Jul 22, 2016

Member

The default value can just be the empty string.

Jim Berlage
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.
@jimberlage jimberlage force-pushed the jimberlage:12158/shell-linting branch from 8800af2 to 7952bd0 Jul 22, 2016
@KiChjang
Copy link
Member

KiChjang commented Jul 22, 2016

@bors-servo r=aneeshusa

@bors-servo
Copy link
Contributor

bors-servo commented Jul 22, 2016

📌 Commit 7952bd0 has been approved by aneeshusa

@bors-servo
Copy link
Contributor

bors-servo commented Jul 22, 2016

Testing commit 7952bd0 with merge a8c41b7...

bors-servo added a commit that referenced this pull request Jul 22, 2016
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
Copy link
Contributor

bors-servo commented Jul 22, 2016

💔 Test failed - android

@aneeshusa
Copy link
Member

aneeshusa commented Aug 4, 2016

@bors-servo retry

  • Logs are gone (probably removed by the old-log-cleanup cron job)
@bors-servo
Copy link
Contributor

bors-servo commented Aug 4, 2016

Testing commit 7952bd0 with merge 4bc629b...

bors-servo added a commit that referenced this pull request Aug 4, 2016
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
Copy link
Contributor

bors-servo commented Aug 4, 2016

@bors-servo bors-servo merged commit 7952bd0 into servo:master Aug 4, 2016
2 checks passed
2 checks passed
continuous-integration/travis-ci/pr The Travis CI build passed
Details
homu Test successful
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

6 participants
You can’t perform that action at this time.