-
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
Changes from all commits
d0ae6de
afe459a
8f5f95a
4e52521
9cae271
777d937
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,4 +2,4 @@ | |
| "recommendations": [ | ||
| "bierner.markdown-mermaid" | ||
| ] | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| # Files to exempt from whitespace check. Can contain patterns in Python's glob module format. | ||
|
Contributor
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 recommend sticking to gitignore patterns.
Contributor
Author
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 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. |
||
| # Generated files: | ||
| .codegen/_openapi_sha | ||
| .release_metadata.json | ||
| bundle/schema/jsonschema.json | ||
| experimental/python/docs/images/databricks-logo.svg | ||
| **/*.dist-info/METADATA | ||
| **/*.dist-info/WHEEL | ||
|
|
||
| # Binary files | ||
| **/*.zip | ||
| **/*.whl | ||
|
|
||
| # "bundle run" has trailing whitespace: | ||
| acceptance/bundle/integration_whl/*/output.txt | ||
|
|
||
| # "bundle init" has trailing whitespace: | ||
| acceptance/bundle/templates-machinery/helpers-error/output.txt | ||
|
|
||
| # "bundle deploy" with apps has trailing whitespace: | ||
| acceptance/bundle/apps/config_section/output.txt | ||
| integration/bundle/testdata/apps/bundle_deploy.txt | ||
|
|
||
| # Extra whitespace within the default template: | ||
| acceptance/bundle/templates/default-python/classic/out.compare-vs-serverless.diff | ||
| acceptance/bundle/templates/default-python/classic/output/my_default_python/resources/my_default_python.job.yml | ||
| acceptance/bundle/templates/default-python/serverless/output/my_default_python/resources/my_default_python.job.yml | ||
|
|
||
| # Extra whitespace in command help: | ||
| acceptance/cmd/workspace/apps/output.txt | ||
|
|
||
| # Extra whitespace in generated commands: | ||
| cmd/workspace/**/*.go | ||
| cmd/account/**/*.go | ||
|
|
||
| # Extra whitespace in generated Python models | ||
| experimental/python/databricks/bundles/*/_models/*.py | ||
|
|
||
| # Developed elsewhere: | ||
| internal/genkit/tagging.py | ||
|
|
||
| # Docsgen: | ||
| bundle/docsgen/output/resources.md | ||
| bundle/docsgen/output/reference.md | ||
| bundle/docsgen/testdata/anchors.md | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,4 +6,3 @@ resources: | |
| cluster1: | ||
| cluster_name: "DEFAULT Test Cluster" | ||
| spark_version: '16.2.x-scala2.12' | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,4 +5,3 @@ resources: | |
| experiments: | ||
| experiment1: | ||
| name: $EXPERIMENT_NAME | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,4 +7,3 @@ resources: | |
| name: $MODEL_NAME | ||
| catalog_name: $CATALOG_NAME | ||
| schema_name: $SCHEMA_NAME | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,4 +7,3 @@ resources: | |
| name: $SCHEMA_NAME | ||
| catalog_name: main | ||
| comment: This schema was created from DABs | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,3 @@ | ||
| include: | ||
| - b.yml | ||
| - c.yml | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,4 +4,4 @@ Hello! | |
| "userName": "[USERNAME]" | ||
| } | ||
|
|
||
| Footer | ||
| Footer | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,4 +4,4 @@ Hello! | |
| "userName": "[USERNAME]" | ||
| } | ||
|
|
||
| Footer | ||
| Footer | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| Main-Class: PrintArgs | ||
| Main-Class: PrintArgs |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,4 +10,3 @@ resources: | |
| name: test-schema-{{.unique_id}} | ||
| catalog_name: main | ||
| comment: This schema was created from DABs | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| #!/usr/bin/env python3 | ||
| import os | ||
| import re | ||
| import sys | ||
| import glob | ||
| import subprocess | ||
|
|
||
|
|
||
| def load_ignores(): | ||
| ignores = set() | ||
| fail = False | ||
| for ind, line in enumerate(open(".wsignore")): | ||
| line = line.strip() | ||
| if not line: | ||
| continue | ||
| if line.startswith("#"): | ||
| continue | ||
| expanded = glob.glob(line, recursive=True) | ||
| if len(expanded) == 0: | ||
| print(f".wsignore:{ind + 1}: No matches for line: {line}") | ||
| fail = True | ||
| ignores.update(expanded) | ||
| if fail: | ||
| sys.exit(1) | ||
| return ignores | ||
|
|
||
|
|
||
| def count_trailing_newlines(s): | ||
| match = re.search(r"(\n+)$", s) | ||
| return len(match.group(1)) if match else 0 | ||
|
|
||
|
|
||
| def validate_contents(data): | ||
| if not data: | ||
| return | ||
| try: | ||
| text = data.decode("utf") | ||
| except Exception as ex: | ||
| yield f" Failed to decode utf-8: {ex}" | ||
| return | ||
|
|
||
| for i, line in enumerate(text.split("\n")): | ||
| if not line: | ||
| continue | ||
| if line.strip() == "": | ||
| yield f"{i + 1}: Whitespace-only line" | ||
| continue | ||
| if line.rstrip() != line: | ||
| yield f"{i + 1}: Trailing whitespace {line[-200:]!r}" | ||
|
|
||
| newlines = count_trailing_newlines(text) | ||
|
|
||
| if newlines == 0: | ||
| yield " File does not end with a newline" | ||
|
|
||
| if newlines >= 2: | ||
| yield f" {newlines} newlines at the end" | ||
|
|
||
|
|
||
| def main(): | ||
| quiet = "-q" in sys.argv | ||
| files = subprocess.check_output(["git", "ls-files"], encoding="utf-8").split() | ||
|
Contributor
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. You can run
Contributor
Author
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. Does not work, it seems to be applied to untracked files only: |
||
| ignores = load_ignores() | ||
| n_checked = 0 | ||
| n_skipped = 0 | ||
| n_errored = 0 | ||
| for f in files: | ||
| if not os.path.isfile(f): | ||
| n_skipped += 1 | ||
| continue | ||
| if f in ignores: | ||
| n_skipped += 1 | ||
| continue | ||
| data = open(f, "rb").read() | ||
| error = False | ||
| for msg in validate_contents(data): | ||
| print(f"{f}:{msg}") | ||
| error = True | ||
| n_checked += 1 | ||
| n_errored += 1 if error else 0 | ||
|
|
||
| if not quiet: | ||
| sys.stderr.write(f"{n_checked} checked, {n_skipped} skipped, {n_errored} failed.\n") | ||
| sys.exit(1 if n_errored else 0) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| try: | ||
| main() | ||
| except BrokenPipeError: | ||
| sys.exit(1) | ||
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).