mirror of https://github.com/linebender/xilem
Import our intended set of lints (#432)
See discussion in [#linebender > Standard Lint set](https://xi.zulipchat.com/#narrow/stream/419691-linebender/topic/Standard.20Lint.20set) Of note: I have taken steps to ensure that this can be practically reviewed by *not* applying most of the lints. The commented out lints make good follow-ups --------- Co-authored-by: Olivier FAURE <couteaubleu@gmail.com>
This commit is contained in:
parent
7f40266bd8
commit
f11b64892c
65
Cargo.toml
65
Cargo.toml
|
@ -23,7 +23,6 @@ repository = "https://github.com/linebender/xilem"
|
|||
homepage = "https://xilem.dev/"
|
||||
|
||||
[workspace.lints]
|
||||
clippy.semicolon_if_nothing_returned = "warn"
|
||||
# Remove assigning_clones once it's allowed by default in stable Rust
|
||||
# https://github.com/rust-lang/rust-clippy/pull/12779
|
||||
clippy.assigning_clones = "allow"
|
||||
|
@ -37,6 +36,70 @@ rust.unexpected_cfgs = { level = "warn", check-cfg = [
|
|||
# (And cargo doesn't let us have platform specific lints here)
|
||||
rust.unsafe_code = "deny"
|
||||
|
||||
rust.keyword_idents_2024 = "forbid"
|
||||
rust.non_ascii_idents = "forbid"
|
||||
rust.unsafe_op_in_unsafe_fn = "forbid"
|
||||
rust.non_local_definitions = "forbid"
|
||||
|
||||
rust.unused_lifetimes = "warn"
|
||||
rust.unit_bindings = "warn"
|
||||
rust.unused_import_braces = "warn"
|
||||
rust.trivial_numeric_casts = "warn"
|
||||
rust.unused_macro_rules = "warn"
|
||||
rust.variant_size_differences = "warn"
|
||||
|
||||
clippy.allow_attributes_without_reason = "warn"
|
||||
clippy.collection_is_never_read = "warn"
|
||||
clippy.debug_assert_with_mut_call = "warn"
|
||||
clippy.fn_to_numeric_cast_any = "forbid"
|
||||
clippy.infinite_loop = "warn"
|
||||
clippy.large_include_file = "warn"
|
||||
clippy.large_stack_arrays = "warn"
|
||||
clippy.mismatching_type_param_order = "warn"
|
||||
clippy.missing_fields_in_debug = "warn"
|
||||
clippy.same_functions_in_if_condition = "warn"
|
||||
clippy.semicolon_if_nothing_returned = "warn"
|
||||
clippy.should_panic_without_expect = "warn"
|
||||
clippy.unseparated_literal_suffix = "warn"
|
||||
|
||||
# Follow-ups for their own PRs, too noisy to go in lint group PR
|
||||
|
||||
# rust.let_underscore_drop = "warn"
|
||||
# rust.missing_debug_implementations = "warn"
|
||||
# rust.unused_qualifications = "warn"
|
||||
# rust.single_use_lifetimes = "warn"
|
||||
# clippy.exhaustive_enums = "warn"
|
||||
# clippy.dbg_macro = "warn"
|
||||
# clippy.match_same_arms = "warn"
|
||||
# clippy.cast_possible_truncation = "warn"
|
||||
# clippy.missing_assert_message = "warn"
|
||||
# clippy.return_self_not_must_use = "warn"
|
||||
# clippy.wildcard_imports = "warn"
|
||||
# rust.elided_lifetimes_in_paths = "warn"
|
||||
# clippy.use_self = "warn"
|
||||
|
||||
# Aspirational lints, not enabled for one reason or another
|
||||
|
||||
# rust.missing_docs = "warn" # We have many as-yet undocumented items
|
||||
# rust.unreachable_pub = "warn" # Potentially controversial code style
|
||||
# rust.unnameable_types = "warn" # Requires lint_reasons rustc feature for exceptions
|
||||
# clippy.todo = "warn" # We have a lot of "real" todos
|
||||
# clippy.missing_errors_doc = "warn" # Can be quite noisy?
|
||||
# clippy.missing_panics_doc = "warn" # Can be quite noisy?
|
||||
# clippy.partial_pub_fields = "warn" # Potentially controversial code style
|
||||
# clippy.shadow_unrelated = "warn" # Potentially controversial code style
|
||||
|
||||
# This catches duplicated dependencies in the tree, which we don't have much control over
|
||||
# We should use cargo deny for this, anyway
|
||||
# clippy.cargo = "warn"
|
||||
|
||||
# Lints which we still set in individual crates lib.rs
|
||||
# False positives with example targets - https://github.com/rust-lang/rust/issues/57274
|
||||
# rust.unused_crate_dependencies = "warn"
|
||||
# Examples often do want to print
|
||||
# clippy.print_stdout = "warn" # Note that this is allowed in Masonry
|
||||
# clippy.print_stderr = "warn" # Note that this is allowed in Masonry
|
||||
|
||||
[workspace.dependencies]
|
||||
xilem_web_core = { version = "0.1.0", path = "xilem_web/xilem_web_core" }
|
||||
masonry = { version = "0.2.0", path = "masonry" }
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
// On Windows platform, don't show a console when opening the app.
|
||||
#![windows_subsystem = "windows"]
|
||||
#![allow(clippy::single_match)]
|
||||
#![allow(variant_size_differences, clippy::single_match)]
|
||||
|
||||
use accesskit::{DefaultActionVerb, Role};
|
||||
use masonry::app_driver::{AppDriver, DriverCtx};
|
||||
|
|
|
@ -79,11 +79,13 @@
|
|||
#![deny(clippy::trivially_copy_pass_by_ref)]
|
||||
// #![deny(rustdoc::broken_intra_doc_links)]
|
||||
// #![warn(missing_docs)]
|
||||
#![warn(unused_imports)]
|
||||
#![warn(unused_imports, /* TODO: clippy::print_stdout, clippy::print_stderr */)]
|
||||
#![allow(clippy::should_implement_trait)]
|
||||
#![allow(clippy::single_match)]
|
||||
#![cfg_attr(docsrs, feature(doc_cfg))]
|
||||
#![cfg_attr(not(debug_assertions), allow(unused))]
|
||||
// False-positive with dev-dependencies only used in examples
|
||||
#![cfg_attr(not(test), warn(unused_crate_dependencies))]
|
||||
|
||||
// TODO - Add logo
|
||||
|
||||
|
|
|
@ -139,7 +139,7 @@ mod tests {
|
|||
assert!(promise_result.try_get(promise_token_2).is_none());
|
||||
}
|
||||
|
||||
#[should_panic]
|
||||
#[should_panic(expected = "mismatched token")]
|
||||
#[test]
|
||||
fn bad_promise_get() {
|
||||
let promise_token_1: PromiseToken<i32> = PromiseToken::new();
|
||||
|
@ -149,7 +149,7 @@ mod tests {
|
|||
promise_result.get(promise_token_2);
|
||||
}
|
||||
|
||||
#[should_panic]
|
||||
#[should_panic(expected = "payload already taken")]
|
||||
#[test]
|
||||
fn get_promise_twice() {
|
||||
let promise_token = PromiseToken::new();
|
||||
|
|
|
@ -503,7 +503,8 @@ impl<T: TextStorage> std::fmt::Debug for TextLayout<T> {
|
|||
.field("outdated?", &self.needs_rebuild())
|
||||
.field("width", &self.layout.width())
|
||||
.field("height", &self.layout.height())
|
||||
.finish()
|
||||
.field("links", &self.links)
|
||||
.finish_non_exhaustive()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -569,7 +569,7 @@ pub trait EditableTextCursor {
|
|||
impl<Str: Deref<Target = str> + TextStorage> Selectable for Str {
|
||||
type Cursor<'a> = StringCursor<'a> where Self: 'a;
|
||||
|
||||
fn cursor<'a>(&self, position: usize) -> Option<StringCursor> {
|
||||
fn cursor(&self, position: usize) -> Option<StringCursor> {
|
||||
let new_cursor = StringCursor {
|
||||
text: self,
|
||||
position,
|
||||
|
|
|
@ -48,7 +48,7 @@ pub const TEXTBOX_INSETS: Insets = Insets::new(4.0, 4.0, 4.0, 4.0);
|
|||
pub const SCROLLBAR_COLOR: Color = Color::rgb8(0xff, 0xff, 0xff);
|
||||
pub const SCROLLBAR_BORDER_COLOR: Color = Color::rgb8(0x77, 0x77, 0x77);
|
||||
pub const SCROLLBAR_MAX_OPACITY: f64 = 0.7;
|
||||
pub const SCROLLBAR_FADE_DELAY: u64 = 1500u64;
|
||||
pub const SCROLLBAR_FADE_DELAY: u64 = 1500;
|
||||
pub const SCROLLBAR_WIDTH: f64 = 8.;
|
||||
pub const SCROLLBAR_PAD: f64 = 2.;
|
||||
pub const SCROLLBAR_MIN_SIZE: f64 = 45.;
|
||||
|
|
|
@ -15,15 +15,13 @@ use std::hash::Hash;
|
|||
///
|
||||
/// It's useful when a backtrace would aid debugging but a crash can be avoided in release.
|
||||
macro_rules! debug_panic {
|
||||
() => { ... };
|
||||
($msg:expr) => {
|
||||
($msg:expr$(,)?) => {
|
||||
if cfg!(debug_assertions) {
|
||||
panic!($msg);
|
||||
} else {
|
||||
tracing::error!($msg);
|
||||
}
|
||||
};
|
||||
($msg:expr,) => { debug_panic!($msg) };
|
||||
($fmt:expr, $($arg:tt)+) => {
|
||||
if cfg!(debug_assertions) {
|
||||
panic!($fmt, $($arg)*);
|
||||
|
|
|
@ -136,7 +136,7 @@ impl Widget for Align {
|
|||
ctx.set_paint_insets(my_insets);
|
||||
if self.height_factor.is_some() {
|
||||
let baseline_offset = ctx.child_baseline_offset(&self.child);
|
||||
if baseline_offset > 0f64 {
|
||||
if baseline_offset > 0_f64 {
|
||||
ctx.set_baseline_offset(baseline_offset + extra_height / 2.0);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -516,8 +516,8 @@ impl Widget for Flex {
|
|||
// minor-axis values for all children
|
||||
let mut minor = self.direction.minor(bc.min());
|
||||
// these two are calculated but only used if we're baseline aligned
|
||||
let mut max_above_baseline = 0f64;
|
||||
let mut max_below_baseline = 0f64;
|
||||
let mut max_above_baseline = 0_f64;
|
||||
let mut max_below_baseline = 0_f64;
|
||||
let mut any_use_baseline = self.cross_alignment == CrossAxisAlignment::Baseline;
|
||||
|
||||
// Measure non-flex children.
|
||||
|
@ -1085,7 +1085,7 @@ mod tests {
|
|||
|
||||
// TODO - fix this test
|
||||
#[test]
|
||||
#[should_panic]
|
||||
#[ignore = "Unclear what test is trying to validate"]
|
||||
fn test_invalid_flex_params() {
|
||||
use float_cmp::approx_eq;
|
||||
let params = FlexParams::new(0.0, None);
|
||||
|
|
|
@ -35,8 +35,10 @@ tracing.workspace = true
|
|||
vello.workspace = true
|
||||
smallvec.workspace = true
|
||||
accesskit.workspace = true
|
||||
accesskit_winit.workspace = true
|
||||
tokio = { version = "1.38.0", features = ["rt", "rt-multi-thread", "time"] }
|
||||
|
||||
[dev-dependencies]
|
||||
accesskit_winit.workspace = true
|
||||
|
||||
[target.'cfg(target_os = "android")'.dev-dependencies]
|
||||
winit = { features = ["android-native-activity"], workspace = true }
|
||||
|
|
|
@ -90,7 +90,7 @@ where
|
|||
&mut self.state,
|
||||
)
|
||||
} else {
|
||||
eprintln!("Got action {action:?} for unknown widget. Did you forget to use `with_action_widget`?");
|
||||
tracing::error!("Got action {action:?} for unknown widget. Did you forget to use `with_action_widget`?");
|
||||
return;
|
||||
};
|
||||
let rebuild = match message_result {
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
// Copyright 2024 the Xilem Authors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
#![allow(clippy::comparison_chain)]
|
||||
// False-positive with dev-dependencies only used in examples
|
||||
#![cfg_attr(not(test), warn(unused_crate_dependencies))]
|
||||
#![warn(unnameable_types, unreachable_pub)]
|
||||
#![warn(clippy::print_stdout, clippy::print_stderr)]
|
||||
use std::{collections::HashMap, sync::Arc};
|
||||
|
||||
use masonry::{
|
||||
|
|
|
@ -3,7 +3,13 @@
|
|||
|
||||
#![cfg_attr(not(test), no_std)]
|
||||
#![forbid(unsafe_code)]
|
||||
#![warn(missing_docs, unreachable_pub)]
|
||||
#![warn(
|
||||
missing_docs,
|
||||
unreachable_pub,
|
||||
unused_crate_dependencies,
|
||||
clippy::print_stdout,
|
||||
clippy::print_stderr
|
||||
)]
|
||||
// https://linebender.org/blog/doc-include
|
||||
//! <!-- This license link is in a .rustdoc-hidden section, but we may as well give the correct link -->
|
||||
//! [LICENSE]: https://github.com/linebender/xilem/blob/main/xilem_core/LICENSE
|
||||
|
|
|
@ -41,8 +41,7 @@ It's not possible in Rust currently to check whether the (content of the) callba
|
|||
|
||||
/// Create a new `Memoize` view.
|
||||
pub fn new(data: D, child_cb: F) -> Self {
|
||||
#[allow(clippy::let_unit_value)]
|
||||
let _ = Self::ASSERT_CONTEXTLESS_FN;
|
||||
let () = Self::ASSERT_CONTEXTLESS_FN;
|
||||
Memoize { data, child_cb }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ pub struct ElementProps {
|
|||
pub(crate) attributes: Option<Box<Attributes>>,
|
||||
pub(crate) classes: Option<Box<Classes>>,
|
||||
pub(crate) styles: Option<Box<Styles>>,
|
||||
pub children: Vec<AnyPod>,
|
||||
pub(crate) children: Vec<AnyPod>,
|
||||
}
|
||||
|
||||
impl ElementProps {
|
||||
|
|
|
@ -27,7 +27,7 @@ impl AppState {
|
|||
}
|
||||
let title = self.new_todo.trim().to_string();
|
||||
self.new_todo.clear();
|
||||
let id = self.next_id();
|
||||
let id: u64 = self.next_id();
|
||||
self.todos.push(Todo::new(title, id));
|
||||
self.focus_new_todo = true;
|
||||
self.save();
|
||||
|
|
Loading…
Reference in New Issue