From 3f41a6791c31127849eea17030ed03152b99b445 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Wed, 9 Aug 2023 08:15:05 -0500 Subject: [PATCH 1/2] test(cli): Verify disallowed functionality --- .../tests/cmd/config-disallowed.in/_typos.toml | 2 ++ .../tests/cmd/config-disallowed.in/file | 1 + .../typos-cli/tests/cmd/config-disallowed.toml | 17 +++++++++++++++++ 3 files changed, 20 insertions(+) create mode 100644 crates/typos-cli/tests/cmd/config-disallowed.in/_typos.toml create mode 100644 crates/typos-cli/tests/cmd/config-disallowed.in/file create mode 100644 crates/typos-cli/tests/cmd/config-disallowed.toml diff --git a/crates/typos-cli/tests/cmd/config-disallowed.in/_typos.toml b/crates/typos-cli/tests/cmd/config-disallowed.in/_typos.toml new file mode 100644 index 0000000..56a17b6 --- /dev/null +++ b/crates/typos-cli/tests/cmd/config-disallowed.in/_typos.toml @@ -0,0 +1,2 @@ +[default.extend-identifiers] +hello = "" diff --git a/crates/typos-cli/tests/cmd/config-disallowed.in/file b/crates/typos-cli/tests/cmd/config-disallowed.in/file new file mode 100644 index 0000000..b4cfe09 --- /dev/null +++ b/crates/typos-cli/tests/cmd/config-disallowed.in/file @@ -0,0 +1 @@ +hello `hello` diff --git a/crates/typos-cli/tests/cmd/config-disallowed.toml b/crates/typos-cli/tests/cmd/config-disallowed.toml new file mode 100644 index 0000000..e484ec5 --- /dev/null +++ b/crates/typos-cli/tests/cmd/config-disallowed.toml @@ -0,0 +1,17 @@ +bin.name = "typos" +stdin = "" +stdout = """ +error: `hello` is disallowed + --> ./file:1:1 + | +1 | hello `hello` + | ^^^^^ + | +error: `hello` is disallowed + --> ./file:1:8 + | +1 | hello `hello` + | ^^^^^ + | +""" +stderr = "" From 3bae999225ad493ea481309a2846b2a099d6eacd Mon Sep 17 00:00:00 2001 From: Ed Page Date: Wed, 9 Aug 2023 08:21:53 -0500 Subject: [PATCH 2/2] fix(cli): Report bad exit code on disallowed --- crates/typos-cli/src/bin/typos-cli/report.rs | 2 +- crates/typos-cli/src/report.rs | 4 ++-- crates/typos-cli/tests/cmd/config-disallowed.toml | 1 + 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/crates/typos-cli/src/bin/typos-cli/report.rs b/crates/typos-cli/src/bin/typos-cli/report.rs index 3f86f51..8f3970a 100644 --- a/crates/typos-cli/src/bin/typos-cli/report.rs +++ b/crates/typos-cli/src/bin/typos-cli/report.rs @@ -89,7 +89,7 @@ impl<'r> MessageStatus<'r> { impl<'r> Report for MessageStatus<'r> { fn report(&self, msg: Message) -> Result<(), std::io::Error> { - if msg.is_correction() { + if msg.is_typo() { self.typos_found.store(true, atomic::Ordering::Relaxed); } if msg.is_error() { diff --git a/crates/typos-cli/src/report.rs b/crates/typos-cli/src/report.rs index e11ac52..06aee50 100644 --- a/crates/typos-cli/src/report.rs +++ b/crates/typos-cli/src/report.rs @@ -20,10 +20,10 @@ pub enum Message<'m> { } impl<'m> Message<'m> { - pub fn is_correction(&self) -> bool { + pub fn is_typo(&self) -> bool { match self { Message::BinaryFile(_) => false, - Message::Typo(c) => c.corrections.is_correction(), + Message::Typo(c) => !c.corrections.is_valid(), Message::FileType(_) => false, Message::File(_) => false, Message::Parse(_) => false, diff --git a/crates/typos-cli/tests/cmd/config-disallowed.toml b/crates/typos-cli/tests/cmd/config-disallowed.toml index e484ec5..3185611 100644 --- a/crates/typos-cli/tests/cmd/config-disallowed.toml +++ b/crates/typos-cli/tests/cmd/config-disallowed.toml @@ -1,4 +1,5 @@ bin.name = "typos" +status.code = 2 stdin = "" stdout = """ error: `hello` is disallowed