Skip to content

Commit

Permalink
Address new lints
Browse files Browse the repository at this point in the history
Signed-off-by: Tom Jakubowski <tom@prospective.dev>
  • Loading branch information
tomjakubowski authored and texodus committed May 19, 2024
1 parent 4bc0fa0 commit 18c4231
Show file tree
Hide file tree
Showing 16 changed files with 46 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ derive_model!(Renderer, Session for ConfigSelectorProps);

#[derive(Debug)]
pub enum ConfigSelectorMsg {
DragStart(DragEffect),
DragStart,
DragEnd,
DragOver(usize, DragTarget),
DragLeave(DragTarget),
Expand Down Expand Up @@ -173,7 +173,7 @@ impl Component for ConfigSelector {
type Properties = ConfigSelectorProps;

fn create(ctx: &Context<Self>) -> Self {
let cb = ctx.link().callback(ConfigSelectorMsg::DragStart);
let cb = ctx.link().callback(|_| ConfigSelectorMsg::DragStart);
let drag_sub = Rc::new(ctx.props().dragdrop.dragstart_received.add_listener(cb));

let cb = ctx.link().callback(|_| ConfigSelectorMsg::DragEnd);
Expand Down Expand Up @@ -201,7 +201,7 @@ impl Component for ConfigSelector {

fn update(&mut self, ctx: &Context<Self>, msg: Self::Message) -> bool {
match msg {
ConfigSelectorMsg::DragStart(_) | ConfigSelectorMsg::ViewCreated => true,
ConfigSelectorMsg::DragStart | ConfigSelectorMsg::ViewCreated => true,
ConfigSelectorMsg::DragEnd => true,
ConfigSelectorMsg::DragOver(index, action) => {
let should_render = ctx.props().dragdrop.notify_drag_enter(action, index);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ pub struct ColumnSettingsProps {
pub is_active: bool,
}

derive_model!(CustomEvents, Session, Renderer, Presentation for ColumnSettingsProps);
derive_model!(Session, Renderer, Presentation for ColumnSettingsProps);

impl PartialEq for ColumnSettingsProps {
fn eq(&self, other: &Self) -> bool {
Expand Down Expand Up @@ -258,8 +258,8 @@ impl Component for ColumnSettingsSidebar {
rerender
},
ColumnSettingsMsg::OnResetAttributes(()) => {
self.header_value = self.initial_header_value.clone();
self.expr_value = self.initial_expr_value.clone();
self.header_value.clone_from(&self.initial_header_value);
self.expr_value.clone_from(&self.initial_expr_value);
self.save_enabled = false;
self.reset_enabled = false;
self.reset_count += 1;
Expand All @@ -280,8 +280,8 @@ impl Component for ColumnSettingsSidebar {
ColumnLocator::NewExpression => ctx.props().save_expr(new_expr),
}

self.initial_expr_value = self.expr_value.clone();
self.initial_header_value = self.header_value.clone();
self.initial_expr_value.clone_from(&self.expr_value);
self.initial_header_value.clone_from(&self.header_value);
self.save_enabled = false;
self.reset_enabled = false;
self.save_count += 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ pub struct StyleTabProps {
pub ty: Option<Type>,
pub column_name: String,
}
derive_model!(Session, Renderer, Presentation, CustomEvents for StyleTabProps);
derive_model!(Session, Renderer, Presentation for StyleTabProps);

impl StyleTabProps {
fn send_plugin_config(&self, update: ColumnConfigValueUpdate) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ impl Component for SplitPanel {
match msg {
SplitPanelMsg::Reset(index) => {
self.styles[index] = None;
self.on_reset = ctx.props().on_reset.clone();
self.on_reset.clone_from(&ctx.props().on_reset);
},
SplitPanelMsg::StartResizing(index, client_offset, pointer_id, pointer_elem) => {
let elem = self.refs[index].cast::<HtmlElement>().unwrap();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,11 @@ impl Component for EditableHeader {

fn changed(&mut self, ctx: &yew::prelude::Context<Self>, old_props: &Self::Properties) -> bool {
if ctx.props().reset_count != old_props.reset_count {
self.value = ctx.props().initial_value.clone();
self.value.clone_from(&ctx.props().initial_value);
}
if ctx.props().initial_value != old_props.initial_value {
self.edited = false;
self.value = ctx.props().initial_value.clone();
self.value.clone_from(&ctx.props().initial_value);
}
if !ctx.props().editable {
self.edited = false;
Expand Down Expand Up @@ -125,7 +125,7 @@ impl Component for EditableHeader {
})
.unwrap_or(true);

self.value = maybe_value.clone();
self.value.clone_from(&maybe_value);
ctx.props().on_change.emit((maybe_value, self.valid));

true
Expand Down
2 changes: 1 addition & 1 deletion rust/perspective-viewer/src/rust/components/font_loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ impl FontLoaderProps {

let mut block_promises: PromiseSet = vec![];
let preload_fonts = parse_fonts(&txt);
*self.state.fonts.borrow_mut() = preload_fonts.clone();
self.state.fonts.borrow_mut().clone_from(&preload_fonts);
self.state.status.set(FontLoaderStatus::Loading);
self.state.on_update.emit(());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@ impl PartialEq for NumberColumnStyleProps {

impl NumberColumnStyleProps {
fn set_default_gradient(&self, ctx: &Context<NumberColumnStyle>) {
if let Some(session) = self.session.clone() && let Some(column_name) = self.column_name.clone() {
if let Some(session) = self.session.clone()
&& let Some(column_name) = self.column_name.clone()
{
ctx.link().send_future(async move {
let view = session.get_view().unwrap();
let min_max = view.get_min_max(&column_name).await.unwrap();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ impl StyleCache {
map.insert(name, style.clone());
let mut values = map.values();
if let Some(mut x) = first {
while let Some(y) = values.next() && y.get_attribute("name").as_deref() < Some(name) {
while let Some(y) = values.next()
&& y.get_attribute("name").as_deref() < Some(name)
{
x = y.clone();
}

Expand Down
6 changes: 4 additions & 2 deletions rust/perspective-viewer/src/rust/components/viewer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ impl Component for PerspectiveViewer {
self.selected_column = None;
(false, None)
} else {
self.selected_column = locator.clone();
self.selected_column.clone_from(&locator);

locator
.clone()
Expand All @@ -363,7 +363,9 @@ impl Component for PerspectiveViewer {
};

let mut open_column_settings = ctx.props().presentation.get_open_column_settings();
open_column_settings.locator = self.selected_column.clone();
open_column_settings
.locator
.clone_from(&self.selected_column);
ctx.props()
.presentation
.set_open_column_settings(Some(open_column_settings));
Expand Down
20 changes: 13 additions & 7 deletions rust/perspective-viewer/src/rust/config/expressions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,19 @@ impl std::ops::DerefMut for Expressions {

fn upgrade_legacy_format(expressions: &[String]) -> HashMap<String, String> {
tracing::warn!("Legacy `expressions` format: {:?}", expressions);
expressions.iter().map(|s| {
if let Some((name, expression)) = s.split_once('\n') && !expression.is_empty() && name.starts_with("//") {
(name.split_at(2).1.trim().to_owned(), expression.to_owned())
} else {
(s.to_owned(), s.to_owned())
}
}).collect::<HashMap<_, _>>()
expressions
.iter()
.map(|s| {
if let Some((name, expression)) = s.split_once('\n')
&& !expression.is_empty()
&& name.starts_with("//")
{
(name.split_at(2).1.trim().to_owned(), expression.to_owned())
} else {
(s.to_owned(), s.to_owned())
}
})
.collect::<HashMap<_, _>>()
}

impl From<ExpressionsDeserde> for Expressions {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ impl FilterDropDownElement {
FilterDropDownMsg::SetValues(values),
]);

if let Some(x) = self.target.borrow().clone() && !self.modal.is_open() {
if let Some(x) = self.target.borrow().clone()
&& !self.modal.is_open()
{
ApiFuture::spawn(self.modal.clone().open(x, None))
}
}
Expand Down
2 changes: 1 addition & 1 deletion rust/perspective-viewer/src/rust/exprtk/language.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub struct CompletionItemSuggestion {
}

thread_local! {
pub static COMPLETION_COLUMN_NAMES: RefCell<Vec<String>> = RefCell::new(vec![]);
pub static COMPLETION_COLUMN_NAMES: RefCell<Vec<String>> = const { RefCell::new(vec![]) };

pub static COMPLETIONS: Vec<CompletionItemSuggestion> = vec![
CompletionItemSuggestion {
Expand Down
2 changes: 1 addition & 1 deletion rust/perspective-viewer/src/rust/js/testing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ extern "C" {
#[cfg(test)]
pub async fn get_mock_table() -> JsPerspectiveTable {
thread_local! {
static WORKER: RefCell<Option<JsPerspectiveWorker>> = RefCell::new(None);
static WORKER: RefCell<Option<JsPerspectiveWorker>> = const { RefCell::new(None) };
}

let worker: JsPerspectiveWorker = match WORKER.with(|x| x.borrow().clone()) {
Expand Down
12 changes: 0 additions & 12 deletions rust/perspective-viewer/src/rust/model/structural.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
//! `struct`s only if the define accessors for the necessary applications state
//! objects (which are conviently derivable with the `derive_model!` macro).

use crate::custom_events::*;
use crate::dragdrop::*;
use crate::presentation::*;
use crate::renderer::*;
Expand All @@ -37,10 +36,6 @@ pub trait HasDragDrop {
fn dragdrop(&self) -> &'_ DragDrop;
}

pub trait HasCustomEvents {
fn custom_events(&self) -> &'_ CustomEvents;
}

#[macro_export]
macro_rules! derive_model {
(DragDrop for $key:ty) => {
Expand Down Expand Up @@ -71,13 +66,6 @@ macro_rules! derive_model {
}
}
};
(CustomEvents for $key:ty) => {
impl $crate::model::HasCustomEvents for $key {
fn custom_events(&self) -> &'_ CustomEvents {
&self.custom_events
}
}
};
($i:ident, $($is:ident),+ for $key:ty) => {
derive_model!($i for $key);
derive_model!($($is),+ for $key);
Expand Down
6 changes: 3 additions & 3 deletions rust/perspective-viewer/src/rust/presentation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ impl Presentation {
}

pub fn set_title(&self, title: Option<String>) {
*self.name.borrow_mut() = title.clone();
self.name.borrow_mut().clone_from(&title);
self.title_changed.emit(title);
}

Expand Down Expand Up @@ -155,7 +155,7 @@ impl Presentation {
pub fn set_open_column_settings(&self, settings: Option<OpenColumnSettings>) {
let settings = settings.unwrap_or_default();
if *(self.open_column_settings.borrow()) != settings {
*(self.open_column_settings.borrow_mut()) = settings.to_owned();
settings.clone_into(&mut (self.open_column_settings.borrow_mut()));
self.column_settings_open_changed
.emit((true, settings.name()));
}
Expand Down Expand Up @@ -224,7 +224,7 @@ impl Presentation {
self.set_theme_attribute(Some(theme))?;
themes.iter().position(|x| x == theme)
} else if !themes.is_empty() {
self.set_theme_attribute(themes.get(0).map(|x| x.as_str()))?;
self.set_theme_attribute(themes.first().map(|x| x.as_str()))?;
Some(0)
} else {
self.set_theme_attribute(None)?;
Expand Down
2 changes: 1 addition & 1 deletion rust/perspective-viewer/src/rust/session/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ impl SessionMetadata {
.map(|x| x.edited)
.unwrap_or_default();

edited.retain(|k, _| expression_alias.get(k).is_some());
edited.retain(|k, _| expression_alias.contains_key(k));
self.as_mut().unwrap().expr_meta = Some(SessionViewExpressionMetadata {
schema: expression_schema,
alias: expression_alias,
Expand Down

0 comments on commit 18c4231

Please sign in to comment.