Skip to content

Commit

Permalink
Cargo clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
WGUNDERWOOD committed May 3, 2024
1 parent 6abe09c commit d75dd02
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 17 deletions.
4 changes: 1 addition & 3 deletions notes.org
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@
** Find todos
** Clippy
** New source files: write.rs, parse.rs, print.rs
** Check unused regexes
** Check for collect() not needed
** Tests output better
** Tests better output
* Bugs
** Better errors including line numbers in source file
** Handle list items properly
Expand Down
12 changes: 4 additions & 8 deletions src/comments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,22 @@ pub fn find_comment_index(line: &str) -> Option<usize> {
// multi-character line
for i in 1..n {
let c = line.chars().nth(i).unwrap();
if c == '%' {
if prev_c == ' ' {
return Some(i);
} else if prev_c != '\\' {
return Some(i);
}
if c == '%' && (prev_c == ' ' || prev_c != '\\') {
return Some(i);
}
prev_c = c;
}
None
}

pub fn remove_comment<'a>(line: &'a str, comment: Option<usize>) -> &'a str {
pub fn remove_comment(line: &str, comment: Option<usize>) -> &str {
match comment {
Some(c) => &line[0..c],
None => line,
}
}

pub fn get_comment<'a>(line: &'a str, comment: Option<usize>) -> &'a str {
pub fn get_comment(line: &str, comment: Option<usize>) -> &str {
match comment {
Some(c) => &line[c..line.len()],
None => "",
Expand Down
3 changes: 1 addition & 2 deletions src/indent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,10 @@ pub fn get_indent(line: &str, prev_indent: Indent) -> Indent {
}

pub fn apply_indent(file: &str, debug: bool) -> String {
let lines: Vec<&str> = file.lines().collect();
let mut indent = Indent::new();
let mut new_file = "".to_owned();

for (i, line) in lines.iter().enumerate() {
for (i, line) in file.lines().enumerate() {
// calculate indent
let comment_index = find_comment_index(line);
let line_strip = remove_comment(line, comment_index);
Expand Down
3 changes: 1 addition & 2 deletions src/subs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ pub fn remove_trailing_spaces(file: &str) -> String {

pub fn begin_end_environments_new_line(file: &str) -> String {
let mut new_file = "".to_string();
let lines = file.lines();
for line in lines {
for line in file.lines() {
if RE_ENV_BEGIN.is_match(line) || RE_ENV_END.is_match(line) {
let comment_index = find_comment_index(line);
let comment = get_comment(line, comment_index);
Expand Down
3 changes: 1 addition & 2 deletions src/wrap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@ pub fn wrap_line(line: &str) -> String {

pub fn wrap(file: &str) -> String {
let mut new_file = "".to_string();
let lines = file.lines();
for line in lines {
for line in file.lines() {
if line_needs_wrap(line) {
let new_line = wrap_line(line);
new_file.push_str(&new_line);
Expand Down

0 comments on commit d75dd02

Please sign in to comment.