Skip to content
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

lint: standardize formatting of let-else-return statements #2297

Merged
merged 1 commit into from
Jun 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/re_data_ui/src/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ pub fn show_zoomed_image_region_area_outline(
) {
use egui::{pos2, remap, Rect};

let Some([height, width, _]) = tensor.image_height_width_channels() else {return;};
let Some([height, width, _]) = tensor.image_height_width_channels() else { return; };

let width = width as f32;
let height = height as f32;
Expand Down
6 changes: 3 additions & 3 deletions crates/re_viewer/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -434,11 +434,11 @@ impl App {
}

fn run_time_control_command(&mut self, command: TimeControlCommand) {
let Some(rec_id) = &self.state.selected_rec_id else {return;};
let Some(rec_cfg) = self.state.recording_configs.get_mut(rec_id) else {return;};
let Some(rec_id) = &self.state.selected_rec_id else { return; };
let Some(rec_cfg) = self.state.recording_configs.get_mut(rec_id) else { return; };
let time_ctrl = &mut rec_cfg.time_ctrl;

let Some(log_db) = self.log_dbs.get(rec_id) else { return };
let Some(log_db) = self.log_dbs.get(rec_id) else { return; };
let times_per_timeline = log_db.times_per_timeline();

match command {
Expand Down
4 changes: 2 additions & 2 deletions rerun_py/src/python_bridge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1171,7 +1171,7 @@ fn add_space_view(
entity_paths: Vec<&str>,
blueprint: Option<&PyRecordingStream>,
) {
let Some(blueprint) = get_blueprint_recording(blueprint) else { return };
let Some(blueprint) = get_blueprint_recording(blueprint) else { return; };

let mut space_view = SpaceViewBlueprint::new(
"Spatial".into(),
Expand Down Expand Up @@ -1213,7 +1213,7 @@ fn add_space_view(

#[pyfunction]
fn set_auto_space_views(enabled: bool, blueprint: Option<&PyRecordingStream>) {
let Some(blueprint) = get_blueprint_recording(blueprint) else { return };
let Some(blueprint) = get_blueprint_recording(blueprint) else { return; };

// TODO(jleibs) timeless? Something else?
let timepoint = time(true, &blueprint);
Expand Down
12 changes: 12 additions & 0 deletions scripts/lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
error_map_err_name = re.compile(r"map_err\(\|(\w+)\|")
wasm_caps = re.compile(r"\bWASM\b")
nb_prefix = re.compile(r"nb_")
else_return = re.compile(r"else\s*{\s*return;?\s*};")


def lint_line(line: str) -> Optional[str]:
Expand Down Expand Up @@ -63,6 +64,13 @@ def lint_line(line: str) -> Optional[str]:
if name in ("e", "error"):
return "Errors should be called 'err', '_err' or '_'"

m = re.search(else_return, line)
if m:
match = m.group(0)
if match != "else { return; };":
# Because cargo fmt doesn't handle let-else
return f"Use 'else {{ return; }};' instead of '{match}'"

if wasm_caps.search(line):
return "WASM should be written 'Wasm'"

Expand Down Expand Up @@ -94,6 +102,7 @@ def test_lint_line() -> None:
"Wasm",
"num_instances",
"instances_count",
"let Some(foo) = bar else { return; };",
]

should_error = [
Expand All @@ -112,6 +121,9 @@ def test_lint_line() -> None:
"We use WASM in Rerun",
"nb_instances",
"inner_nb_instances",
"let Some(foo) = bar else {return;};",
"let Some(foo) = bar else {return};",
"let Some(foo) = bar else { return };",
]

for line in should_pass:
Expand Down