-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3b018cf
commit e105c8f
Showing
9 changed files
with
186 additions
and
144 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
pub const CYAN: &str = "\x1b[36m\x1b[1m"; | ||
pub const PINK: &str = "\x1b[35m\x1b[1m"; | ||
pub const PURPLE: &str = "\x1b[34m\x1b[1m"; | ||
pub const RED: &str = "\x1b[31m\x1b[1m"; | ||
pub const RESET: &str = "\x1b[00m\x1b[0m"; | ||
pub const WHITE: &str = "\x1b[37m\x1b[1m"; | ||
pub const YELLOW: &str = "\x1b[33m\x1b[1m"; | ||
pub const PURPLE: &str = "\x1b[34m\x1b[1m"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
enum Error { | ||
kind: ErrorKind, | ||
message: String, | ||
linum: Option<usize>, | ||
filename: String, | ||
} | ||
|
||
enum ErrorKind { | ||
FileExtensionError, | ||
FormatFileInfo, | ||
IndentFileInfo, | ||
IndentLineInfo, | ||
IndentNegativeError, | ||
IndentZeroError, | ||
IgnoreEndError, | ||
IgnoreStartError, | ||
WrapFileInfo, | ||
WrapLineInfo, | ||
WrapLineError, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,71 @@ | ||
use crate::colors::*; | ||
//use crate::colors::*; | ||
use crate::indent::*; | ||
use crate::logging::*; | ||
use crate::subs::*; | ||
use crate::wrap::*; | ||
use crate::Cli; | ||
use log::Level::Warn; | ||
//use log::Level::Warn; | ||
|
||
const MAX_TRIES: u8 = 10; | ||
|
||
fn apply_passes(file: &str, args: &Cli) -> String { | ||
let mut new_file = apply_indent(file, args); | ||
fn apply_passes( | ||
file: &str, | ||
args: &Cli, | ||
filename: &str, | ||
logs: &mut Vec<Log>, | ||
) -> String { | ||
let mut new_logs: Vec<Log> = vec![]; | ||
let mut new_file = apply_indent(file, args, filename, &mut new_logs); | ||
let mut finished = false; | ||
let mut tries = 0; | ||
|
||
while needs_wrap(&new_file) && !finished && tries < MAX_TRIES { | ||
new_logs.clear(); | ||
let old_file = new_file.clone(); | ||
new_file = wrap(&new_file); | ||
new_file = wrap(&new_file, filename, &mut new_logs); | ||
new_file = remove_trailing_spaces(&new_file); | ||
new_file = apply_indent(&new_file, args); | ||
new_file = apply_indent(&new_file, args, filename, &mut new_logs); | ||
tries += 1; | ||
if new_file == old_file { | ||
finished = true; | ||
} | ||
} | ||
|
||
// check indents return to zero | ||
if new_file.lines().last().unwrap().starts_with(' ') { | ||
log::error!("Indent does not return to zero at end of file"); | ||
} | ||
//if new_file.lines().last().unwrap().starts_with(' ') { | ||
//log::error!("Indent does not return to zero at end of file"); | ||
//} | ||
|
||
// TODO move this logging into wrap.rs | ||
if needs_wrap(&new_file) { | ||
for (i, line) in new_file.lines().enumerate() { | ||
if line_needs_wrap(line) { | ||
record_log( | ||
Warn, | ||
i, | ||
format!( | ||
" Line {}: cannot be wrapped: {}{:.50}...", | ||
i, WHITE, line | ||
), | ||
); | ||
} | ||
} | ||
} | ||
//if needs_wrap(&new_file) { | ||
//for (i, line) in new_file.lines().enumerate() { | ||
//if line_needs_wrap(line) { | ||
//record_log( | ||
//Warn, | ||
//i, | ||
//format!( | ||
//" Line {}: cannot be wrapped: {}{:.50}", | ||
//i, WHITE, line | ||
//), | ||
//); | ||
//} | ||
//} | ||
//} | ||
|
||
logs.append(&mut new_logs); | ||
new_file | ||
} | ||
|
||
pub fn format_file(file: &str, args: &Cli) -> String { | ||
pub fn format_file( | ||
file: &str, | ||
args: &Cli, | ||
filename: &str, | ||
logs: &mut Vec<Log>, | ||
) -> String { | ||
let mut new_file = remove_extra_newlines(file); | ||
new_file = begin_end_environments_new_line(&new_file); | ||
new_file = remove_tabs(&new_file); | ||
new_file = remove_trailing_spaces(&new_file); | ||
new_file = apply_passes(&new_file, args); | ||
new_file = apply_passes(&new_file, args, filename, logs); | ||
new_file | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.