Skip to content

Commit

Permalink
fix clippy comments (#500)
Browse files Browse the repository at this point in the history
* `cargo clippy`

* run ci again

* Removed unused `syntax` from
`recursively_mark_no_prototype`
  • Loading branch information
CGMossa authored Nov 29, 2023
1 parent e1cc6b2 commit 100b8b2
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 43 deletions.
6 changes: 3 additions & 3 deletions examples/syntest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ fn test_file(
return Err(SyntaxTestHeaderError::MalformedHeader);
}

line = line.replace("\r", "");
line = line.replace('\r', "");

// parse the syntax test header in the first line of the file
let header_line = line.clone();
Expand Down Expand Up @@ -308,7 +308,7 @@ fn test_file(
if reader.read_line(&mut line).unwrap() == 0 {
break;
}
line = line.replace("\r", "");
line = line.replace('\r', "");
}
let res = if assertion_failures > 0 {
Ok(SyntaxTestFileResult::FailedAssertions(
Expand Down Expand Up @@ -369,7 +369,7 @@ fn main() {
if !syntaxes_path.is_empty() {
println!("loading syntax definitions from {}", syntaxes_path);
let mut builder = SyntaxSetBuilder::new();
builder.add_from_folder(&syntaxes_path, true).unwrap(); // note that we load the version with newlines
builder.add_from_folder(syntaxes_path, true).unwrap(); // note that we load the version with newlines
ss = builder.build();
}

Expand Down
8 changes: 4 additions & 4 deletions src/dumps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ use bincode::deserialize_from;
use bincode::serialize_into;
use std::fs::File;
#[cfg(feature = "dump-load")]
use std::io::{BufRead};
use std::io::BufRead;
#[cfg(feature = "dump-create")]
use std::io::{BufWriter, Write};
#[cfg(all(feature = "default-syntaxes"))]
#[cfg(feature = "default-syntaxes")]
use crate::parsing::SyntaxSet;
#[cfg(all(feature = "default-themes"))]
#[cfg(feature = "default-themes")]
use crate::highlighting::ThemeSet;
use std::path::Path;
#[cfg(feature = "dump-create")]
Expand Down Expand Up @@ -195,7 +195,7 @@ impl SyntaxSet {
}
}

#[cfg(all(feature = "default-themes"))]
#[cfg(feature = "default-themes")]
impl ThemeSet {
/// Loads the set of default themes
/// Currently includes (these are the keys for the map):
Expand Down
2 changes: 1 addition & 1 deletion src/highlighting/highlighter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ impl<'a> Highlighter<'a> {

let mult_iter = self.multi_selectors
.iter()
.filter_map(|&(ref sel, ref style)| sel.does_match(path).map(|score| (score, style)));
.filter_map(|(sel, style)| sel.does_match(path).map(|score| (score, style)));
for (score, modif) in mult_iter {
new_style.apply(modif, score);
}
Expand Down
2 changes: 0 additions & 2 deletions src/highlighting/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ use plist::Error as PlistError;
use std::io::{Read, Seek};

pub use serde_json::Value as Settings;
pub use serde_json::Value::Array as SettingsArray;
pub use serde_json::Value::Object as SettingsObject;

pub trait ParseSettings: Sized {
type Error;
Expand Down
10 changes: 2 additions & 8 deletions src/highlighting/theme.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// Code based on https://github.com/defuz/sublimate/blob/master/src/core/syntax/theme.rs
// released under the MIT license by @defuz

use super::style::*;
use super::selector::*;
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -118,16 +117,11 @@ pub struct ThemeItem {
pub style: StyleModifier,
}

#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)]
pub enum UnderlineOption {
#[default]
None,
Underline,
StippledUnderline,
SquigglyUnderline,
}

impl Default for UnderlineOption {
fn default() -> UnderlineOption {
UnderlineOption::None
}
}
9 changes: 3 additions & 6 deletions src/parsing/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,9 @@ impl From<LoadMetadata> for Metadata {
}

let scoped_metadata = scoped_metadata.into_iter()
.map(|r|
.flat_map(|r|
MetadataSet::from_raw(r)
.map_err(|e| eprintln!("{}", e))
)
.flatten()
.map_err(|e| eprintln!("{}", e)))
.collect();
Metadata { scoped_metadata }
}
Expand Down Expand Up @@ -205,8 +203,7 @@ impl Metadata {
final_items.insert(item.selector_string.clone(), item);
}

let scoped_metadata: Vec<MetadataSet> = final_items.into_iter()
.map(|(_k, v)| v)
let scoped_metadata: Vec<MetadataSet> = final_items.into_values()
.collect();

Metadata { scoped_metadata }
Expand Down
16 changes: 8 additions & 8 deletions src/parsing/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ impl ParseState {

let (matched, can_cache) = match (match_pat.has_captures, captures) {
(true, Some(captures)) => {
let &(ref region, ref s) = captures;
let (region, s) = captures;
let regex = match_pat.regex_with_refs(region, s);
let matched = regex.search(line, start, line.len(), Some(regions));
(matched, false)
Expand Down Expand Up @@ -518,18 +518,18 @@ impl ParseState {
// println!("popping at {}", match_end);
ops.push((match_end, ScopeStackOp::Pop(pat.scope.len())));
}
self.push_meta_ops(false, match_end, &*level_context, &pat.operation, syntax_set, ops)?;
self.push_meta_ops(false, match_end, level_context, &pat.operation, syntax_set, ops)?;

self.perform_op(line, &reg_match.regions, pat, syntax_set)
}

fn push_meta_ops<'a>(
fn push_meta_ops(
&self,
initial: bool,
index: usize,
cur_context: &Context,
match_op: &MatchOperation,
syntax_set: &'a SyntaxSet,
syntax_set: &SyntaxSet,
ops: &mut Vec<(usize, ScopeStackOp)>,
) -> Result<(), ParsingError>{
// println!("metas ops for {:?}, initial: {}",
Expand All @@ -548,7 +548,7 @@ impl ParseState {
}

// cleared scopes are restored after the scopes from match pattern that invoked the pop are applied
if !initial && cur_context.clear_scopes != None {
if !initial && cur_context.clear_scopes.is_some() {
ops.push((index, ScopeStackOp::Restore))
}
},
Expand All @@ -561,7 +561,7 @@ impl ParseState {
let is_set = matches!(*match_op, MatchOperation::Set(_));
// a match pattern that "set"s keeps the meta_content_scope and meta_scope from the previous context
if initial {
if is_set && cur_context.clear_scopes != None {
if is_set && cur_context.clear_scopes.is_some() {
// cleared scopes from the old context are restored immediately
ops.push((index, ScopeStackOp::Restore));
}
Expand Down Expand Up @@ -778,7 +778,7 @@ mod tests {
test_stack.push(Scope::new("meta.function.parameters.ruby").unwrap());

let mut stack = ScopeStack::new();
for &(_, ref op) in ops.iter() {
for (_, op) in ops.iter() {
stack.apply(op).expect("#[cfg(test)]");
}
assert_eq!(stack, test_stack);
Expand Down Expand Up @@ -1835,7 +1835,7 @@ contexts:
fn stack_states(ops: Vec<(usize, ScopeStackOp)>) -> Vec<String> {
let mut states = Vec::new();
let mut stack = ScopeStack::new();
for &(_, ref op) in ops.iter() {
for (_, op) in ops.iter() {
stack.apply(op).expect("#[cfg(test)]");
let scopes: Vec<String> = stack.as_slice().iter().map(|s| format!("{:?}", s)).collect();
let stack_str = scopes.join(", ");
Expand Down
2 changes: 1 addition & 1 deletion src/parsing/syntax_definition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ pub(crate) fn substitute_backrefs_in_regex<F>(regex_str: &str, substituter: F) -

let mut last_was_escape = false;
for c in regex_str.chars() {
if last_was_escape && c.is_digit(10) {
if last_was_escape && c.is_ascii_digit() {
let val = c.to_digit(10).unwrap() as usize;
if let Some(sub) = substituter(val) {
reg_str.push_str(&sub);
Expand Down
17 changes: 8 additions & 9 deletions src/parsing/syntax_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,11 +357,11 @@ impl SyntaxSet {
let syntax = &self
.syntaxes
.get(context_id.syntax_index)
.ok_or_else(|| ParsingError::MissingContext(*context_id))?;
.ok_or(ParsingError::MissingContext(*context_id))?;
syntax
.contexts()
.get(context_id.context_index)
.ok_or_else(|| ParsingError::MissingContext(*context_id))
.ok_or(ParsingError::MissingContext(*context_id))
}

fn first_line_cache(&self) -> &FirstLineCache {
Expand Down Expand Up @@ -590,12 +590,12 @@ impl SyntaxSetBuilder {
}

let mut found_more_backref_includes = true;
for (syntax_index, syntax) in syntaxes.iter().enumerate() {
for (syntax_index, _syntax) in syntaxes.iter().enumerate() {
let mut no_prototype = HashSet::new();
let prototype = all_context_ids[syntax_index].get("prototype");
if let Some(prototype_id) = prototype {
// TODO: We could do this after parsing YAML, instead of here?
Self::recursively_mark_no_prototype(syntax, prototype_id, &all_context_ids[syntax_index], &all_contexts, &mut no_prototype);
Self::recursively_mark_no_prototype(prototype_id, &all_context_ids[syntax_index], &all_contexts, &mut no_prototype);
}

for context_id in all_context_ids[syntax_index].values() {
Expand Down Expand Up @@ -670,7 +670,6 @@ impl SyntaxSetBuilder {
/// Anything recursively included by the prototype shouldn't include the prototype.
/// This marks them as such.
fn recursively_mark_no_prototype(
syntax: &SyntaxReference,
context_id: &ContextId,
syntax_context_ids: &HashMap<String, ContextId>,
all_contexts: &[Vec<Context>],
Expand All @@ -696,11 +695,11 @@ impl SyntaxSetBuilder {
match context_ref {
ContextReference::Inline(ref s) | ContextReference::Named(ref s) => {
if let Some(i) = syntax_context_ids.get(s) {
Self::recursively_mark_no_prototype(syntax, i, syntax_context_ids, all_contexts, no_prototype);
Self::recursively_mark_no_prototype(i, syntax_context_ids, all_contexts, no_prototype);
}
},
ContextReference::Direct(ref id) => {
Self::recursively_mark_no_prototype(syntax, id, syntax_context_ids, all_contexts, no_prototype);
Self::recursively_mark_no_prototype(id, syntax_context_ids, all_contexts, no_prototype);
},
_ => (),
}
Expand All @@ -711,11 +710,11 @@ impl SyntaxSetBuilder {
match reference {
ContextReference::Named(ref s) => {
if let Some(id) = syntax_context_ids.get(s) {
Self::recursively_mark_no_prototype(syntax, id, syntax_context_ids, all_contexts, no_prototype);
Self::recursively_mark_no_prototype(id, syntax_context_ids, all_contexts, no_prototype);
}
},
ContextReference::Direct(ref id) => {
Self::recursively_mark_no_prototype(syntax, id, syntax_context_ids, all_contexts, no_prototype);
Self::recursively_mark_no_prototype(id, syntax_context_ids, all_contexts, no_prototype);
},
_ => (),
}
Expand Down
2 changes: 1 addition & 1 deletion src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ pub fn as_latex_escaped(v: &[(Style, &str)]) -> String {
}
content = text.to_string();
for &(old, new) in LATEX_REPLACE.iter() {
content = content.replace(&old, new);
content = content.replace(old, new);
}
write!(s, "{}", &content).unwrap();
prev_style = Some(style);
Expand Down

0 comments on commit 100b8b2

Please sign in to comment.