Skip to content

Conversation

@denik
Copy link
Contributor

@denik denik commented Mar 31, 2025

Changes

  • Add tools/validate_whitespace.py that checks all the files in the repo for:
    • Trailing whitespace.
    • Lack of newline in the end.
    • Too many newlines in the end.
    • Exceptions can be specified in .wsignore as glob patterns (with "**" support).
  • Fix some of the issues.
  • Add the rest to .wsignore as known violations. To be addressed in follow up PRs.

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.

@denik denik temporarily deployed to test-trigger-is March 31, 2025 15:11 — with GitHub Actions Inactive
@denik denik force-pushed the denik/whitespace-check branch from 93fb2e6 to d0ae6de Compare March 31, 2025 15:16
@denik denik temporarily deployed to test-trigger-is March 31, 2025 15:16 — with GitHub Actions Inactive
@denik denik marked this pull request as ready for review March 31, 2025 15:17
@denik denik temporarily deployed to test-trigger-is March 31, 2025 16:32 — with GitHub Actions Inactive
@denik denik temporarily deployed to test-trigger-is March 31, 2025 16:36 — with GitHub Actions Inactive
@denik denik temporarily deployed to test-trigger-is April 1, 2025 09:08 — with GitHub Actions Inactive
version: "0.9.1"
args: "format --check"
- name: Run whitespace check
run: python tools/validate_whitespace.py
Copy link
Contributor

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.
Copy link
Contributor

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.

Copy link
Contributor Author

@denik denik Apr 1, 2025

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()
Copy link
Contributor

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.

Copy link
Contributor Author

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.

return

count = 0
max_trailing_errors = 9
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why?

Copy link
Contributor Author

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.

Copy link
Contributor Author

@denik denik Apr 1, 2025

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

@denik denik temporarily deployed to test-trigger-is April 1, 2025 10:26 — with GitHub Actions Inactive
@denik denik temporarily deployed to test-trigger-is April 1, 2025 10:27 — with GitHub Actions Inactive
@denik denik enabled auto-merge April 1, 2025 10:29
@denik denik added this pull request to the merge queue Apr 1, 2025
Merged via the queue into main with commit 5770828 Apr 1, 2025
15 checks passed
@denik denik deleted the denik/whitespace-check branch April 1, 2025 11:10
denik added a commit that referenced this pull request Apr 2, 2025
Also use 'make ws' in github action.

Follow up to #2603
denik added a commit that referenced this pull request Apr 2, 2025
Also use 'make ws' in github action.

Follow up to #2603
github-merge-queue bot pushed a commit that referenced this pull request Apr 2, 2025
Also use 'make ws' in github action.

Follow up to #2603
github-merge-queue bot pushed a commit to databricks/terraform-provider-databricks that referenced this pull request Jul 14, 2025
## 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
//-->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants