Skip to content

Commit

Permalink
[Enhancement] complain: Add Range Mercy Feature (#1224)
Browse files Browse the repository at this point in the history
* Added ::= complain:  ask for range mercy for rule ÆC-0003

* Changed ::= README:  apply range mercy for URL definition section

* Added ::= complain:  further test cases

* Added ::= CI:  run complain linter over .github/ directory; fixes #1222

* Create summary of recent changes

---------

Co-authored-by: GitHub Actions <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
kevinmatthes and github-actions[bot] committed Feb 16, 2024
1 parent 344a531 commit 4e2653c
Show file tree
Hide file tree
Showing 5 changed files with 179 additions and 139 deletions.
2 changes: 1 addition & 1 deletion .justfile
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ default: ci
# Run all CI steps.
ci:
cargo fmt --check
cargo r -- complain src/ tests/
cargo r -- complain .github/ src/ tests/
just feature cff
just feature cff-create
just feature mkcws
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
(
references: {},
changes: {
"Added": [
"CI: run complain linter over .github/ directory; fixes #1222",
"complain: ask for range mercy for rule ÆC-0003",
"complain: further test cases",
],
"Changed": [
"README: apply range mercy for URL definition section",
],
},
)
11 changes: 11 additions & 0 deletions src/complain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,8 +259,19 @@ impl Logic {

fn aec_0003(&mut self) -> Result<()> {
let mut line = 1;
let mut mercy = false;

for l in self.data.lines() {
if l.contains("#[aeruginous::mercy::0003::start]") {
mercy = true;
} else if l.contains("#[aeruginous::mercy::0003::end]") {
mercy = false;
}

if mercy {
continue;
}

let c = l.chars().count();

if c > self.cli.line_width
Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
| |
\******************************************************************************/

//! <!------------------------------------------------------------------------->
//! <!------------------- #[aeruginous::mercy::0003::start] ------------------->
//!
//! [ci]: https://github.com/kevinmatthes/aeruginous-rs/workflows/ci/badge.svg
//! [crate]: https://crates.io/crates/aeruginous
Expand All @@ -36,7 +36,7 @@
//! [repository]: https://github.com/kevinmatthes/aeruginous-rs
//! [tag]: https://img.shields.io/github/v/tag/kevinmatthes/aeruginous-rs
//!
//! <!------------------------------------------------------------------------->
//! <!-------------------- #[aeruginous::mercy::0003::end] -------------------->
//!
//! <p align = 'center'>
//! <a href = 'https://github.com/kevinmatthes/aeruginous-rs'>
Expand Down
288 changes: 152 additions & 136 deletions tests/complain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,153 +17,169 @@
| |
\******************************************************************************/

use aeruginous::{Complain, IndentationUnit};
use std::{
fs::{remove_file, write},
path::PathBuf,
};

macro_rules! make_test {
( @content $( $name:ident : $text:literal -> $n:tt ),+ ) => {
$(
#[test]
fn $name() {
let file = concat!(stringify!($name), ".txt");
let ac = Complain::new(vec![PathBuf::from(file)]);

write(file, $text).unwrap();

assert!(ac.main().is_err());
assert_eq!($n, ac.process().unwrap());

remove_file(file).unwrap();
}
)+
mod complain {
use aeruginous::{Complain, IndentationUnit};
use std::{
fs::{remove_file, write},
path::PathBuf,
};

( @content @tabs $( $name:ident : $text:literal -> $n:tt ),+ ) => {
$(
#[test]
fn $name() {
let file = concat!(stringify!($name), ".txt");
let mut ac = Complain::new(vec![PathBuf::from(file)]);

ac.indent_by(IndentationUnit::Tabs);
write(file, $text).unwrap();

assert!(ac.main().is_err());
assert_eq!($n, ac.process().unwrap());

remove_file(file).unwrap();
}
)+
};

( @path @failure $( $name:ident : $file:literal -> $n:tt ),+ ) => {
$(
#[test]
fn $name() {
let ac = Complain::new(vec![PathBuf::from($file)]);

assert!(ac.main().is_err());
assert_eq!($n, ac.process().unwrap());
}
)+
};

( @path @success $( $name:ident : $file:literal ),+ ) => {
$(
#[test]
fn $name() {
let ac = Complain::new(vec![PathBuf::from($file)]);
macro_rules! make_test {
( @content $( $name:ident : $text:literal -> $n:tt ),+ ) => {
$(
#[test]
fn $name() {
let file = concat!(stringify!($name), ".txt");
let ac = Complain::new(vec![PathBuf::from(file)]);

write(file, $text).unwrap();

assert!(ac.main().is_err());
assert_eq!($n, ac.process().unwrap());

remove_file(file).unwrap();
}
)+
};

( @content @tabs $( $name:ident : $text:literal -> $n:tt ),+ ) => {
$(
#[test]
fn $name() {
let file = concat!(stringify!($name), ".txt");
let mut ac = Complain::new(vec![PathBuf::from(file)]);

ac.indent_by(IndentationUnit::Tabs);
write(file, $text).unwrap();

assert!(ac.main().is_err());
assert_eq!($n, ac.process().unwrap());

remove_file(file).unwrap();
}
)+
};

( @path @failure $( $name:ident : $file:literal -> $n:tt ),+ ) => {
$(
#[test]
fn $name() {
let ac = Complain::new(vec![PathBuf::from($file)]);

assert!(ac.main().is_err());
assert_eq!($n, ac.process().unwrap());
}
)+
};

( @path @success $( $name:ident : $file:literal ),+ ) => {
$(
#[test]
fn $name() {
let ac = Complain::new(vec![PathBuf::from($file)]);

assert!(ac.main().is_ok());
assert_eq!(0, ac.process().unwrap());
}
)+
};
}

make_test!(@content
ac_0001_1: "" -> 1,
ac_0001_2: "abc" -> 1,
ac_0002_1: "\r\n" -> 1,
ac_0002_2: "abc\r\n" -> 1,
ac_0004_1: "abc \n" -> 1,
ac_0004_2: "abc\t\n" -> 1,
ac_0004_3: "abc \t\n" -> 1,
ac_0004_4: "abc\t \n" -> 1,
ac_0005_1: "\tabc\n" -> 1,
ac_0006_1: " \t\n" -> 1,
ac_0006_2: " \tabc\n" -> 1,
ac_0007_1: "abc\tabc\n" -> 1
);

assert!(ac.main().is_ok());
assert_eq!(0, ac.process().unwrap());
}
)+
};
}
make_test!(@content @tabs
ac_0001_3: "" -> 1,
ac_0001_4: "abc" -> 1,
ac_0002_3: "\r\n" -> 1,
ac_0002_4: "abc\r\n" -> 1,
ac_0004_5: "abc \n" -> 1,
ac_0004_6: "abc\t\n" -> 1,
ac_0004_7: "abc \t\n" -> 1,
ac_0004_8: "abc\t \n" -> 1,
ac_0005_2: " abc\n" -> 1,
ac_0006_3: "\t \n" -> 1,
ac_0006_4: "\t abc\n" -> 1,
ac_0007_2: "abc\tabc\n" -> 1
);

make_test!(@content
ac_0001_1: "" -> 1,
ac_0001_2: "abc" -> 1,
ac_0002_1: "\r\n" -> 1,
ac_0002_2: "abc\r\n" -> 1,
ac_0004_1: "abc \n" -> 1,
ac_0004_2: "abc\t\n" -> 1,
ac_0004_3: "abc \t\n" -> 1,
ac_0004_4: "abc\t \n" -> 1,
ac_0005_1: "\tabc\n" -> 1,
ac_0006_1: " \t\n" -> 1,
ac_0006_2: " \tabc\n" -> 1,
ac_0007_1: "abc\tabc\n" -> 1
);

make_test!(@content @tabs
ac_0001_3: "" -> 1,
ac_0001_4: "abc" -> 1,
ac_0002_3: "\r\n" -> 1,
ac_0002_4: "abc\r\n" -> 1,
ac_0004_5: "abc \n" -> 1,
ac_0004_6: "abc\t\n" -> 1,
ac_0004_7: "abc \t\n" -> 1,
ac_0004_8: "abc\t \n" -> 1,
ac_0005_2: " abc\n" -> 1,
ac_0006_3: "\t \n" -> 1,
ac_0006_4: "\t abc\n" -> 1,
ac_0007_2: "abc\tabc\n" -> 1
);

make_test!(@path @failure
ac_0003: "graphs/invalid/too_long_comments.agd" -> 2
);

make_test!(@path @success
ac_success_license_file: "LICENSE"
);

#[test]
fn default() {
assert_eq!(
Complain::default().state(),
(&Vec::new(), [false; 7], IndentationUnit::Spaces, 80)
make_test!(@path @failure
ac_0003: "graphs/invalid/too_long_comments.agd" -> 2
);
}

#[test]
fn ignore_all_lints() {
let mut ac = Complain::new(vec![PathBuf::from(
"graphs/invalid/too_long_comments.agd",
)]);

ac.ignore_carriage_return_line_feeds();
ac.ignore_line_width_issues();
ac.ignore_missing_final_line_feed();
ac.ignore_mixed_indentation();
ac.ignore_tabs_within_lines();
ac.ignore_trailing_white_space_characters();
ac.ignore_wrong_indentation();

assert!(ac.main().is_ok());
assert_eq!(
ac.state(),
(
&vec![PathBuf::from("graphs/invalid/too_long_comments.agd")],
[true; 7],
IndentationUnit::Spaces,
80
)
make_test!(@path @success
ac_success_license_file: "LICENSE"
);

#[test]
fn default() {
assert_eq!(
Complain::default().state(),
(&Vec::new(), [false; 7], IndentationUnit::Spaces, 80)
);
}

#[test]
fn ignore_all_lints() {
let mut ac = Complain::new(vec![PathBuf::from(
"graphs/invalid/too_long_comments.agd",
)]);

ac.ignore_carriage_return_line_feeds();
ac.ignore_line_width_issues();
ac.ignore_missing_final_line_feed();
ac.ignore_mixed_indentation();
ac.ignore_tabs_within_lines();
ac.ignore_trailing_white_space_characters();
ac.ignore_wrong_indentation();

assert!(ac.main().is_ok());
assert_eq!(
ac.state(),
(
&vec![PathBuf::from("graphs/invalid/too_long_comments.agd")],
[true; 7],
IndentationUnit::Spaces,
80
)
);
}

#[test]
fn repository_check() {
let mut ac = Complain::default();

ac.push("src/");
ac.push("tests/");

assert!(ac.main().is_ok());
}
}

#[test]
fn repository_check() {
let mut ac = Complain::default();
mod indentation_unit {
use aeruginous::IndentationUnit;

ac.push("src/");
ac.push("tests/");
#[test]
fn debug_trait() {
assert_eq!(format!("{:#?}", IndentationUnit::Spaces), "Spaces");
}

assert!(ac.main().is_ok());
#[test]
fn default_trait() {
assert_eq!(IndentationUnit::default(), IndentationUnit::Spaces);
}
}

/******************************************************************************/

0 comments on commit 4e2653c

Please sign in to comment.