🔧 Enable back clippy rules (#6492)

* 🔧 Fix lint script (rust)

* 🔧 Temporarily add clippy rules to ignore so lint script passes

* 💄 Fix clippy rule crate_in_macro_def

* 💄 Fix clippy rule redundant-static-lifetimes

* 💄 Fix clippy rule unnecessary_cast

* 💄 Fix clippy rule nonminimal_bool

* 💄 Fix clippy rule redundant_pattern_matching

* 💄 Fix clippy rule assign_op_pattern

* 💄 Fix clippy rule needless_lifetimes

* 💄 Fix clippy rule for_kv_map

* 💄 Fix clippy rule ptr_arg

* 💄 Fix clippy rule match_like_matches_macro

* 💄 Fix clippy rule macro_metavars_in_unsafe

* 💄 Fix clippy rule map_clone

* 💄 Fix clippy rule wrong_self_convention

* 💄 Fix clippy rule vec_box

* 💄 Fix clippy rule useless_format

* 💄 Fix clippy rule unwrap_or_default

* 💄 Fix clippy rule unused_unit

* 💄 Fix clippy rule unnecessary_to_owned

* 💄 Fix clippy rule too_many_arguments

* 💄 Fix clippy rule slow_vector_initialization

* 💄 Fix clippy rule single_match

* 💄 Fix clippy rule redundant_field_names

* 💄 Fix clippy rule rendudant_closure

* 💄 Fix clippy rule needless_return

* 💄 Fix clippy rule needless_range_loop

* 💄 Fix clippy rule needless_borrows_for_generic_args

* 💄 Fix clippy rule needless-borrow

* 💄 Fix clippy rule missing_transmute_annotations

* 💄 Fix clippy rule map_entry

* 💄 Fix clippy rule manual_map

* 💄 Fix clippy rule len_zero

* 💄 Fix clippy rule from_over_into

* 💄 Fix clippy rule field_reassign_with_default

* 💄 Fix clippy rule enum_variant_names

* 💄 Fix clippy rule derivable_impls

* 💄 Fix clippy rule clone_on_copy

* 💄 Fix clippy rule box_collection

* 🔧 Make lint script also check test config target

* 🔧 Remove cargo-watch as a lib dependency

* 💄 Fix clippy rule for join_bounds

* 🔧 Fix lint script return code

---------

Co-authored-by: alonso.torres <alonso.torres@kaleidos.net>
This commit is contained in:
Belén Albeza 2025-05-19 11:14:55 +02:00 committed by GitHub
parent 051c2a7e99
commit 8afd217a80
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
35 changed files with 447 additions and 2338 deletions

View file

@ -12,17 +12,17 @@ impl Default for BlendMode {
impl From<i32> for BlendMode {
fn from(value: i32) -> Self {
if value <= skia::BlendMode::Luminosity as i32 {
unsafe { Self(std::mem::transmute(value)) }
unsafe { Self(std::mem::transmute::<i32, skia_safe::BlendMode>(value)) }
} else {
Self::default()
}
}
}
impl Into<skia::BlendMode> for BlendMode {
fn into(self) -> skia::BlendMode {
match self {
Self(skia_blend) => skia_blend,
impl From<BlendMode> for skia::BlendMode {
fn from(val: BlendMode) -> Self {
match val {
BlendMode(skia_blend) => skia_blend,
}
}
}

View file

@ -23,7 +23,7 @@ fn render_debug_view(render_state: &mut RenderState) {
paint.set_color(skia::Color::from_rgb(255, 0, 255));
paint.set_stroke_width(1.);
let rect = get_debug_rect(render_state.viewbox.area.clone());
let rect = get_debug_rect(render_state.viewbox.area);
render_state
.surfaces
.canvas(SurfaceId::Debug)
@ -55,7 +55,7 @@ pub fn render_wasm_label(render_state: &mut RenderState) {
let p = skia::Point::new(width as f32 - 25.0 - scalar, height as f32 - 25.0);
let debug_font = render_state.fonts.debug_font();
canvas.draw_str(str, p, &debug_font, &paint);
canvas.draw_str(str, p, debug_font, &paint);
}
pub fn render_debug_shape(render_state: &mut RenderState, element: &Shape, intersected: bool) {
@ -90,12 +90,7 @@ pub fn render_debug_tiles_for_viewbox(
let str_rect = format!("{} {} {} {}", sx, sy, ex, ey);
let debug_font = render_state.fonts.debug_font();
canvas.draw_str(
str_rect,
skia::Point::new(100.0, 150.0),
&debug_font,
&paint,
);
canvas.draw_str(str_rect, skia::Point::new(100.0, 150.0), debug_font, &paint);
}
// Renders the tiles in the viewbox
@ -111,12 +106,7 @@ pub fn render_debug_viewbox_tiles(render_state: &mut RenderState) {
let str_rect = format!("{} {} {} {}", sx, sy, ex, ey);
let debug_font = render_state.fonts.debug_font();
canvas.draw_str(
str_rect,
skia::Point::new(100.0, 100.0),
&debug_font,
&paint,
);
canvas.draw_str(str_rect, skia::Point::new(100.0, 100.0), debug_font, &paint);
let tile_size = tiles::get_tile_size(scale);
for y in sy..=ey {
@ -131,8 +121,8 @@ pub fn render_debug_viewbox_tiles(render_state: &mut RenderState) {
let p = skia::Point::new(debug_rect.x(), debug_rect.y() - 1.);
let str = format!("{}:{}", x, y);
let debug_font = render_state.fonts.debug_font();
canvas.draw_str(str, p, &debug_font, &paint);
canvas.draw_rect(&debug_rect, &paint);
canvas.draw_str(str, p, debug_font, &paint);
canvas.draw_rect(debug_rect, &paint);
}
}
}
@ -166,8 +156,8 @@ pub fn render_debug_tiles(render_state: &mut RenderState) {
let str = format!("{}:{} {}", x, y, shape_count);
let debug_font = render_state.fonts.debug_font();
canvas.draw_str(str, p, &debug_font, &paint);
canvas.draw_rect(&debug_rect, &paint);
canvas.draw_str(str, p, debug_font, &paint);
canvas.draw_rect(debug_rect, &paint);
}
}
}
@ -219,11 +209,11 @@ pub fn render_workspace_current_tile(
let mut p = skia::Paint::default();
p.set_stroke_width(1.);
p.set_style(skia::PaintStyle::Stroke);
canvas.draw_rect(&rect, &p);
canvas.draw_rect(rect, &p);
let point = skia::Point::new(rect.x() + 10., rect.y() + 20.);
p.set_stroke_width(1.);
let str = format!("{prefix} {}:{}", tile.0, tile.1);
let debug_font = render_state.fonts.debug_font();
canvas.draw_str(str, point, &debug_font, &p);
canvas.draw_str(str, point, debug_font, &p);
}

View file

@ -62,7 +62,7 @@ fn draw_image_fill(
corners: Some(corners),
..
}) => {
let rrect: RRect = RRect::new_rect_radii(container, &corners);
let rrect: RRect = RRect::new_rect_radii(container, corners);
canvas.clip_rrect(rrect, skia::ClipOp::Intersect, antialias);
}
Type::Rect(_) | Type::Frame(_) => {
@ -77,7 +77,7 @@ fn draw_image_fill(
if let Some(path) = shape_type.path() {
if let Some(path_transform) = path_transform {
canvas.clip_path(
&path.to_skia_path().transform(&path_transform),
path.to_skia_path().transform(&path_transform),
skia::ClipOp::Intersect,
antialias,
);
@ -98,7 +98,7 @@ fn draw_image_fill(
None,
dest_rect,
render_state.sampling_options,
&paint,
paint,
);
}

View file

@ -3,7 +3,7 @@ use skia_safe::{self as skia, textlayout, Font, FontMgr};
use crate::shapes::{FontFamily, FontStyle};
use crate::uuid::Uuid;
pub static DEFAULT_EMOJI_FONT: &'static str = "noto-color-emoji";
pub static DEFAULT_EMOJI_FONT: &str = "noto-color-emoji";
const DEFAULT_FONT_BYTES: &[u8] = include_bytes!("../fonts/sourcesanspro-regular.ttf");

View file

@ -1,20 +1,11 @@
use crate::options;
#[derive(Debug, Copy, Clone, PartialEq)]
#[derive(Debug, Copy, Clone, PartialEq, Default)]
pub struct RenderOptions {
pub flags: u32,
pub dpr: Option<f32>,
}
impl Default for RenderOptions {
fn default() -> Self {
Self {
flags: 0x00,
dpr: None,
}
}
}
impl RenderOptions {
pub fn is_debug_visible(&self) -> bool {
self.flags & options::DEBUG_VISIBLE == options::DEBUG_VISIBLE

View file

@ -8,7 +8,7 @@ use skia_safe::{textlayout::Paragraph, Paint};
pub fn render_fill_drop_shadows(render_state: &mut RenderState, shape: &Shape, antialias: bool) {
if shape.has_fills() {
for shadow in shape.drop_shadows().rev().filter(|s| !s.hidden()) {
render_fill_drop_shadow(render_state, &shape, &shadow, antialias);
render_fill_drop_shadow(render_state, shape, shadow, antialias);
}
}
}
@ -26,7 +26,7 @@ fn render_fill_drop_shadow(
pub fn render_fill_inner_shadows(render_state: &mut RenderState, shape: &Shape, antialias: bool) {
if shape.has_fills() {
for shadow in shape.inner_shadows().rev().filter(|s| !s.hidden()) {
render_fill_inner_shadow(render_state, &shape, &shadow, antialias);
render_fill_inner_shadow(render_state, shape, shadow, antialias);
}
}
}
@ -52,7 +52,7 @@ pub fn render_stroke_drop_shadows(
let filter = shadow.get_drop_shadow_filter();
strokes::render(
render_state,
&shape,
shape,
stroke,
Some(SurfaceId::Strokes), // FIXME
filter.as_ref(),
@ -73,7 +73,7 @@ pub fn render_stroke_inner_shadows(
let filter = shadow.get_inner_shadow_filter();
strokes::render(
render_state,
&shape,
shape,
stroke,
Some(SurfaceId::Strokes), // FIXME
filter.as_ref(),
@ -90,7 +90,7 @@ pub fn render_text_drop_shadows(
antialias: bool,
) {
for shadow in shape.drop_shadows().rev().filter(|s| !s.hidden()) {
render_text_drop_shadow(render_state, &shape, &shadow, &paragraphs, antialias);
render_text_drop_shadow(render_state, shape, shadow, paragraphs, antialias);
}
}
@ -101,12 +101,12 @@ pub fn render_text_drop_shadow(
paragraphs: &[Vec<Paragraph>],
antialias: bool,
) {
let paint = &shadow.get_drop_shadow_paint(antialias);
let paint = shadow.get_drop_shadow_paint(antialias);
text::render(
render_state,
shape,
&paragraphs,
paragraphs,
Some(SurfaceId::DropShadows),
Some(paint),
);
@ -119,7 +119,7 @@ pub fn render_text_inner_shadows(
antialias: bool,
) {
for shadow in shape.inner_shadows().rev().filter(|s| !s.hidden()) {
render_text_inner_shadow(render_state, &shape, &shadow, &paragraphs, antialias);
render_text_inner_shadow(render_state, shape, shadow, paragraphs, antialias);
}
}
@ -130,12 +130,12 @@ pub fn render_text_inner_shadow(
paragraphs: &[Vec<Paragraph>],
antialias: bool,
) {
let paint = &shadow.get_inner_shadow_paint(antialias);
let paint = shadow.get_inner_shadow_paint(antialias);
text::render(
render_state,
shape,
&paragraphs,
paragraphs,
Some(SurfaceId::InnerShadows),
Some(paint),
);

View file

@ -7,6 +7,8 @@ use skia_safe::{self as skia, ImageFilter, RRect};
use super::{RenderState, SurfaceId};
// FIXME: See if we can simplify these arguments
#[allow(clippy::too_many_arguments)]
fn draw_stroke_on_rect(
canvas: &skia::Canvas,
stroke: &Stroke,
@ -36,11 +38,13 @@ fn draw_stroke_on_rect(
canvas.draw_rrect(rrect, &paint);
}
None => {
canvas.draw_rect(&stroke_rect, &paint);
canvas.draw_rect(stroke_rect, &paint);
}
}
}
// FIXME: See if we can simplify these arguments
#[allow(clippy::too_many_arguments)]
fn draw_stroke_on_circle(
canvas: &skia::Canvas,
stroke: &Stroke,
@ -62,9 +66,11 @@ fn draw_stroke_on_circle(
paint.set_image_filter(filter.clone());
}
canvas.draw_oval(&stroke_rect, &paint);
canvas.draw_oval(stroke_rect, &paint);
}
// FIXME: See if we can simplify these arguments
#[allow(clippy::too_many_arguments)]
pub fn draw_stroke_on_path(
canvas: &skia::Canvas,
stroke: &Stroke,
@ -90,18 +96,18 @@ pub fn draw_stroke_on_path(
// Draw the different kind of strokes for a path requires different strategies:
match stroke.render_kind(is_open) {
// For inner stroke we draw a center stroke (with double width) and clip to the original path (that way the extra outer stroke is removed)
StrokeKind::InnerStroke => {
StrokeKind::Inner => {
canvas.save(); // As we are using clear for surfaces we use save and restore here to still be able to clean the full surface
canvas.clip_path(&skia_path, skia::ClipOp::Intersect, antialias);
canvas.draw_path(&skia_path, &paint);
canvas.restore();
}
// For center stroke we don't need to do anything extra
StrokeKind::CenterStroke => {
StrokeKind::Center => {
canvas.draw_path(&skia_path, &paint);
}
// For outer stroke we draw a center stroke (with double width) and use another path with blend mode clear to remove the inner stroke added
StrokeKind::OuterStroke => {
StrokeKind::Outer => {
let mut outer_paint = skia::Paint::default();
outer_paint.set_blend_mode(skia::BlendMode::SrcOver);
outer_paint.set_anti_alias(antialias);
@ -121,7 +127,7 @@ pub fn draw_stroke_on_path(
handle_stroke_caps(
&mut skia_path,
stroke,
&selrect,
selrect,
canvas,
is_open,
svg_attrs,
@ -144,31 +150,33 @@ fn handle_stroke_cap(
StrokeCap::None => {}
StrokeCap::Line => {
// We also draw this square cap to fill the gap between the path and the arrow
draw_square_cap(canvas, &paint, p1, p2, width, 0.);
draw_square_cap(canvas, paint, p1, p2, width, 0.);
paint.set_style(skia::PaintStyle::Stroke);
draw_arrow_cap(canvas, &paint, p1, p2, width * 4.);
draw_arrow_cap(canvas, paint, p1, p2, width * 4.);
}
StrokeCap::Triangle => {
draw_triangle_cap(canvas, &paint, p1, p2, width * 4.);
draw_triangle_cap(canvas, paint, p1, p2, width * 4.);
}
StrokeCap::Rectangle => {
draw_square_cap(canvas, &paint, p1, p2, width * 4., 0.);
draw_square_cap(canvas, paint, p1, p2, width * 4., 0.);
}
StrokeCap::Circle => {
canvas.draw_circle((p1.x, p1.y), width * 2., &paint);
canvas.draw_circle((p1.x, p1.y), width * 2., paint);
}
StrokeCap::Diamond => {
draw_square_cap(canvas, &paint, p1, p2, width * 4., 45.);
draw_square_cap(canvas, paint, p1, p2, width * 4., 45.);
}
StrokeCap::Round => {
canvas.draw_circle((p1.x, p1.y), width / 2.0, &paint);
canvas.draw_circle((p1.x, p1.y), width / 2.0, paint);
}
StrokeCap::Square => {
draw_square_cap(canvas, &paint, p1, p2, width, 0.);
draw_square_cap(canvas, paint, p1, p2, width, 0.);
}
}
}
// FIXME: See if we can simplify these arguments
#[allow(clippy::too_many_arguments)]
fn handle_stroke_caps(
path: &mut skia::Path,
stroke: &Stroke,
@ -238,7 +246,7 @@ fn draw_square_cap(
Point::new(rect.left(), rect.bottom()),
];
let mut transformed_points = points.clone();
let mut transformed_points = points;
matrix.map_points(&mut transformed_points, &points);
let mut path = skia::Path::new();
@ -272,7 +280,7 @@ fn draw_arrow_cap(
Point::new(center.x + size, center.y + half_height),
];
let mut transformed_points = points.clone();
let mut transformed_points = points;
matrix.map_points(&mut transformed_points, &points);
let mut path = skia::Path::new();
@ -306,7 +314,7 @@ fn draw_triangle_cap(
Point::new(center.x + size, center.y + half_height),
];
let mut transformed_points = points.clone();
let mut transformed_points = points;
matrix.map_points(&mut transformed_points, &points);
let mut path = skia::Path::new();
@ -406,11 +414,11 @@ fn draw_image_stroke_in_container(
path.transform(&path_transform.unwrap());
let stroke_kind = stroke.render_kind(p.is_open());
match stroke_kind {
StrokeKind::InnerStroke => {
StrokeKind::Inner => {
canvas.clip_path(&path, skia::ClipOp::Intersect, antialias);
}
StrokeKind::CenterStroke => {}
StrokeKind::OuterStroke => {
StrokeKind::Center => {}
StrokeKind::Outer => {
canvas.clip_path(&path, skia::ClipOp::Difference, antialias);
}
}
@ -418,7 +426,7 @@ fn draw_image_stroke_in_container(
let mut paint =
stroke.to_stroked_paint(is_open, &outer_rect, svg_attrs, scale, antialias);
canvas.draw_path(&path, &paint);
if stroke.render_kind(is_open) == StrokeKind::OuterStroke {
if stroke.render_kind(is_open) == StrokeKind::Outer {
// Small extra inner stroke to overlap with the fill
// and avoid unnecesary artifacts.
paint.set_stroke_width(1. / scale);
@ -461,7 +469,7 @@ fn draw_image_stroke_in_container(
// Clear outer stroke for paths if necessary. When adding an outer stroke we need to empty the stroke added too in the inner area.
if let Type::Path(p) = &shape.shape_type {
if stroke.render_kind(p.is_open()) == StrokeKind::OuterStroke {
if stroke.render_kind(p.is_open()) == StrokeKind::Outer {
let mut path = p.to_skia_path();
path.transform(&path_transform.unwrap());
let mut clear_paint = skia::Paint::default();
@ -494,7 +502,7 @@ pub fn render(
let path_transform = shape.to_path_transform();
let svg_attrs = &shape.svg_attrs;
if !shadow.is_some() && matches!(stroke.fill, Fill::Image(_)) {
if shadow.is_none() && matches!(stroke.fill, Fill::Image(_)) {
if let Fill::Image(image_fill) = &stroke.fill {
draw_image_stroke_in_container(render_state, shape, stroke, image_fill, antialias);
}

View file

@ -105,7 +105,7 @@ impl Surfaces {
let encoded_image = image
.encode(context.as_mut(), skia::EncodedImageFormat::PNG, None)
.unwrap();
general_purpose::STANDARD.encode(&encoded_image.as_bytes())
general_purpose::STANDARD.encode(encoded_image.as_bytes())
}
pub fn base64_snapshot_rect(&mut self, id: SurfaceId, irect: skia::IRect) -> Option<String> {
@ -115,7 +115,7 @@ impl Surfaces {
let encoded_image = image
.encode(context.as_mut(), skia::EncodedImageFormat::PNG, None)
.unwrap();
return Some(general_purpose::STANDARD.encode(&encoded_image.as_bytes()));
return Some(general_purpose::STANDARD.encode(encoded_image.as_bytes()));
}
None
}
@ -137,7 +137,7 @@ impl Surfaces {
.draw(self.canvas(to), (0.0, 0.0), sampling_options, paint);
}
pub fn apply_mut(&mut self, ids: &[SurfaceId], mut f: impl FnMut(&mut skia::Surface) -> ()) {
pub fn apply_mut(&mut self, ids: &[SurfaceId], mut f: impl FnMut(&mut skia::Surface)) {
for id in ids {
let surface = self.get_mut(*id);
f(surface);
@ -257,10 +257,10 @@ impl Surfaces {
self.current.height() - TILE_SIZE_MULTIPLIER * self.margins.height,
);
if let Some(snapshot) = self.current.image_snapshot_with_bounds(&rect) {
if let Some(snapshot) = self.current.image_snapshot_with_bounds(rect) {
self.tiles.add(tile, snapshot.clone());
self.cache.canvas().draw_image_rect(
&snapshot.clone(),
snapshot.clone(),
None,
tile_rect,
&skia::Paint::default(),
@ -302,7 +302,7 @@ impl TileTextureCache {
}
pub fn has(&mut self, tile: Tile) -> bool {
return self.grid.contains_key(&tile);
self.grid.contains_key(&tile)
}
fn remove_list(&mut self, marked: Vec<Tile>) {
@ -318,7 +318,7 @@ impl TileTextureCache {
.iter_mut()
.filter_map(|(tile, _)| {
if !self.visited.contains_key(tile) {
Some(tile.clone())
Some(*tile)
} else {
None
}

View file

@ -1,15 +1,15 @@
use super::{RenderState, Shape, SurfaceId};
use skia_safe::{self as skia, canvas::SaveLayerRec, paint, textlayout::Paragraph};
use skia_safe::{self as skia, canvas::SaveLayerRec, textlayout::Paragraph};
pub fn render(
render_state: &mut RenderState,
shape: &Shape,
paragraphs: &[Vec<Paragraph>],
surface_id: Option<SurfaceId>,
paint: Option<&paint::Paint>,
paint: Option<skia::Paint>,
) {
let default_paint = skia::Paint::default();
let mask = SaveLayerRec::default().paint(&paint.unwrap_or(&default_paint));
let mask_paint = paint.unwrap_or_default();
let mask = SaveLayerRec::default().paint(&mask_paint);
let canvas = render_state
.surfaces
.canvas(surface_id.unwrap_or(SurfaceId::Fills));

View file

@ -74,7 +74,7 @@ impl TileHashMap {
}
pub fn get_shapes_at(&mut self, tile: Tile) -> Option<&IndexSet<Uuid>> {
return self.grid.get(&tile);
self.grid.get(&tile)
}
pub fn remove_shape_at(&mut self, tile: Tile, id: Uuid) {
@ -92,13 +92,8 @@ impl TileHashMap {
}
pub fn add_shape_at(&mut self, tile: Tile, shape_id: Uuid) {
if !self.grid.contains_key(&tile) {
self.grid.insert(tile, IndexSet::new());
}
if !self.index.contains_key(&shape_id) {
self.index.insert(shape_id, HashSet::new());
}
self.grid.entry(tile).or_default();
self.index.entry(shape_id).or_default();
let tile_set = self.grid.get_mut(&tile).unwrap();
tile_set.insert(shape_id);