mirror of
https://github.com/typst/typst
synced 2025-05-14 17:15:28 +08:00
Use clippy workspace lints and inline format args (#2771)
This commit is contained in:
parent
3c2b61ee7d
commit
e36a18b991
@ -132,3 +132,6 @@ codegen-units = 1
|
|||||||
|
|
||||||
[profile.release.package."typst-cli"]
|
[profile.release.package."typst-cli"]
|
||||||
strip = true
|
strip = true
|
||||||
|
|
||||||
|
[workspace.lints.clippy]
|
||||||
|
uninlined_format_args = "warn"
|
||||||
|
@ -74,3 +74,6 @@ embed-fonts = []
|
|||||||
|
|
||||||
# Permits the CLI to update itself without a package manager
|
# Permits the CLI to update itself without a package manager
|
||||||
self-update = ["dep:self-replace", "dep:xz2", "dep:zip", "ureq/json"]
|
self-update = ["dep:self-replace", "dep:xz2", "dep:zip", "ureq/json"]
|
||||||
|
|
||||||
|
[lints]
|
||||||
|
workspace = true
|
||||||
|
@ -198,7 +198,7 @@ impl RemoteReader {
|
|||||||
}))
|
}))
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
None => format!("Total: {} Speed: {} Elapsed: {}", total, speed_h, elapsed,),
|
None => format!("Total: {total} Speed: {speed_h} Elapsed: {elapsed}"),
|
||||||
};
|
};
|
||||||
|
|
||||||
let _ = write!(self.stderr, "{output}");
|
let _ = write!(self.stderr, "{output}");
|
||||||
@ -252,6 +252,6 @@ fn as_time_unit(size: usize, include_suffix: bool) -> String {
|
|||||||
} else if size >= KI {
|
} else if size >= KI {
|
||||||
format!("{:5.1} KiB{}", size / KI, suffix)
|
format!("{:5.1} KiB{}", size / KI, suffix)
|
||||||
} else {
|
} else {
|
||||||
format!("{size:3.0} B{}", suffix)
|
format!("{size:3.0} B{suffix}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -102,12 +102,10 @@ impl Release {
|
|||||||
pub fn from_tag(tag: Option<&Version>) -> StrResult<Release> {
|
pub fn from_tag(tag: Option<&Version>) -> StrResult<Release> {
|
||||||
let url = match tag {
|
let url = match tag {
|
||||||
Some(tag) => format!(
|
Some(tag) => format!(
|
||||||
"https://api.github.com/repos/{}/{}/releases/tags/v{}",
|
"https://api.github.com/repos/{TYPST_GITHUB_ORG}/{TYPST_REPO}/releases/tags/v{tag}"
|
||||||
TYPST_GITHUB_ORG, TYPST_REPO, tag
|
|
||||||
),
|
),
|
||||||
None => format!(
|
None => format!(
|
||||||
"https://api.github.com/repos/{}/{}/releases/latest",
|
"https://api.github.com/repos/{TYPST_GITHUB_ORG}/{TYPST_REPO}/releases/latest",
|
||||||
TYPST_GITHUB_ORG, TYPST_REPO
|
|
||||||
),
|
),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -25,3 +25,6 @@ typed-arena = { workspace = true }
|
|||||||
unicode_names2 = { workspace = true }
|
unicode_names2 = { workspace = true }
|
||||||
unscanny = { workspace = true }
|
unscanny = { workspace = true }
|
||||||
yaml-front-matter = { workspace = true }
|
yaml-front-matter = { workspace = true }
|
||||||
|
|
||||||
|
[lints]
|
||||||
|
workspace = true
|
||||||
|
@ -24,3 +24,6 @@ if_chain = { workspace = true }
|
|||||||
log = { workspace = true }
|
log = { workspace = true }
|
||||||
serde = { workspace = true }
|
serde = { workspace = true }
|
||||||
unscanny = { workspace = true }
|
unscanny = { workspace = true }
|
||||||
|
|
||||||
|
[lints]
|
||||||
|
workspace = true
|
||||||
|
@ -22,3 +22,6 @@ heck = { workspace = true }
|
|||||||
proc-macro2 = { workspace = true }
|
proc-macro2 = { workspace = true }
|
||||||
quote = { workspace = true }
|
quote = { workspace = true }
|
||||||
syn = { workspace = true }
|
syn = { workspace = true }
|
||||||
|
|
||||||
|
[lints]
|
||||||
|
workspace = true
|
||||||
|
@ -248,10 +248,10 @@ fn parse_field(field: &syn::Field) -> Result<Field> {
|
|||||||
default: parse_attr::<syn::Expr>(&mut attrs, "default")?.flatten(),
|
default: parse_attr::<syn::Expr>(&mut attrs, "default")?.flatten(),
|
||||||
vis: field.vis.clone(),
|
vis: field.vis.clone(),
|
||||||
ident: ident.clone(),
|
ident: ident.clone(),
|
||||||
ident_in: Ident::new(&format!("{}_in", ident), ident.span()),
|
ident_in: Ident::new(&format!("{ident}_in"), ident.span()),
|
||||||
with_ident: Ident::new(&format!("with_{}", ident), ident.span()),
|
with_ident: Ident::new(&format!("with_{ident}"), ident.span()),
|
||||||
push_ident: Ident::new(&format!("push_{}", ident), ident.span()),
|
push_ident: Ident::new(&format!("push_{ident}"), ident.span()),
|
||||||
set_ident: Ident::new(&format!("set_{}", ident), ident.span()),
|
set_ident: Ident::new(&format!("set_{ident}"), ident.span()),
|
||||||
enum_ident: Ident::new(&ident.to_string().to_upper_camel_case(), ident.span()),
|
enum_ident: Ident::new(&ident.to_string().to_upper_camel_case(), ident.span()),
|
||||||
const_ident: Ident::new(&ident.to_string().to_shouty_snake_case(), ident.span()),
|
const_ident: Ident::new(&ident.to_string().to_shouty_snake_case(), ident.span()),
|
||||||
ty: field.ty.clone(),
|
ty: field.ty.clone(),
|
||||||
@ -530,7 +530,7 @@ fn create_with_field_method(field: &Field) -> TokenStream {
|
|||||||
default,
|
default,
|
||||||
..
|
..
|
||||||
} = field;
|
} = field;
|
||||||
let doc = format!("Set the [`{}`](Self::{}) field.", name, ident);
|
let doc = format!("Set the [`{name}`](Self::{ident}) field.");
|
||||||
|
|
||||||
let set = if field.inherent() || (*synthesized && default.is_some()) {
|
let set = if field.inherent() || (*synthesized && default.is_some()) {
|
||||||
quote! { self.#ident = #ident; }
|
quote! { self.#ident = #ident; }
|
||||||
@ -558,7 +558,7 @@ fn create_push_field_method(field: &Field) -> TokenStream {
|
|||||||
default,
|
default,
|
||||||
..
|
..
|
||||||
} = field;
|
} = field;
|
||||||
let doc = format!("Push the [`{}`](Self::{}) field.", name, ident);
|
let doc = format!("Push the [`{name}`](Self::{ident}) field.");
|
||||||
let set = if (field.inherent() && !synthesized) || (*synthesized && default.is_some())
|
let set = if (field.inherent() && !synthesized) || (*synthesized && default.is_some())
|
||||||
{
|
{
|
||||||
quote! { self.#ident = #ident; }
|
quote! { self.#ident = #ident; }
|
||||||
@ -577,7 +577,7 @@ fn create_push_field_method(field: &Field) -> TokenStream {
|
|||||||
fn create_set_field_method(element: &Elem, field: &Field) -> TokenStream {
|
fn create_set_field_method(element: &Elem, field: &Field) -> TokenStream {
|
||||||
let elem = &element.ident;
|
let elem = &element.ident;
|
||||||
let Field { vis, ident, set_ident, enum_ident, ty, name, .. } = field;
|
let Field { vis, ident, set_ident, enum_ident, ty, name, .. } = field;
|
||||||
let doc = format!("Create a style property for the `{}` field.", name);
|
let doc = format!("Create a style property for the `{name}` field.");
|
||||||
quote! {
|
quote! {
|
||||||
#[doc = #doc]
|
#[doc = #doc]
|
||||||
#vis fn #set_ident(#ident: #ty) -> #foundations::Style {
|
#vis fn #set_ident(#ident: #ty) -> #foundations::Style {
|
||||||
@ -593,7 +593,7 @@ fn create_set_field_method(element: &Elem, field: &Field) -> TokenStream {
|
|||||||
/// Create a style chain access method for a field.
|
/// Create a style chain access method for a field.
|
||||||
fn create_field_in_method(element: &Elem, field: &Field) -> TokenStream {
|
fn create_field_in_method(element: &Elem, field: &Field) -> TokenStream {
|
||||||
let Field { vis, ident_in, name, output, .. } = field;
|
let Field { vis, ident_in, name, output, .. } = field;
|
||||||
let doc = format!("Access the `{}` field in the given style chain.", name);
|
let doc = format!("Access the `{name}` field in the given style chain.");
|
||||||
let access = create_style_chain_access(element, field, quote! { None });
|
let access = create_style_chain_access(element, field, quote! { None });
|
||||||
|
|
||||||
let output = if field.borrowed {
|
let output = if field.borrowed {
|
||||||
@ -903,8 +903,8 @@ fn create_native_elem_impl(element: &Elem) -> TokenStream {
|
|||||||
)
|
)
|
||||||
.unwrap_or_else(|| quote! { None });
|
.unwrap_or_else(|| quote! { None });
|
||||||
|
|
||||||
let unknown_field = format!("unknown field {{}} on {}", name);
|
let unknown_field = format!("unknown field {{}} on {name}");
|
||||||
let label_error = format!("cannot set label on {}", name);
|
let label_error = format!("cannot set label on {name}");
|
||||||
let data = quote! {
|
let data = quote! {
|
||||||
#foundations::NativeElementData {
|
#foundations::NativeElementData {
|
||||||
name: #name,
|
name: #name,
|
||||||
|
@ -32,3 +32,6 @@ ttf-parser = { workspace = true }
|
|||||||
unicode-properties = { workspace = true }
|
unicode-properties = { workspace = true }
|
||||||
unscanny = { workspace = true }
|
unscanny = { workspace = true }
|
||||||
xmp-writer = { workspace = true }
|
xmp-writer = { workspace = true }
|
||||||
|
|
||||||
|
[lints]
|
||||||
|
workspace = true
|
||||||
|
@ -27,3 +27,6 @@ roxmltree = { workspace = true }
|
|||||||
tiny-skia = { workspace = true }
|
tiny-skia = { workspace = true }
|
||||||
ttf-parser = { workspace = true }
|
ttf-parser = { workspace = true }
|
||||||
usvg = { workspace = true }
|
usvg = { workspace = true }
|
||||||
|
|
||||||
|
[lints]
|
||||||
|
workspace = true
|
||||||
|
@ -25,3 +25,6 @@ tracing = { workspace = true }
|
|||||||
ttf-parser = { workspace = true }
|
ttf-parser = { workspace = true }
|
||||||
xmlparser = { workspace = true }
|
xmlparser = { workspace = true }
|
||||||
xmlwriter = { workspace = true }
|
xmlwriter = { workspace = true }
|
||||||
|
|
||||||
|
[lints]
|
||||||
|
workspace = true
|
||||||
|
@ -446,7 +446,7 @@ impl SVGRenderer {
|
|||||||
|
|
||||||
self.xml.start_element("use");
|
self.xml.start_element("use");
|
||||||
self.xml.write_attribute_fmt("xlink:href", format_args!("#{id}"));
|
self.xml.write_attribute_fmt("xlink:href", format_args!("#{id}"));
|
||||||
self.xml.write_attribute_fmt("x", format_args!("{}", x_offset));
|
self.xml.write_attribute_fmt("x", format_args!("{x_offset}"));
|
||||||
self.write_fill(
|
self.write_fill(
|
||||||
&text.fill,
|
&text.fill,
|
||||||
Size::new(Abs::pt(width), Abs::pt(height)),
|
Size::new(Abs::pt(width), Abs::pt(height)),
|
||||||
|
@ -26,3 +26,6 @@ unicode-math-class = { workspace = true }
|
|||||||
unicode-script = { workspace = true }
|
unicode-script = { workspace = true }
|
||||||
unicode-segmentation = { workspace = true }
|
unicode-segmentation = { workspace = true }
|
||||||
unscanny = { workspace = true }
|
unscanny = { workspace = true }
|
||||||
|
|
||||||
|
[lints]
|
||||||
|
workspace = true
|
||||||
|
@ -65,3 +65,6 @@ wasmi = { workspace = true }
|
|||||||
|
|
||||||
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
|
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
|
||||||
stacker = { workspace = true }
|
stacker = { workspace = true }
|
||||||
|
|
||||||
|
[lints]
|
||||||
|
workspace = true
|
||||||
|
@ -216,7 +216,7 @@ impl Display for Tracepoint {
|
|||||||
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
|
||||||
match self {
|
match self {
|
||||||
Tracepoint::Call(Some(name)) => {
|
Tracepoint::Call(Some(name)) => {
|
||||||
write!(f, "error occurred in this call of function `{}`", name)
|
write!(f, "error occurred in this call of function `{name}`")
|
||||||
}
|
}
|
||||||
Tracepoint::Call(None) => {
|
Tracepoint::Call(None) => {
|
||||||
write!(f, "error occurred in this function call")
|
write!(f, "error occurred in this function call")
|
||||||
|
@ -139,7 +139,7 @@ impl Array {
|
|||||||
let count = self
|
let count = self
|
||||||
.len()
|
.len()
|
||||||
.checked_mul(n)
|
.checked_mul(n)
|
||||||
.ok_or_else(|| format!("cannot repeat this array {} times", n))?;
|
.ok_or_else(|| format!("cannot repeat this array {n} times"))?;
|
||||||
|
|
||||||
Ok(self.iter().cloned().cycle().take(count).collect())
|
Ok(self.iter().cloned().cycle().take(count).collect())
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user