Skip to content

Commit

Permalink
lint.py: forbid trailing whitespace and missing ending newline
Browse files Browse the repository at this point in the history
Well-configured editors trim trailing whitespace and always
end each file with a newline. We should enforce that, otherwise
we end up with spurious diffs (like this one) when one person
edits a file, and then another.

Trailing whitspace only makes sense if you are programming in
[whitespace](https://en.wikipedia.org/wiki/Whitespace_(programming_language))
  • Loading branch information
emilk committed Jul 12, 2023
1 parent d33c644 commit e779802
Show file tree
Hide file tree
Showing 16 changed files with 35 additions and 21 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/manual_adhoc_web.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
RRD_ARTIFACT_NAME: linux-rrd-fast
UPLOAD_COMMIT: false
secrets: inherit

build-web-demo-adhoc:
name: 'Build Web Demo'
needs: [min-test-wheel, build-web-adhoc]
Expand All @@ -56,7 +56,7 @@ jobs:
CONCURRENCY: adhoc-web-${{ github.event.inputs.ADHOC_NAME }}
WHEEL_ARTIFACT_NAME: linux-wheel
secrets: inherit

upload-web-demo:
name: 'Upload Web Demo'
needs: [build-web-demo-adhoc]
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/reusable_build_and_test_wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ jobs:
# --target x86_64-unknown-linux-gnu because otherwise cargo loses the target cache... even though this is the target anyhow...
# --no-build because rerun-sdk is already built and installed
# NOTE: run with --release so we can reuse some of the "Build Wheel"'s job artifacts, hopefully
run: RUST_LOG=debug scripts/ci/run_e2e_roundtrip_tests.py --release --target x86_64-unknown-linux-gnu --no-build
run: RUST_LOG=debug scripts/ci/run_e2e_roundtrip_tests.py --release --target x86_64-unknown-linux-gnu --no-build

- name: Cache RRD dataset
if: needs.set-config.outputs.RUN_TESTS == 'true'
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
.DS_Store

# C++ and CMake stuff:
**/CMakeFiles/
**/build/

# Rust compile target directory:
**/target
**/target_ra
Expand Down
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
[Rerun](https://www.rerun.io/) is an easy-to-use visualization toolbox for computer vision and robotics.

* Python: `pip install rerun-sdk`
* Rust: `cargo add rerun` and `cargo install rerun-cli`
* Rust: `cargo add rerun` and `cargo install rerun-cli`
* Online demo: <https://app.rerun.io/version/0.7.0/index.html>

### Overview & Highlights
Expand Down
2 changes: 1 addition & 1 deletion crates/re_build_tools/src/hashing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ pub fn write_versioning_hash(path: impl AsRef<Path>, hash: impl AsRef<str>) {
{hash}
"
));
std::fs::write(path, contents.trim())
std::fs::write(path, contents.trim_start())
.with_context(|| format!("couldn't write to {path:?}"))
.unwrap();
}
Expand Down
2 changes: 1 addition & 1 deletion crates/re_types/source_hash.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# This is a sha256 hash for all direct and indirect dependencies of this crate's build script.
# It can be safely removed at anytime to force the build script to run again.
# Check out build.rs to see how it's computed.
5e3154fdbb6c48cfbef3855ec4d2e8dd243b158b517628c187510810837541d0
08ff48565c52ba1b521525e867d963c674d5c61a097d529c0751f1ec08c154ce
2 changes: 1 addition & 1 deletion crates/re_types_builder/source_hash.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# This is a sha256 hash for all direct and indirect dependencies of this crate's build script.
# It can be safely removed at anytime to force the build script to run again.
# Check out build.rs to see how it's computed.
674450e64722effea9b29a84c34fab81b9d57497136a8f161561b8e19f7441b2
674450e64722effea9b29a84c34fab81b9d57497136a8f161561b8e19f7441b2
2 changes: 1 addition & 1 deletion crates/re_ui/data/OFL.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ with others.

The OFL allows the licensed fonts to be used, studied, modified and
redistributed freely as long as they are not sold by themselves. The
fonts, including any derivative works, can be bundled, embedded,
fonts, including any derivative works, can be bundled, embedded,
redistributed and/or sold with any software provided that any reserved
names are not used by derivative works. The fonts and derivatives,
however, cannot be released under any other type of license. The
Expand Down
2 changes: 1 addition & 1 deletion docs/content/getting-started/troubleshooting.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ On WSL2, in addition to the above packages for Linux, you also need to run:

`sudo apt-get install -y libvulkan1 libxcb-randr0 mesa-vulkan-drivers adwaita-icon-theme-full`

[TODO(#1250)](https://github.com/rerun-io/rerun/issues/1250): Running with the wayland window manager
[TODO(#1250)](https://github.com/rerun-io/rerun/issues/1250): Running with the wayland window manager
sometimes causes Rerun to crash. Try setting `WINIT_UNIX_BACKEND=x11` as a workaround.

## Graphics issues
Expand Down
2 changes: 1 addition & 1 deletion docs/content/howto/limit-ram.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: How To Limit Memory Use
order: 1
description: How to limit the memory of Rerun so that it doesn't run out of RAM.
description: How to limit the memory of Rerun so that it doesn't run out of RAM.
---

### `--memory-limit`
Expand Down
6 changes: 3 additions & 3 deletions docs/content/howto/notebook.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Rather than logging to a file or a remote server, you can also configure the Rer

This `MemoryRecording` can then used to produce an inline HTML snippet to be directly displayed in most notebook
environments. The snippet includes an embedded copy of an RRD file and some javascript that loads that RRD file into an
IFrame.
IFrame.

Each cell in the notebook is fully isolated from the other cells and will only display the data from the source
`MemoryRecording`.
Expand All @@ -32,7 +32,7 @@ In order to create a new `MemoryRecording`, you call:
rec = rr.memory_recording()
```
This is similar to calling `rr.connect()` or `rr.save()` in that it configures the Rerun SDK to use this new
recording as a target for future API calls.
recording as a target for future API calls.

After logging data to the recording you can display it in a cell by calling the
[show()](https://ref.rerun.io/docs/python/latest/package/rerun/recording/#rerun.recording.MemoryRecording.show) method
Expand Down Expand Up @@ -87,7 +87,7 @@ This will create a new file `cube.html` that can be hosted on any static web ser

## Limitations

Although convenient, the approach of fully inlining an RRD file as an HTML snippet has some drawbacks. In particular,
Although convenient, the approach of fully inlining an RRD file as an HTML snippet has some drawbacks. In particular,
it is not suited to large RRD files. The RRD file is embedded as a base64 encoded string which can
result in a very large HTML file. This can cause problems in some browsers. If you want to share large datasets,
we recommend using the `save()` API to create a separate file and hosting it as a separate standalone asset.
Expand Down
2 changes: 1 addition & 1 deletion docs/content/reference/viewer.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
title: Viewer
order: 1
redirect: reference/viewer/overview
---
---
2 changes: 1 addition & 1 deletion docs/content/reference/viewer/selection.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ order: 2
---

Making selections is one of the primary ways of exploring data in Rerun.
The current selection can be changed with a mouse click on most elements of the -
The current selection can be changed with a mouse click on most elements of the -
including the [Blueprint](blueprint.md), [Viewport](viewport.md),
[Timeline](timeline.md), [Event Log](overview.md#event-log)
and even the Selection view itself.
Expand Down
2 changes: 1 addition & 1 deletion docs/content/reference/viewer/viewport.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@ Rerun distinguishes various categories of Space Views:

Which category is used is determined upon creation of a Space View.

[TODO(@#1164)](https://github.com/rerun-io/rerun/issues/1164): Allow configuring the category of a space view after its creation
[TODO(@#1164)](https://github.com/rerun-io/rerun/issues/1164): Allow configuring the category of a space view after its creation.

The kind of Space View determines which Entities it can display, how it displays them and the way they can be interacted with.
1 change: 0 additions & 1 deletion rerun_cpp/.gitignore

This file was deleted.

19 changes: 15 additions & 4 deletions scripts/lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@


def lint_line(line: str, file_extension: str = "rs") -> str | None:
if line == "":
return None

if line[-1].isspace():
return "Trailing whitespace"

if "NOLINT" in line:
return None # NOLINT ignores the linter

Expand Down Expand Up @@ -136,6 +142,7 @@ def test_lint_line() -> None:
r'println!("Problem: \"{}\"", string)',
r'println!("Problem: \"{0}\"")',
r'println!("Problem: \"{string}\"")',
"trailing whitespace ",
]

for line in should_pass:
Expand Down Expand Up @@ -381,7 +388,11 @@ def lint_file(filepath: str, args: Any) -> int:
num_errors = 0

for line_nr, line in enumerate(lines_in):
error = lint_line(line, file_extension)
if line == "" or line[-1] != '\n':
error = "Missing newline at end of file"
else:
line = line[:-1]
error = lint_line(line, file_extension)
if error is not None:
num_errors += 1
print(f"{filepath}:{line_nr+1}: {error}")
Expand Down Expand Up @@ -454,16 +465,16 @@ def main() -> None:
"./web_viewer/re_viewer_debug.js", # auto-generated by wasm_bindgen
}

matches = parse_gitignore(".gitignore")
should_ignore = parse_gitignore(".gitignore") # TODO(emilk): parse all .gitignore files, not just top-level

for root, dirs, files in os.walk(".", topdown=True):
dirs[:] = [d for d in dirs if not matches(d)]
dirs[:] = [d for d in dirs if not should_ignore(d)]

for filename in files:
extension = filename.split(".")[-1]
if extension in extensions:
filepath = os.path.join(root, filename)
if matches(filepath):
if should_ignore(filepath):
continue
if filepath not in exclude_paths:
num_errors += lint_file(filepath, args)
Expand Down

0 comments on commit e779802

Please sign in to comment.