-
Notifications
You must be signed in to change notification settings - Fork 122
Enforce no trailing whitespace #2603
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
Conversation
93fb2e6 to
d0ae6de
Compare
| version: "0.9.1" | ||
| args: "format --check" | ||
| - name: Run whitespace check | ||
| run: python tools/validate_whitespace.py |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would make for a good custom GH action (for a rainy day).
| @@ -0,0 +1,45 @@ | |||
| # Files to exempt from whitespace check. Can contain patterns in Python's glob module format. | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I recommend sticking to gitignore patterns.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, that would be nicer. I wanted something that is part of stdlib so we can just run it with system Python (not even uv needed).
Update: saw your comment about --exclude-from, going to try that.
|
|
||
| def main(): | ||
| quiet = "-q" in sys.argv | ||
| files = subprocess.check_output(["git", "ls-files"], encoding="utf-8").split() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can run git ls-files --exclude-from= to let Git take care of exclusion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does not work, it seems to be applied to untracked files only:
-x <pattern>, --exclude=<pattern>
Skip untracked files matching pattern. Note that pattern is a shell
wildcard pattern. See EXCLUDE PATTERNS below for more information.
-X <file>, --exclude-from=<file>
Read exclude patterns from <file>; 1 per line.
tools/validate_whitespace.py
Outdated
| return | ||
|
|
||
| count = 0 | ||
| max_trailing_errors = 9 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some files have too many of these, polluting the output.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On second thought, we can live without this and it simplifies the code: 9cae271
Also use 'make ws' in github action. Follow up to #2603
Also use 'make ws' in github action. Follow up to #2603
Also use 'make ws' in github action. Follow up to #2603
## Changes This mirrors databricks/cli#2603. I ran into this when working on `jobs/resource_job_test.go`. My editor trims trailing whitespace on save and I got a dozen diffs related to this. Enforcing no trailing whitespace reduces this noise. ## Tests - `make ws` is run for PRs to ensure new code doesn't violate this - The VS Code settings are updated to trim trailing whitespace on save. <!-- NO_CHANGELOG=true //-->
Changes
Why
This is best practice that helps with editing and reduces noise on diffs.
I'm using custom script because I want this check across different languages, configs, templates.