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

Add Linebender lint set v2. #744

Merged
merged 2 commits into from
Nov 25, 2024
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
11 changes: 11 additions & 0 deletions .clippy.toml
Original file line number Diff line number Diff line change
@@ -1 +1,12 @@
# LINEBENDER LINT SET - .clippy.toml - v1
# See https://linebender.org/wiki/canonical-lints/

# The default Clippy value is capped at 8 bytes, which was chosen to improve performance on 32-bit.
# Given that we are building for the future and even low-end mobile phones have 64-bit CPUs,
# it makes sense to optimize for 64-bit and accept the performance hits on 32-bit.
# 16 bytes is the number of bytes that fits into two 64-bit CPU registers.
trivial-copy-size-limit = 16

# END LINEBENDER LINT SET

doc-valid-idents = ["MotionMark", "WebGPU", "PostScript", ".."]
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

62 changes: 57 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ members = [
"vello_tests",

"examples/headless",
"examples/with_winit",
"examples/run_wasm",
"examples/scenes",
"examples/simple",
"examples/simple_sdl2",
"examples/with_winit",
]

[workspace.package]
Expand All @@ -32,11 +32,64 @@ license = "Apache-2.0 OR MIT"
repository = "https://github.com/linebender/vello"

[workspace.lints]
# LINEBENDER LINT SET - Cargo.toml - v2
# See https://linebender.org/wiki/canonical-lints/
rust.keyword_idents_2024 = "forbid"
rust.non_ascii_idents = "forbid"
rust.non_local_definitions = "forbid"
rust.unsafe_op_in_unsafe_fn = "forbid"

rust.elided_lifetimes_in_paths = "warn"
rust.let_underscore_drop = "warn"
rust.missing_debug_implementations = "warn"
rust.missing_docs = "warn"
rust.single_use_lifetimes = "warn"
rust.trivial_numeric_casts = "warn"
rust.unexpected_cfgs = "warn"
rust.unit_bindings = "warn"
rust.unnameable_types = "warn"
rust.unreachable_pub = "warn"
rust.unused_import_braces = "warn"
rust.unused_lifetimes = "warn"
rust.unused_macro_rules = "warn"
rust.unused_qualifications = "warn"
rust.variant_size_differences = "warn"

clippy.allow_attributes = "warn"
clippy.allow_attributes_without_reason = "warn"
clippy.cast_possible_truncation = "warn"
clippy.collection_is_never_read = "warn"
clippy.dbg_macro = "warn"
clippy.debug_assert_with_mut_call = "warn"
clippy.doc_markdown = "warn"
clippy.exhaustive_enums = "warn"
clippy.fn_to_numeric_cast_any = "warn" # Can't be forbid due to 'scenes' requiring an exception.
clippy.infinite_loop = "warn"
clippy.large_include_file = "warn"
clippy.large_stack_arrays = "warn"
clippy.match_same_arms = "warn"
clippy.mismatching_type_param_order = "warn"
clippy.missing_assert_message = "warn"
clippy.missing_errors_doc = "warn"
clippy.missing_fields_in_debug = "warn"
clippy.missing_panics_doc = "warn"
clippy.partial_pub_fields = "warn"
clippy.return_self_not_must_use = "warn"
clippy.same_functions_in_if_condition = "warn"
clippy.semicolon_if_nothing_returned = "warn"
# We use a modified version of `unreachable_pub`, where we mark associated functions of pub(crate) items as pub.
# This policy was implemented as it could gain begrudging consensus - there is no lint for this.
# rust.unreachable_pub = "warn"
clippy.shadow_unrelated = "warn"
clippy.should_panic_without_expect = "warn"
clippy.todo = "warn"
clippy.trivially_copy_pass_by_ref = "warn"
clippy.unseparated_literal_suffix = "warn"
clippy.use_self = "warn"
clippy.wildcard_imports = "warn"

clippy.cargo_common_metadata = "warn"
clippy.negative_feature_names = "warn"
clippy.redundant_feature_names = "warn"
clippy.wildcard_dependencies = "warn"
# END LINEBENDER LINT SET

[workspace.dependencies]
vello = { version = "0.3.0", path = "vello" }
Expand All @@ -50,7 +103,6 @@ peniko = "0.2.0"
# FIXME: This can be removed once peniko supports the schemars feature.
kurbo = "0.11.1"
futures-intrusive = "0.5.0"
raw-window-handle = "0.6.2"
smallvec = "1.13.2"
static_assertions = "1.1.0"
thiserror = "1.0.64"
Expand Down
18 changes: 14 additions & 4 deletions examples/headless/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
// Copyright 2023 the Vello Authors
// SPDX-License-Identifier: Apache-2.0 OR MIT

//! Headless

// The following lints are part of the Linebender standard set,
// but resolving them has been deferred for now.
// Feel free to send a PR that solves one or more of these.
#![allow(
clippy::cast_possible_truncation,
clippy::allow_attributes_without_reason
)]

use std::fs::File;
use std::num::NonZeroUsize;
use std::path::{Path, PathBuf};
Expand Down Expand Up @@ -206,10 +216,10 @@ async fn render(mut scenes: SceneSet, index: usize, args: &Args) -> Result<()> {
.join(&example_scene.config.name)
.with_extension("png");
let mut file = File::create(&out_path)?;
let mut encoder = png::Encoder::new(&mut file, width, height);
encoder.set_color(png::ColorType::Rgba);
encoder.set_depth(png::BitDepth::Eight);
let mut writer = encoder.write_header()?;
let mut png_encoder = png::Encoder::new(&mut file, width, height);
png_encoder.set_color(png::ColorType::Rgba);
png_encoder.set_depth(png::BitDepth::Eight);
let mut writer = png_encoder.write_header()?;
writer.write_image_data(&result_unpadded)?;
writer.finish()?;
println!("Wrote result ({width}x{height}) to {out_path:?}");
Expand Down
2 changes: 2 additions & 0 deletions examples/run_wasm/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Copyright 2022 the Vello Authors
// SPDX-License-Identifier: Apache-2.0 OR MIT

//! Wasm

/// Use [cargo-run-wasm](https://github.com/rukai/cargo-run-wasm) to build an example for web
///
/// Usage:
Expand Down
28 changes: 25 additions & 3 deletions examples/scenes/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,30 @@
// Copyright 2022 the Vello Authors
// SPDX-License-Identifier: Apache-2.0 OR MIT

// This is not a published crate, so we don't need to understand our public API
#![allow(unreachable_pub)]
//! Scenes

// The following lints are part of the Linebender standard set,
// but resolving them has been deferred for now.
// Feel free to send a PR that solves one or more of these.
#![allow(
missing_debug_implementations,
elided_lifetimes_in_paths,
single_use_lifetimes,
unreachable_pub,
missing_docs,
clippy::wildcard_imports,
clippy::unseparated_literal_suffix,
clippy::cast_possible_truncation,
clippy::shadow_unrelated,
clippy::missing_panics_doc,
clippy::missing_errors_doc,
clippy::partial_pub_fields,
clippy::use_self,
clippy::match_same_arms,
clippy::allow_attributes_without_reason,
clippy::allow_attributes,
clippy::fn_to_numeric_cast_any
)]

mod images;
mod mmark;
Expand Down Expand Up @@ -32,7 +54,7 @@ pub struct SceneParams<'a> {
pub text: &'a mut SimpleText,
pub images: &'a mut ImageCache,
pub resolution: Option<Vec2>,
pub base_color: Option<vello::peniko::Color>,
pub base_color: Option<Color>,
pub complexity: usize,
}

Expand Down
10 changes: 5 additions & 5 deletions examples/scenes/src/mmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ impl MMark {
}

impl TestScene for MMark {
fn render(&mut self, scene: &mut Scene, params: &mut SceneParams) {
fn render(&mut self, scene: &mut Scene, params: &mut SceneParams<'_>) {
let c = params.complexity;
let n = if c < 10 {
(c + 1) * 1000
Expand Down Expand Up @@ -101,7 +101,7 @@ impl TestScene for MMark {
);
path.truncate(0); // Should have clear method, to avoid allocations.
}
if rng.gen::<f32>() > 0.995 {
if rng.r#gen::<f32>() > 0.995 {
element.is_split ^= true;
}
}
Expand Down Expand Up @@ -161,8 +161,8 @@ impl Element {
)
};
let color = *COLORS.choose(&mut rng).unwrap();
let width = rng.gen::<f64>().powi(5) * 20.0 + 1.0;
let is_split = rng.gen();
let width = rng.r#gen::<f64>().powi(5) * 20.0 + 1.0;
let is_split = rng.r#gen();
Element {
seg,
color,
Expand Down Expand Up @@ -191,7 +191,7 @@ impl GridPoint {
GridPoint(x, y)
}

fn coordinate(&self) -> Point {
fn coordinate(self) -> Point {
let scale_x = WIDTH as f64 / ((GRID_WIDTH + 1) as f64);
let scale_y = HEIGHT as f64 / ((GRID_HEIGHT + 1) as f64);
Point::new(
Expand Down
4 changes: 2 additions & 2 deletions examples/scenes/src/pico_svg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ impl Parser {

fn rec_parse(
&mut self,
node: Node,
node: Node<'_, '_>,
properties: &RecursiveProperties,
items: &mut Vec<Item>,
) -> Result<(), Box<dyn std::error::Error>> {
Expand Down Expand Up @@ -274,7 +274,7 @@ fn parse_color(color: &str) -> Color {
}
}

fn modify_opacity(mut color: Color, attr_name: &str, node: Node) -> Color {
fn modify_opacity(mut color: Color, attr_name: &str, node: Node<'_, '_>) -> Color {
if let Some(opacity) = node.attribute(attr_name) {
let alpha: f64 = if let Some(o) = opacity.strip_suffix('%') {
let pctg = o.parse().unwrap_or(100.0);
Expand Down
2 changes: 1 addition & 1 deletion examples/scenes/src/svg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ pub fn svg_function_of<R: AsRef<str>>(
None,
48.,
None,
vello::kurbo::Affine::translate((110.0, 600.0)),
Affine::translate((110.0, 600.0)),
&format!("Loading {name}"),
),
Err(RecvTimeoutError::Disconnected) => {
Expand Down
44 changes: 22 additions & 22 deletions examples/scenes/src/test_scenes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -735,7 +735,7 @@ mod impls {
Affine::IDENTITY,
&Brush::Solid(Color::rgb8(128, 0, 0)),
None,
&[PathEl::MoveTo(center), PathEl::LineTo(p1)],
&[MoveTo(center), LineTo(p1)],
);
scene.fill(
Fill::NonZero,
Expand Down Expand Up @@ -1128,7 +1128,7 @@ mod impls {
scene.push_layer(Mix::Clip, 1.0, translate * rot, &base_tri);
}
let rot = Affine::rotate(rng.gen_range(0.0..PI));
let color = Color::rgb(rng.gen(), rng.gen(), rng.gen());
let color = Color::rgb(rng.r#gen(), rng.r#gen(), rng.r#gen());
scene.fill(Fill::NonZero, translate * rot, color, None, &base_tri);
for _ in 0..CLIPS_PER_FILL {
scene.pop_layer();
Expand All @@ -1141,7 +1141,7 @@ mod impls {

pub(super) fn render_cardioid(scene: &mut Scene) {
let n = 601;
let dth = std::f64::consts::PI * 2.0 / (n as f64);
let dth = PI * 2.0 / (n as f64);
let center = Point::new(1024.0, 768.0);
let r = 750.0;
let mut path = BezPath::new();
Expand Down Expand Up @@ -1571,59 +1571,59 @@ mod impls {
}
scene.pop_layer();

let large_background_rect = kurbo::Rect::new(-1000.0, -1000.0, 2000.0, 2000.0);
let inside_clip_rect = kurbo::Rect::new(11.0, 13.399999999999999, 59.0, 56.6);
let outside_clip_rect = kurbo::Rect::new(
let large_background_rect = Rect::new(-1000.0, -1000.0, 2000.0, 2000.0);
let inside_clip_rect = Rect::new(11.0, 13.399999999999999, 59.0, 56.6);
let outside_clip_rect = Rect::new(
12.599999999999998,
12.599999999999998,
57.400000000000006,
57.400000000000006,
);
let clip_rect = kurbo::Rect::new(0.0, 0.0, 74.4, 339.20000000000005);
let clip_rect = Rect::new(0.0, 0.0, 74.4, 339.20000000000005);
let scale = 2.0;

scene.push_layer(
BlendMode {
mix: peniko::Mix::Normal,
compose: peniko::Compose::SrcOver,
mix: Mix::Normal,
compose: Compose::SrcOver,
},
1.0,
Affine::new([scale, 0.0, 0.0, scale, 27.07470703125, 176.40660533027858]),
&clip_rect,
);

scene.fill(
peniko::Fill::NonZero,
kurbo::Affine::new([scale, 0.0, 0.0, scale, 27.07470703125, 176.40660533027858]),
peniko::Color::rgb8(0, 0, 255),
Fill::NonZero,
Affine::new([scale, 0.0, 0.0, scale, 27.07470703125, 176.40660533027858]),
Color::rgb8(0, 0, 255),
None,
&large_background_rect,
);
scene.fill(
peniko::Fill::NonZero,
kurbo::Affine::new([
Fill::NonZero,
Affine::new([
scale,
0.0,
0.0,
scale,
29.027636718750003,
182.9755506427786,
]),
peniko::Color::rgb8(0, 255, 0),
Color::rgb8(0, 255, 0),
None,
&inside_clip_rect,
);
scene.fill(
peniko::Fill::NonZero,
kurbo::Affine::new([
Fill::NonZero,
Affine::new([
scale,
0.0,
0.0,
scale,
29.027636718750003,
scale * 559.3583631427786,
]),
peniko::Color::rgb8(255, 0, 0),
Color::rgb8(255, 0, 0),
None,
&outside_clip_rect,
);
Expand Down Expand Up @@ -1778,8 +1778,8 @@ mod impls {
blob.push(b[1]);
blob.push(b[0]);
});
let data = vello::peniko::Blob::new(Arc::new(blob));
let image = vello::peniko::Image::new(data, vello::peniko::Format::Rgba8, 2, 2);
let data = Blob::new(Arc::new(blob));
let image = Image::new(data, Format::Rgba8, 2, 2);

scene.draw_image(
&image,
Expand Down Expand Up @@ -1820,8 +1820,8 @@ mod impls {
blob.push(b[1]);
blob.push(b[0]);
});
let data = vello::peniko::Blob::new(Arc::new(blob));
let image = vello::peniko::Image::new(data, vello::peniko::Format::Rgba8, 2, 2);
let data = Blob::new(Arc::new(blob));
let image = Image::new(data, Format::Rgba8, 2, 2);
let image = image.with_extend(Extend::Pad);
// Pad extend mode
scene.fill(
Expand Down
Loading