Fix basic lints (cargo clippy) (#383)
This commit is contained in:
parent
dfbd3503d9
commit
213f31c5d7
@ -138,7 +138,7 @@ fn prepare(stream: TokenStream, body: &syn::ItemStruct) -> Result<Elem> {
|
||||
.collect();
|
||||
|
||||
let docs = documentation(&body.attrs);
|
||||
let mut lines = docs.split("\n").collect();
|
||||
let mut lines = docs.split('\n').collect();
|
||||
let category = meta_line(&mut lines, "Category")?.into();
|
||||
let display = meta_line(&mut lines, "Display")?.into();
|
||||
let docs = lines.join("\n").trim().into();
|
||||
|
@ -73,7 +73,7 @@ fn prepare(item: &syn::ItemFn) -> Result<Func> {
|
||||
}
|
||||
|
||||
let docs = documentation(&item.attrs);
|
||||
let mut lines = docs.split("\n").collect();
|
||||
let mut lines = docs.split('\n').collect();
|
||||
let returns = meta_line(&mut lines, "Returns")?
|
||||
.split(" or ")
|
||||
.map(Into::into)
|
||||
|
@ -115,7 +115,7 @@ impl Func {
|
||||
}
|
||||
Repr::With(arc) => {
|
||||
args.items = arc.1.items.iter().cloned().chain(args.items).collect();
|
||||
return arc.0.call_vm(vm, args);
|
||||
arc.0.call_vm(vm, args)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ pub fn call(
|
||||
},
|
||||
|
||||
Value::Str(string) => match method {
|
||||
"len" => Value::Int(string.len() as i64),
|
||||
"len" => Value::Int(string.len()),
|
||||
"first" => Value::Str(string.first().at(span)?),
|
||||
"last" => Value::Str(string.last().at(span)?),
|
||||
"at" => Value::Str(string.at(args.expect("index")?).at(span)?),
|
||||
@ -73,7 +73,7 @@ pub fn call(
|
||||
Value::Content(content) => match method {
|
||||
"func" => content.func().into(),
|
||||
"has" => Value::Bool(content.has(&args.expect::<EcoString>("field")?)),
|
||||
"at" => content.at(&args.expect::<EcoString>("field")?).at(span)?.clone(),
|
||||
"at" => content.at(&args.expect::<EcoString>("field")?).at(span)?,
|
||||
"location" => content
|
||||
.location()
|
||||
.ok_or("this method can only be called on content returned by query(..)")
|
||||
|
@ -652,7 +652,7 @@ impl Eval for ast::MathIdent {
|
||||
type Output = Value;
|
||||
|
||||
fn eval(&self, vm: &mut Vm) -> SourceResult<Self::Output> {
|
||||
Ok(vm.scopes.get_in_math(self).cloned().at(self.span())?)
|
||||
vm.scopes.get_in_math(self).cloned().at(self.span())
|
||||
}
|
||||
}
|
||||
|
||||
@ -700,7 +700,7 @@ impl Eval for ast::Ident {
|
||||
type Output = Value;
|
||||
|
||||
fn eval(&self, vm: &mut Vm) -> SourceResult<Self::Output> {
|
||||
Ok(vm.scopes.get(self).cloned().at(self.span())?)
|
||||
vm.scopes.get(self).cloned().at(self.span())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -60,7 +60,7 @@ impl Module {
|
||||
|
||||
/// Try to access a definition in the module.
|
||||
pub fn get(&self, name: &str) -> StrResult<&Value> {
|
||||
self.scope().get(&name).ok_or_else(|| {
|
||||
self.scope().get(name).ok_or_else(|| {
|
||||
eco_format!("module `{}` does not contain `{name}`", self.name())
|
||||
})
|
||||
}
|
||||
|
@ -118,7 +118,7 @@ impl Str {
|
||||
/// The text of the pattern's first match in this string.
|
||||
pub fn find(&self, pattern: StrPattern) -> Option<Self> {
|
||||
match pattern {
|
||||
StrPattern::Str(pat) => self.0.contains(pat.as_str()).then(|| pat),
|
||||
StrPattern::Str(pat) => self.0.contains(pat.as_str()).then_some(pat),
|
||||
StrPattern::Regex(re) => re.find(self).map(|m| m.as_str().into()),
|
||||
}
|
||||
}
|
||||
|
@ -70,7 +70,7 @@ impl Symbol {
|
||||
modifiers.push('.');
|
||||
}
|
||||
modifiers.push_str(modifier);
|
||||
if find(list.variants(), &modifiers).is_some() {
|
||||
if find(list.variants(), modifiers).is_some() {
|
||||
return Ok(self);
|
||||
}
|
||||
}
|
||||
|
@ -17,9 +17,10 @@ use crate::model::Styles;
|
||||
use crate::syntax::{ast, Span};
|
||||
|
||||
/// A computational value.
|
||||
#[derive(Clone)]
|
||||
#[derive(Clone, Default)]
|
||||
pub enum Value {
|
||||
/// The value that indicates the absence of a meaningful value.
|
||||
#[default]
|
||||
None,
|
||||
/// A value that indicates some smart default behaviour.
|
||||
Auto,
|
||||
@ -122,10 +123,10 @@ impl Value {
|
||||
/// Try to access a field on the value.
|
||||
pub fn field(&self, field: &str) -> StrResult<Value> {
|
||||
match self {
|
||||
Self::Symbol(symbol) => symbol.clone().modified(&field).map(Self::Symbol),
|
||||
Self::Dict(dict) => dict.at(&field).cloned(),
|
||||
Self::Content(content) => content.at(&field),
|
||||
Self::Module(module) => module.get(&field).cloned(),
|
||||
Self::Symbol(symbol) => symbol.clone().modified(field).map(Self::Symbol),
|
||||
Self::Dict(dict) => dict.at(field).cloned(),
|
||||
Self::Content(content) => content.at(field),
|
||||
Self::Module(module) => module.get(field).cloned(),
|
||||
v => Err(eco_format!("cannot access fields on type {}", v.type_name())),
|
||||
}
|
||||
}
|
||||
@ -168,12 +169,6 @@ impl Value {
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Value {
|
||||
fn default() -> Self {
|
||||
Value::None
|
||||
}
|
||||
}
|
||||
|
||||
impl Debug for Value {
|
||||
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
|
||||
match self {
|
||||
|
@ -122,7 +122,7 @@ fn complete_markup(ctx: &mut CompletionContext) -> bool {
|
||||
}
|
||||
|
||||
// Directly after a raw block.
|
||||
let mut s = Scanner::new(&ctx.text);
|
||||
let mut s = Scanner::new(ctx.text);
|
||||
s.jump(ctx.leaf.offset());
|
||||
if s.eat_if("```") {
|
||||
s.eat_while('`');
|
||||
@ -651,7 +651,7 @@ fn param_completions(
|
||||
kind: CompletionKind::Param,
|
||||
label: param.name.into(),
|
||||
apply: Some(eco_format!("{}: ${{}}", param.name)),
|
||||
detail: Some(plain_docs_sentence(param.docs).into()),
|
||||
detail: Some(plain_docs_sentence(param.docs)),
|
||||
});
|
||||
}
|
||||
|
||||
@ -896,8 +896,8 @@ impl<'a> CompletionContext<'a> {
|
||||
frames,
|
||||
library,
|
||||
source,
|
||||
global: &library.global.scope(),
|
||||
math: &library.math.scope(),
|
||||
global: library.global.scope(),
|
||||
math: library.math.scope(),
|
||||
text,
|
||||
before: &text[..cursor],
|
||||
after: &text[cursor..],
|
||||
@ -1002,9 +1002,7 @@ impl<'a> CompletionContext<'a> {
|
||||
|
||||
let detail = docs.map(Into::into).or_else(|| match value {
|
||||
Value::Symbol(_) => None,
|
||||
Value::Func(func) => {
|
||||
func.info().map(|info| plain_docs_sentence(info.docs).into())
|
||||
}
|
||||
Value::Func(func) => func.info().map(|info| plain_docs_sentence(info.docs)),
|
||||
v => Some(v.repr().into()),
|
||||
});
|
||||
|
||||
|
@ -126,7 +126,7 @@ fn ref_tooltip(
|
||||
let target = leaf.text().trim_start_matches('@');
|
||||
for (label, detail) in analyze_labels(world, frames).0 {
|
||||
if label.0 == target {
|
||||
return Some(Tooltip::Text(detail?.into()));
|
||||
return Some(Tooltip::Text(detail?));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -43,7 +43,7 @@ cast_from_value! {
|
||||
}
|
||||
|
||||
/// Provides stable identities to elements.
|
||||
#[derive(Clone)]
|
||||
#[derive(Clone, Default)]
|
||||
pub struct StabilityProvider {
|
||||
hashes: Vec<u128>,
|
||||
checkpoints: Vec<usize>,
|
||||
@ -52,7 +52,7 @@ pub struct StabilityProvider {
|
||||
impl StabilityProvider {
|
||||
/// Create a new stability provider.
|
||||
pub fn new() -> Self {
|
||||
Self { hashes: vec![], checkpoints: vec![] }
|
||||
Self::default()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -71,8 +71,8 @@ impl Styles {
|
||||
pub fn interruption<T: Element>(&self) -> Option<Option<Span>> {
|
||||
let func = T::func();
|
||||
self.0.iter().find_map(|entry| match entry {
|
||||
Style::Property(property) => property.is_of(func).then(|| property.span),
|
||||
Style::Recipe(recipe) => recipe.is_of(func).then(|| Some(recipe.span)),
|
||||
Style::Property(property) => property.is_of(func).then_some(property.span),
|
||||
Style::Recipe(recipe) => recipe.is_of(func).then_some(Some(recipe.span)),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -284,10 +284,8 @@ impl Lexer<'_> {
|
||||
self.s.eat_while(char::is_ascii_digit);
|
||||
|
||||
let read = self.s.from(start);
|
||||
if self.s.eat_if('.') && self.space_or_end() {
|
||||
if read.parse::<usize>().is_ok() {
|
||||
return SyntaxKind::EnumMarker;
|
||||
}
|
||||
if self.s.eat_if('.') && self.space_or_end() && read.parse::<usize>().is_ok() {
|
||||
return SyntaxKind::EnumMarker;
|
||||
}
|
||||
|
||||
self.text()
|
||||
|
@ -72,7 +72,7 @@ fn try_reparse(
|
||||
return node
|
||||
.replace_children(i..i + 1, vec![newborn])
|
||||
.is_ok()
|
||||
.then(|| new_range);
|
||||
.then_some(new_range);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -157,7 +157,7 @@ fn try_reparse(
|
||||
return node
|
||||
.replace_children(start..end, newborns)
|
||||
.is_ok()
|
||||
.then(|| new_range);
|
||||
.then_some(new_range);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -212,7 +212,7 @@ impl Source {
|
||||
k += c.len_utf16();
|
||||
}
|
||||
|
||||
(k == utf16_idx).then(|| self.text.len())
|
||||
(k == utf16_idx).then_some(self.text.len())
|
||||
}
|
||||
|
||||
/// Return the byte position at which the given line starts.
|
||||
|
@ -205,7 +205,7 @@ pub fn pretty_comma_list(pieces: &[impl AsRef<str>], trailing_comma: bool) -> St
|
||||
/// Tries to format horizontally, but falls back to vertical formatting if the
|
||||
/// pieces are too long.
|
||||
pub fn pretty_array_like(parts: &[impl AsRef<str>], trailing_comma: bool) -> String {
|
||||
let list = pretty_comma_list(&parts, trailing_comma);
|
||||
let list = pretty_comma_list(parts, trailing_comma);
|
||||
let mut buf = String::new();
|
||||
buf.push('(');
|
||||
if list.contains('\n') {
|
||||
|
Loading…
x
Reference in New Issue
Block a user