This repository was archived by the owner on Apr 26, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Add option to scripts-dev/lint.sh to only lint files changed since the last git commit #8472
Merged
Merged
Changes from 4 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
6a8bc76
Add -d option to ./scripts-dev/lint.sh to only lint changed files
anoadragon453 4d077bb
Update CONTRIBUTING with new lint.sh features
anoadragon453 36b3cc8
Changelog
anoadragon453 59ebd67
Print linted paths on a single line separated by spaces
anoadragon453 06226ef
Print and exit if no changed files were found while using -d
anoadragon453 16c2f54
feature -> misc
anoadragon453 e51baae
Clearer help text
anoadragon453 5fb02c9
Lint setup.py as well.
anoadragon453 90d195f
Fix linting issues in setup.py
anoadragon453 0056945
Move diff logic outside of the getopts loop
anoadragon453 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Add `-d` option to `./scripts-dev/lint.sh` to lint files that have changed since the last git commit. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| #!/bin/sh | ||
| #!/bin/bash | ||
| # | ||
| # Runs linting scripts over the local Synapse checkout | ||
| # isort - sorts import statements | ||
|
|
@@ -7,15 +7,79 @@ | |
|
|
||
| set -e | ||
|
|
||
| if [ $# -ge 1 ] | ||
| then | ||
| files=$* | ||
| else | ||
| files="synapse tests scripts-dev scripts contrib synctl" | ||
| usage() { | ||
| echo | ||
anoadragon453 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| echo "Usage: $0 [-h] [-d] [paths...]" | ||
| echo | ||
| echo "-d" | ||
| echo " Lint files that have changed since the last git commit." | ||
| echo | ||
| echo " If paths are provided and this option is set, both provided paths and those" | ||
| echo " that have changed since the last commit will be linted." | ||
| echo | ||
| echo " If no paths are provided and this option is not set, all files will be linted." | ||
| echo | ||
| echo " Note that paths will be excluded if they both have a file extension, and it is not 'py'." | ||
anoadragon453 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| echo "-h" | ||
| echo " Display this help text." | ||
| } | ||
|
|
||
| USING_DIFF=0 | ||
| files=() | ||
|
|
||
| while getopts ":dh" opt; do | ||
| case $opt in | ||
| d) | ||
| USING_DIFF=1 | ||
|
|
||
| # Check both staged and non-staged changes | ||
anoadragon453 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| for path in $(git diff HEAD --name-only); do | ||
| filename=$(basename "$path") | ||
| file_extension="${filename##*.}" | ||
|
|
||
| # If an extension is present, and it's something other than 'py', | ||
| # then ignore this file | ||
| if [[ -n ${file_extension+x} && $file_extension != "py" ]]; then | ||
| continue | ||
| fi | ||
|
|
||
| # Append this path to our list of files to lint | ||
| files+=("$path") | ||
| done | ||
| ;; | ||
| h) | ||
| usage | ||
| exit | ||
| ;; | ||
| \?) | ||
| echo "ERROR: Invalid option: -$OPTARG" >&2 | ||
| usage | ||
| exit | ||
| ;; | ||
| esac | ||
| done | ||
|
|
||
| # Strip any options from the command line arguments now that | ||
| # we've finished processing them | ||
| shift "$((OPTIND-1))" | ||
|
|
||
| # Append any remaining arguments as files to lint | ||
| files+=("$@") | ||
|
Comment on lines
+68
to
+69
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it feels to me like trying to mix There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suppose there's not much use-case for it... though I'm not sure if we explicitly need to block it either. There may a random case where someone might want to do so. |
||
|
|
||
| # If we were not asked to lint changed files, and no paths were found as a result, | ||
| # then lint everything! | ||
| if [[ $USING_DIFF -eq 0 && -z ${files+x} ]]; then | ||
| # Lint all source code files and directories | ||
| files=("synapse" "tests" "scripts-dev" "scripts" "contrib" "synctl") | ||
| fi | ||
|
|
||
| echo "Linting these locations: $files" | ||
| isort $files | ||
| python3 -m black $files | ||
| echo "Linting these paths: ${files[*]}" | ||
| echo | ||
|
|
||
| # Print out the commands being run | ||
| set -x | ||
|
|
||
| isort "${files[@]}" | ||
| python3 -m black "${files[@]}" | ||
| ./scripts-dev/config-lint.sh | ||
| flake8 $files | ||
| flake8 "${files[@]}" | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.