Skip to content

Commit

Permalink
Add linebender lint set to project
Browse files Browse the repository at this point in the history
This comes with a lot of carve-outs to keep the diff minimal.
Further PRs can remove these carve-outs.

The `#[allow]` attributes will need to be replaced with `#[expect]` when the MSRV bumps.
  • Loading branch information
PoignardAzur committed Nov 19, 2024
1 parent a0dbf96 commit 4cd241b
Show file tree
Hide file tree
Showing 18 changed files with 206 additions and 95 deletions.
57 changes: 55 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,63 @@ license = "Apache-2.0 OR MIT"
repository = "https://github.com/linebender/parley"

[workspace.lints]
# LINEBENDER LINT SET - v1
# 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 = "forbid"
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"
clippy.trivially_copy_pass_by_ref = "warn"
rust.unused_qualifications = "warn"
clippy.shadow_unrelated = "warn"
clippy.should_panic_without_expect = "warn"
clippy.todo = "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]
accesskit = "0.17"
Expand Down
11 changes: 7 additions & 4 deletions examples/swash_render/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
//! A simple example that lays out some text using Parley, rasterises the glyph using Swash
//! and and then renders it into a PNG using the `image` crate.

#![allow(clippy::cast_possible_truncation)]
#![allow(clippy::shadow_unrelated)]

use image::codecs::png::PngEncoder;
use image::{self, Pixel, Rgba, RgbaImage};
use parley::layout::{Alignment, Glyph, GlyphRun, Layout, PositionedLayoutItem};
Expand Down Expand Up @@ -185,7 +188,7 @@ fn main() {
path.pop();
path.pop();
path.push("_output");
let _ = std::fs::create_dir(path.clone());
drop(std::fs::create_dir(path.clone()));
path.push("swash_render.png");
path
};
Expand All @@ -196,7 +199,7 @@ fn main() {

fn render_glyph_run(
context: &mut ScaleContext,
glyph_run: &GlyphRun<Color>,
glyph_run: &GlyphRun<'_, Color>,
img: &mut RgbaImage,
padding: u32,
) {
Expand Down Expand Up @@ -254,7 +257,7 @@ fn render_glyph_run(

fn render_decoration(
img: &mut RgbaImage,
glyph_run: &GlyphRun<Color>,
glyph_run: &GlyphRun<'_, Color>,
color: Color,
offset: f32,
width: f32,
Expand All @@ -273,7 +276,7 @@ fn render_decoration(

fn render_glyph(
img: &mut RgbaImage,
scaler: &mut Scaler,
scaler: &mut Scaler<'_>,
color: Color,
glyph: Glyph,
glyph_x: f32,
Expand Down
15 changes: 11 additions & 4 deletions examples/tiny_skia_render/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
//! Note: Emoji rendering is not currently implemented in this example. See the swash example
//! if you need emoji rendering.

#![allow(clippy::cast_possible_truncation)]
#![allow(clippy::shadow_unrelated)]

use parley::{
Alignment, FontContext, FontWeight, GenericFamily, GlyphRun, InlineBox, Layout, LayoutContext,
PositionedLayoutItem, StyleProperty,
Expand Down Expand Up @@ -119,7 +122,7 @@ fn main() {
path.pop();
path.pop();
path.push("_output");
let _ = std::fs::create_dir(path.clone());
drop(std::fs::create_dir(path.clone()));
path.push("tiny_skia_render.png");
path
};
Expand All @@ -130,7 +133,11 @@ fn to_tiny_skia(color: PenikoColor) -> TinySkiaColor {
TinySkiaColor::from_rgba8(color.r, color.g, color.b, color.a)
}

fn render_glyph_run(glyph_run: &GlyphRun<PenikoColor>, pen: &mut TinySkiaPen<'_>, padding: u32) {
fn render_glyph_run(
glyph_run: &GlyphRun<'_, PenikoColor>,
pen: &mut TinySkiaPen<'_>,
padding: u32,
) {
// Resolve properties of the GlyphRun
let mut run_x = glyph_run.offset();
let run_y = glyph_run.baseline();
Expand Down Expand Up @@ -188,7 +195,7 @@ fn render_glyph_run(glyph_run: &GlyphRun<PenikoColor>, pen: &mut TinySkiaPen<'_>

fn render_decoration(
pen: &mut TinySkiaPen<'_>,
glyph_run: &GlyphRun<PenikoColor>,
glyph_run: &GlyphRun<'_, PenikoColor>,
color: PenikoColor,
offset: f32,
width: f32,
Expand All @@ -210,7 +217,7 @@ struct TinySkiaPen<'a> {
}

impl TinySkiaPen<'_> {
fn new(pixmap: PixmapMut) -> TinySkiaPen {
fn new(pixmap: PixmapMut<'_>) -> TinySkiaPen<'_> {
TinySkiaPen {
pixmap,
x: 0.0,
Expand Down
9 changes: 9 additions & 0 deletions examples/vello_editor/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
// Copyright 2024 the Parley Authors
// SPDX-License-Identifier: Apache-2.0 OR MIT

#![allow(elided_lifetimes_in_paths)]
#![allow(missing_debug_implementations)]
#![allow(missing_docs)]
#![allow(unreachable_pub)]
#![allow(clippy::cast_possible_truncation)]
#![allow(clippy::shadow_unrelated)]
#![allow(clippy::unseparated_literal_suffix)]
#![allow(clippy::wildcard_imports)]

use accesskit::{Node, Rect, Role, Tree, TreeUpdate};
use anyhow::Result;
use std::num::NonZeroUsize;
Expand Down
2 changes: 1 addition & 1 deletion fontique/src/backend/fontconfig/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ pub fn parse_config(path: &Path, sink: &mut impl ParserSink) {
}
"include" => {
if let Some(path) = resolve_dir(child, path) {
let _ = include_config(&path, sink);
drop(include_config(&path, sink));
}
}
"match" => {
Expand Down
14 changes: 14 additions & 0 deletions fontique/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,20 @@

#![cfg_attr(docsrs, feature(doc_auto_cfg))]
#![cfg_attr(not(feature = "std"), no_std)]
#![allow(elided_lifetimes_in_paths)]
#![allow(missing_debug_implementations)]
#![allow(missing_docs)]
#![allow(single_use_lifetimes)]
#![allow(trivial_numeric_casts)]
#![allow(unnameable_types)]
#![allow(unreachable_pub)]
#![allow(clippy::cast_possible_truncation)]
#![allow(clippy::exhaustive_enums)]
#![allow(clippy::partial_pub_fields)]
#![allow(clippy::shadow_unrelated)]
#![allow(clippy::unseparated_literal_suffix)]
#![allow(clippy::use_self)]
#![allow(clippy::wildcard_imports)]

#[cfg(not(any(feature = "std", feature = "libm")))]
compile_error!("fontique requires either the `std` or `libm` feature to be enabled");
Expand Down
18 changes: 9 additions & 9 deletions parley/src/bidi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ use swash::text::{BidiClass, BracketType, Codepoint as _};
use BidiClass::*;

/// Type alias for a bidirectional level.
pub type BidiLevel = u8;
pub(crate) type BidiLevel = u8;

/// Resolver for the Unicode bidirectional algorithm.
#[derive(Clone, Default)]
pub struct BidiResolver {
pub(crate) struct BidiResolver {
base_level: BidiLevel,
levels: Vec<BidiLevel>,
initial_types: Vec<BidiClass>,
Expand All @@ -27,7 +27,7 @@ pub struct BidiResolver {

impl BidiResolver {
/// Creates a new resolver.
pub fn new() -> Self {
pub(crate) fn new() -> Self {
Self {
base_level: 0,
levels: Vec::new(),
Expand All @@ -42,18 +42,18 @@ impl BidiResolver {
}

/// Returns the base level of the text.
pub fn base_level(&self) -> u8 {
pub(crate) fn base_level(&self) -> u8 {
self.base_level
}

/// Returns the sequence of bidi levels corresponding to all characters in the
/// paragraph.
pub fn levels(&self) -> &[BidiLevel] {
pub(crate) fn levels(&self) -> &[BidiLevel] {
&self.levels
}

/// Clears the resolver state.
pub fn clear(&mut self) {
pub(crate) fn clear(&mut self) {
self.initial_types.clear();
self.levels.clear();
self.types.clear();
Expand All @@ -65,7 +65,7 @@ impl BidiResolver {

/// Resolves a paragraph with the specified base direction and
/// precomputed types.
pub fn resolve(
pub(crate) fn resolve(
&mut self,
chars: impl Iterator<Item = (char, BidiClass)>,
base_level: Option<u8>,
Expand Down Expand Up @@ -642,7 +642,7 @@ impl BidiResolver {
}

/// Returns a default bidi type for a level.
pub fn type_from_level(level: BidiLevel) -> BidiClass {
pub(crate) fn type_from_level(level: BidiLevel) -> BidiClass {
if level & 1 == 0 {
L
} else {
Expand All @@ -651,7 +651,7 @@ pub fn type_from_level(level: BidiLevel) -> BidiClass {
}

/// Computes an ordering for a sequence of bidi runs based on levels.
pub fn _reorder<F>(order: &mut [usize], levels: F)
pub(crate) fn _reorder<F>(order: &mut [usize], levels: F)
where
F: Fn(usize) -> BidiLevel,
{
Expand Down
9 changes: 0 additions & 9 deletions parley/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,6 @@ impl<B: Brush> LayoutContext<B> {
.resolve_entire_style_set(font_ctx, raw_style, scale)
}

pub fn resolve_style(
&mut self,
font_ctx: &mut FontContext,
scale: f32,
raw_property: &StyleProperty<B>,
) -> ResolvedProperty<B> {
self.rcx.resolve_property(font_ctx, raw_property, scale)
}

pub fn ranged_builder<'a>(
&'a mut self,
fcx: &'a mut FontContext,
Expand Down
2 changes: 1 addition & 1 deletion parley/src/layout/line/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

use super::*;

pub mod greedy;
pub(crate) mod greedy;

impl<'a, B: Brush> Line<'a, B> {
/// Returns the metrics for the line.
Expand Down
1 change: 1 addition & 0 deletions parley/src/layout/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ pub struct Line<'a, B: Brush> {
data: &'a LineData,
}

#[allow(clippy::partial_pub_fields)]
/// Style properties.
#[derive(Clone, Debug)]
pub struct Style<B: Brush> {
Expand Down
15 changes: 15 additions & 0 deletions parley/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,21 @@

#![cfg_attr(docsrs, feature(doc_auto_cfg))]
#![cfg_attr(not(feature = "std"), no_std)]
#![allow(elided_lifetimes_in_paths)]
#![allow(missing_debug_implementations)]
#![allow(missing_docs)]
#![allow(single_use_lifetimes)]
#![allow(trivial_numeric_casts)]
#![allow(unnameable_types)]
#![allow(clippy::cast_possible_truncation)]
#![allow(clippy::exhaustive_enums)]
#![allow(clippy::missing_assert_message)]
#![allow(clippy::missing_panics_doc)]
#![allow(clippy::return_self_not_must_use)]
#![allow(clippy::shadow_unrelated)]
#![allow(clippy::unseparated_literal_suffix)]
#![allow(clippy::use_self)]
#![allow(clippy::wildcard_imports)]

#[cfg(not(any(feature = "std", feature = "libm")))]
compile_error!("parley requires either the `std` or `libm` feature to be enabled");
Expand Down
Loading

0 comments on commit 4cd241b

Please sign in to comment.