From f8d7d0ebaa9f991d9796f379fdee9c1014e5d009 Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Tue, 26 Mar 2024 11:48:24 +0100 Subject: [PATCH] Enforce writing username in TODO comments (#4235) --- crates/eframe/src/web/events.rs | 4 ++-- crates/egui-winit/src/lib.rs | 4 ++-- crates/egui/src/context.rs | 2 +- crates/egui/src/input_state.rs | 2 +- crates/egui/src/interaction.rs | 4 ++-- crates/egui/src/memory.rs | 2 +- crates/egui/src/text_selection/label_text_selection.rs | 6 +++--- crates/egui/src/widgets/image.rs | 2 +- crates/egui/src/widgets/text_edit/builder.rs | 2 +- crates/egui_demo_lib/src/easy_mark/easy_mark_editor.rs | 2 +- crates/egui_extras/src/loaders.rs | 2 +- crates/egui_plot/src/axis.rs | 4 ++-- crates/egui_plot/src/items/values.rs | 2 +- crates/egui_plot/src/lib.rs | 2 +- crates/epaint/src/stats.rs | 2 +- crates/epaint/src/tessellator.rs | 2 +- crates/epaint/src/text/text_layout.rs | 2 +- examples/test_viewports/src/main.rs | 2 +- scripts/lint.py | 8 +++++++- 19 files changed, 31 insertions(+), 25 deletions(-) diff --git a/crates/eframe/src/web/events.rs b/crates/eframe/src/web/events.rs index 5e5f7b22622..30775733e58 100644 --- a/crates/eframe/src/web/events.rs +++ b/crates/eframe/src/web/events.rs @@ -88,7 +88,7 @@ pub(crate) fn install_document_events(runner_ref: &WebRunner) -> Result<(), JsVa if let Some(key) = egui_key { runner.input.raw.events.push(egui::Event::Key { key, - physical_key: None, // TODO + physical_key: None, // TODO(fornwall) pressed: true, repeat: false, // egui will fill this in for us! modifiers, @@ -155,7 +155,7 @@ pub(crate) fn install_document_events(runner_ref: &WebRunner) -> Result<(), JsVa if let Some(key) = translate_key(&event.key()) { runner.input.raw.events.push(egui::Event::Key { key, - physical_key: None, // TODO + physical_key: None, // TODO(fornwall) pressed: false, repeat: false, modifiers, diff --git a/crates/egui-winit/src/lib.rs b/crates/egui-winit/src/lib.rs index 418c39ece32..41db04952e5 100644 --- a/crates/egui-winit/src/lib.rs +++ b/crates/egui-winit/src/lib.rs @@ -308,7 +308,7 @@ impl State { consumed: false, } } - // WindowEvent::TouchpadPressure {device_id, pressure, stage, .. } => {} // TODO + // WindowEvent::TouchpadPressure {device_id, pressure, stage, .. } => {} // TODO(emilk) WindowEvent::Touch(touch) => { self.on_touch(window, touch); let consumed = match touch.phase { @@ -1298,7 +1298,7 @@ fn process_viewport_command( ViewportCommand::StartDrag => { // If `is_viewport_focused` is not checked on x11 the input will be permanently taken until the app is killed! - // TODO: check that the left mouse-button was pressed down recently, + // TODO(emilk): check that the left mouse-button was pressed down recently, // or we will have bugs on Windows. // See https://github.com/emilk/egui/pull/1108 if is_viewport_focused { diff --git a/crates/egui/src/context.rs b/crates/egui/src/context.rs index ea61cd7d034..258c39bfdcf 100644 --- a/crates/egui/src/context.rs +++ b/crates/egui/src/context.rs @@ -2770,7 +2770,7 @@ impl Context { /// The `Context` lock is held while the given closure is called! /// /// Returns `None` if acesskit is off. - // TODO: consider making both RO and RW versions + // TODO(emilk): consider making both RO and RW versions #[cfg(feature = "accesskit")] pub fn accesskit_node_builder( &self, diff --git a/crates/egui/src/input_state.rs b/crates/egui/src/input_state.rs index 2a196c86528..b2284d45c2e 100644 --- a/crates/egui/src/input_state.rs +++ b/crates/egui/src/input_state.rs @@ -236,7 +236,7 @@ impl InputState { // So we smooth it out over several frames for a nicer user experience when scrolling in egui. unprocessed_scroll_delta += raw_scroll_delta; let dt = stable_dt.at_most(0.1); - let t = crate::emath::exponential_smooth_factor(0.90, 0.1, dt); // reach _% in _ seconds. TODO: parameterize + let t = crate::emath::exponential_smooth_factor(0.90, 0.1, dt); // reach _% in _ seconds. TODO(emilk): parameterize for d in 0..2 { if unprocessed_scroll_delta[d].abs() < 1.0 { diff --git a/crates/egui/src/interaction.rs b/crates/egui/src/interaction.rs index d5812d4d7c2..8ee3f259a43 100644 --- a/crates/egui/src/interaction.rs +++ b/crates/egui/src/interaction.rs @@ -247,8 +247,8 @@ pub(crate) fn interact( hits.click.iter().chain(&hits.drag).map(|w| w.id).collect() } else { // Whatever is topmost is what we are hovering. - // TODO: consider handle hovering over multiple top-most widgets? - // TODO: allow hovering close widgets? + // TODO(emilk): consider handle hovering over multiple top-most widgets? + // TODO(emilk): allow hovering close widgets? hits.contains_pointer .last() .map(|w| w.id) diff --git a/crates/egui/src/memory.rs b/crates/egui/src/memory.rs index 068347b5697..dc611787fff 100644 --- a/crates/egui/src/memory.rs +++ b/crates/egui/src/memory.rs @@ -243,7 +243,7 @@ impl Options { pub fn ui(&mut self, ui: &mut crate::Ui) { let Self { style, // covered above - zoom_factor: _, // TODO + zoom_factor: _, // TODO(emilk) zoom_with_keyboard, tessellation_options, repaint_on_widget_change, diff --git a/crates/egui/src/text_selection/label_text_selection.rs b/crates/egui/src/text_selection/label_text_selection.rs index af9e3039eeb..ec5a4729eee 100644 --- a/crates/egui/src/text_selection/label_text_selection.rs +++ b/crates/egui/src/text_selection/label_text_selection.rs @@ -8,7 +8,7 @@ use super::{ }; /// Turn on to help debug this -const DEBUG: bool = false; // TODO: don't merge this while `true` +const DEBUG: bool = false; // Don't merge `true`! fn paint_selection( ui: &Ui, @@ -169,7 +169,7 @@ impl LabelSelectionState { if ctx.input(|i| i.pointer.any_pressed() && !i.modifiers.shift) { // Maybe a new selection is about to begin, but the old one is over: - // state.selection = None; // TODO: this makes sense, but doesn't work as expected. + // state.selection = None; // TODO(emilk): this makes sense, but doesn't work as expected. } state.selection_bbox_last_frame = state.selection_bbox_this_frame; @@ -562,7 +562,7 @@ impl LabelSelectionState { old.widget_id != new_primary.widget_id || old.ccursor != new_primary.ccursor }); if primary_changed && new_primary.widget_id == widget_id { - let is_fully_visible = ui.clip_rect().contains_rect(response.rect); // TODO: remove this HACK workaround for https://github.com/emilk/egui/issues/1531 + let is_fully_visible = ui.clip_rect().contains_rect(response.rect); // TODO(emilk): remove this HACK workaround for https://github.com/emilk/egui/issues/1531 if selection_changed && !is_fully_visible { // Scroll to keep primary cursor in view: let row_height = estimate_row_height(galley); diff --git a/crates/egui/src/widgets/image.rs b/crates/egui/src/widgets/image.rs index 1d1ec581d8a..90176018cb7 100644 --- a/crates/egui/src/widgets/image.rs +++ b/crates/egui/src/widgets/image.rs @@ -452,7 +452,7 @@ impl ImageSize { } } -// TODO: unit-tests +// TODO(jprochazk): unit-tests fn scale_to_fit(image_size: Vec2, available_size: Vec2, maintain_aspect_ratio: bool) -> Vec2 { if maintain_aspect_ratio { let ratio_x = available_size.x / image_size.x; diff --git a/crates/egui/src/widgets/text_edit/builder.rs b/crates/egui/src/widgets/text_edit/builder.rs index bed9b6a6d29..e5745389082 100644 --- a/crates/egui/src/widgets/text_edit/builder.rs +++ b/crates/egui/src/widgets/text_edit/builder.rs @@ -687,7 +687,7 @@ impl<'t> TextEdit<'t> { let primary_cursor_rect = cursor_rect(galley_pos, &galley, &cursor_range.primary, row_height); - let is_fully_visible = ui.clip_rect().contains_rect(rect); // TODO: remove this HACK workaround for https://github.com/emilk/egui/issues/1531 + let is_fully_visible = ui.clip_rect().contains_rect(rect); // TODO(emilk): remove this HACK workaround for https://github.com/emilk/egui/issues/1531 if (response.changed || selection_changed) && !is_fully_visible { // Scroll to keep primary cursor in view: ui.scroll_to_rect(primary_cursor_rect, None); diff --git a/crates/egui_demo_lib/src/easy_mark/easy_mark_editor.rs b/crates/egui_demo_lib/src/easy_mark/easy_mark_editor.rs index 0971abd45b2..2a44d78f3a7 100644 --- a/crates/egui_demo_lib/src/easy_mark/easy_mark_editor.rs +++ b/crates/egui_demo_lib/src/easy_mark/easy_mark_editor.rs @@ -261,7 +261,7 @@ The style characters are chosen to be similar to what they are representing: `$` = $small$ `^` = ^raised^ -# TODO +# To do - Sub-headers (`## h2`, `### h3` etc) - Hotkey Editor - International keyboard algorithm for non-letter keys diff --git a/crates/egui_extras/src/loaders.rs b/crates/egui_extras/src/loaders.rs index cc775a2ca20..05df9bc8eef 100644 --- a/crates/egui_extras/src/loaders.rs +++ b/crates/egui_extras/src/loaders.rs @@ -1,4 +1,4 @@ -// TODO: automatic cache eviction +// TODO(jprochazk): automatic cache eviction /// Installs a set of image loaders. /// diff --git a/crates/egui_plot/src/axis.rs b/crates/egui_plot/src/axis.rs index df182631c1b..3c2972e6d87 100644 --- a/crates/egui_plot/src/axis.rs +++ b/crates/egui_plot/src/axis.rs @@ -106,7 +106,7 @@ pub struct AxisHints { pub(super) label_spacing: Rangef, } -// TODO: this just a guess. It might cease to work if a user changes font size. +// TODO(JohannesProgrammiert): this just a guess. It might cease to work if a user changes font size. const LINE_HEIGHT: f32 = 12.0; impl AxisHints { @@ -366,7 +366,7 @@ impl AxisWidget { match HPlacement::from(self.hints.placement) { HPlacement::Left => { - let angle = 0.0; // TODO: allow users to rotate text + let angle = 0.0; // TODO(emilk): allow users to rotate text if angle == 0.0 { let x = self.rect.max.x - galley.size().x; diff --git a/crates/egui_plot/src/items/values.rs b/crates/egui_plot/src/items/values.rs index 8ed6d38f333..5f9fe8183f3 100644 --- a/crates/egui_plot/src/items/values.rs +++ b/crates/egui_plot/src/items/values.rs @@ -156,7 +156,7 @@ impl Default for Orientation { pub enum PlotPoints { Owned(Vec), Generator(ExplicitGenerator), - // Borrowed(&[PlotPoint]), // TODO: Lifetimes are tricky in this case. + // Borrowed(&[PlotPoint]), // TODO(EmbersArc): Lifetimes are tricky in this case. } impl Default for PlotPoints { diff --git a/crates/egui_plot/src/lib.rs b/crates/egui_plot/src/lib.rs index ed133d7edb6..e9962c843d2 100644 --- a/crates/egui_plot/src/lib.rs +++ b/crates/egui_plot/src/lib.rs @@ -800,7 +800,7 @@ impl Plot { let plot_id = id.unwrap_or_else(|| ui.make_persistent_id(id_source)); let ([x_axis_widgets, y_axis_widgets], plot_rect) = axis_widgets( - PlotMemory::load(ui.ctx(), plot_id).as_ref(), // TODO: avoid loading plot memory twice + PlotMemory::load(ui.ctx(), plot_id).as_ref(), // TODO(emilk): avoid loading plot memory twice show_axes, complete_rect, [&x_axes, &y_axes], diff --git a/crates/epaint/src/stats.rs b/crates/epaint/src/stats.rs index 3bb51e14170..c63d5a0ddec 100644 --- a/crates/epaint/src/stats.rs +++ b/crates/epaint/src/stats.rs @@ -192,7 +192,7 @@ impl PaintStats { fn add(&mut self, shape: &Shape) { match shape { Shape::Vec(shapes) => { - // self += PaintStats::from_shapes(&shapes); // TODO + // self += PaintStats::from_shapes(&shapes); // TODO(emilk) self.shapes += AllocInfo::from_slice(shapes); self.shape_vec += AllocInfo::from_slice(shapes); for shape in shapes { diff --git a/crates/epaint/src/tessellator.rs b/crates/epaint/src/tessellator.rs index bf419e99b58..49d5ab8a33c 100644 --- a/crates/epaint/src/tessellator.rs +++ b/crates/epaint/src/tessellator.rs @@ -1864,7 +1864,7 @@ impl Tessellator { .filter(|(_, clipped_shape)| should_parallelize(&clipped_shape.shape)) .map(|(index, clipped_shape)| { crate::profile_scope!("tessellate_big_shape"); - // TODO: reuse tessellator in a thread local + // TODO(emilk): reuse tessellator in a thread local let mut tessellator = (*self).clone(); let mut mesh = Mesh::default(); tessellator.tessellate_shape(clipped_shape.shape.clone(), &mut mesh); diff --git a/crates/epaint/src/text/text_layout.rs b/crates/epaint/src/text/text_layout.rs index 9b055edc577..322026da3c5 100644 --- a/crates/epaint/src/text/text_layout.rs +++ b/crates/epaint/src/text/text_layout.rs @@ -960,7 +960,7 @@ fn is_kana(c: char) -> bool { #[inline] fn is_cjk(c: char) -> bool { - // TODO: Add support for Korean Hangul. + // TODO(bigfarts): Add support for Korean Hangul. is_cjk_ideograph(c) || is_kana(c) } diff --git a/examples/test_viewports/src/main.rs b/examples/test_viewports/src/main.rs index 69be9177127..05679668013 100644 --- a/examples/test_viewports/src/main.rs +++ b/examples/test_viewports/src/main.rs @@ -441,7 +441,7 @@ fn drag_source( } } -// TODO: Update to be more like `crates/egui_demo_lib/src/debo/drag_and_drop.rs` +// TODO(emilk): Update to be more like `crates/egui_demo_lib/src/debo/drag_and_drop.rs` fn drop_target( ui: &mut egui::Ui, body: impl FnOnce(&mut egui::Ui) -> R, diff --git a/scripts/lint.py b/scripts/lint.py index 59322ad2819..221d980d079 100755 --- a/scripts/lint.py +++ b/scripts/lint.py @@ -36,7 +36,7 @@ def lint_lines(filepath, lines_in): for line_nr, line in enumerate(lines_in): line_nr = line_nr + 1 - # TODO: only # and /// on lines before a keyword + # TODO(emilk): only # and /// on lines before a keyword pattern = ( r"^\s*((///)|((pub(\(\w*\))? )?((impl|fn|struct|enum|union|trait)\b))).*$" @@ -66,6 +66,12 @@ def lint_lines(filepath, lines_in): ) lines_out.append("#[inline]") + + if re.search(r"TODO[^(]", line): + errors.append( + f"{filepath}:{line_nr}: write 'TODO(username):' instead" + ) + if ( "(target_os" in line and filepath.startswith("./crates/egui/")