diff --git a/crates/typos-cli/src/dict.rs b/crates/typos-cli/src/dict.rs index 612f07e..e3eb16e 100644 --- a/crates/typos-cli/src/dict.rs +++ b/crates/typos-cli/src/dict.rs @@ -249,7 +249,7 @@ impl<'i, 'w, D: typos::Dictionary> typos::Dictionary for Override<'i, 'w, D> { fn correct_ident<'s, 't>(&'s self, ident: typos::tokens::Identifier<'t>) -> Option> { for ignored in &self.ignored_identifiers { if ignored.is_match(ident.token()) { - return None; + return Some(Status::Valid); } } diff --git a/crates/typos-cli/src/policy.rs b/crates/typos-cli/src/policy.rs index fd4b71f..054729d 100644 --- a/crates/typos-cli/src/policy.rs +++ b/crates/typos-cli/src/policy.rs @@ -239,6 +239,7 @@ impl<'s> ConfigEngine<'s> { let dict = crate::dict::BuiltIn::new(dict_config.locale()); let mut dict = crate::dict::Override::new(dict); + dict.ignored_identifiers(dict_config.extend_ignore_identifiers_re()); dict.identifiers( dict_config .extend_identifiers() diff --git a/crates/typos-cli/tests/cmd/assumed-dir-failure.toml b/crates/typos-cli/tests/cmd/assumed-dir-failure.toml index a04fffd..0908fa4 100644 --- a/crates/typos-cli/tests/cmd/assumed-dir-failure.toml +++ b/crates/typos-cli/tests/cmd/assumed-dir-failure.toml @@ -1,2 +1,4 @@ bin.name = "typos" status.code = 2 +stdin = "" +stderr = "" diff --git a/crates/typos-cli/tests/cmd/double-escaped.stdin b/crates/typos-cli/tests/cmd/double-escaped.stdin deleted file mode 100644 index 7409124..0000000 --- a/crates/typos-cli/tests/cmd/double-escaped.stdin +++ /dev/null @@ -1,2 +0,0 @@ -\n\n -Destory diff --git a/crates/typos-cli/tests/cmd/double-escaped.stdout b/crates/typos-cli/tests/cmd/double-escaped.stdout deleted file mode 100644 index 35ace03..0000000 --- a/crates/typos-cli/tests/cmd/double-escaped.stdout +++ /dev/null @@ -1,2 +0,0 @@ -\n\n -Destroy diff --git a/crates/typos-cli/tests/cmd/double-escaped.toml b/crates/typos-cli/tests/cmd/double-escaped.toml index 6c0caf9..7994f3c 100644 --- a/crates/typos-cli/tests/cmd/double-escaped.toml +++ b/crates/typos-cli/tests/cmd/double-escaped.toml @@ -1,3 +1,12 @@ bin.name = "typos" args = "--write-changes -" status.code = 0 +stdin = ''' +\n\n +Destory +''' +stdout = """ +/n/n +Destroy +""" +stderr = "" diff --git a/crates/typos-cli/tests/cmd/extend-ignore-identifiers-re.in/_typos.toml b/crates/typos-cli/tests/cmd/extend-ignore-identifiers-re.in/_typos.toml new file mode 100644 index 0000000..ac8e24c --- /dev/null +++ b/crates/typos-cli/tests/cmd/extend-ignore-identifiers-re.in/_typos.toml @@ -0,0 +1,12 @@ +[files] +extend-exclude = ["_typos.toml"] + +[default.extend-identifiers] +hello = "goodbye" + +[type.fail] +extend-glob = ["*.fail"] + +[type.ignore] +extend-glob = ["*.ignore"] +extend-ignore-identifiers-re = ["he.*"] diff --git a/crates/typos-cli/tests/cmd/extend-ignore-identifiers-re.in/file.fail b/crates/typos-cli/tests/cmd/extend-ignore-identifiers-re.in/file.fail new file mode 100644 index 0000000..ce01362 --- /dev/null +++ b/crates/typos-cli/tests/cmd/extend-ignore-identifiers-re.in/file.fail @@ -0,0 +1 @@ +hello diff --git a/crates/typos-cli/tests/cmd/extend-ignore-identifiers-re.in/file.ignore b/crates/typos-cli/tests/cmd/extend-ignore-identifiers-re.in/file.ignore new file mode 100644 index 0000000..ce01362 --- /dev/null +++ b/crates/typos-cli/tests/cmd/extend-ignore-identifiers-re.in/file.ignore @@ -0,0 +1 @@ +hello diff --git a/crates/typos-cli/tests/cmd/extend-ignore-identifiers-re.toml b/crates/typos-cli/tests/cmd/extend-ignore-identifiers-re.toml new file mode 100644 index 0000000..60502eb --- /dev/null +++ b/crates/typos-cli/tests/cmd/extend-ignore-identifiers-re.toml @@ -0,0 +1,12 @@ +bin.name = "typos" +status.code = 2 +stdin = "" +stdout = """ +error: `hello` should be `goodbye` + --> ./file.fail:1:1 + | +1 | hello + | ^^^^^ + | +""" +stderr = "" diff --git a/crates/typos-cli/tests/cmd/file-failure.toml b/crates/typos-cli/tests/cmd/file-failure.toml index 0593893..1670260 100644 --- a/crates/typos-cli/tests/cmd/file-failure.toml +++ b/crates/typos-cli/tests/cmd/file-failure.toml @@ -1,3 +1,43 @@ bin.name = "typos" args = "../../README.md" status.code = 2 +stdin = "" +stdout = """ +error: `Supress` should be `Suppress` + --> ../../README.md:78:19 + | +78 | \"AttributeID.*Supress.*\", + | ^^^^^^^ + | +error: `Supress` should be `Suppress` + --> ../../README.md:83:12 + | +83 | AttributeIDSupressMenu = \"AttributeIDSupressMenu\" + | ^^^^^^^ + | +error: `Supress` should be `Suppress` + --> ../../README.md:83:38 + | +83 | AttributeIDSupressMenu = \"AttributeIDSupressMenu\" + | ^^^^^^^ + | +error: `Teh` should be `The` + --> ../../README.md:86:30 + | +86 | # Don't correct the surname \"Teh\" + | ^^^ + | +error: `teh` should be `the` + --> ../../README.md:87:1 + | +87 | teh = \"teh\" + | ^^^ + | +error: `teh` should be `the` + --> ../../README.md:87:8 + | +87 | teh = \"teh\" + | ^^^ + | +""" +stderr = "" diff --git a/crates/typos-cli/tests/cmd/relative-dir-failure.toml b/crates/typos-cli/tests/cmd/relative-dir-failure.toml index d742035..1534d1a 100644 --- a/crates/typos-cli/tests/cmd/relative-dir-failure.toml +++ b/crates/typos-cli/tests/cmd/relative-dir-failure.toml @@ -1,3 +1,5 @@ bin.name = "typos" args = "." status.code = 2 +stdin = "" +stderr = "" diff --git a/crates/typos-cli/tests/cmd/stdin-correct.stdin b/crates/typos-cli/tests/cmd/stdin-correct.stdin deleted file mode 100644 index 78a4360..0000000 --- a/crates/typos-cli/tests/cmd/stdin-correct.stdin +++ /dev/null @@ -1 +0,0 @@ -Apropriate world diff --git a/crates/typos-cli/tests/cmd/stdin-correct.stdout b/crates/typos-cli/tests/cmd/stdin-correct.stdout deleted file mode 100644 index 8d183c3..0000000 --- a/crates/typos-cli/tests/cmd/stdin-correct.stdout +++ /dev/null @@ -1 +0,0 @@ -Appropriate world diff --git a/crates/typos-cli/tests/cmd/stdin-correct.toml b/crates/typos-cli/tests/cmd/stdin-correct.toml index fd62546..81b3cb1 100644 --- a/crates/typos-cli/tests/cmd/stdin-correct.toml +++ b/crates/typos-cli/tests/cmd/stdin-correct.toml @@ -1,2 +1,9 @@ bin.name = "typos" args = "--write-changes -" +stdin = ''' +Apropriate world +''' +stdout = """ +Appropriate world +""" +stderr = "" diff --git a/crates/typos-cli/tests/cmd/stdin-failure-multiwidth.stdin b/crates/typos-cli/tests/cmd/stdin-failure-multiwidth.stdin deleted file mode 100644 index 989b316..0000000 --- a/crates/typos-cli/tests/cmd/stdin-failure-multiwidth.stdin +++ /dev/null @@ -1,34 +0,0 @@ ---- -Korean character (NFC) -Grapheme clusters: 1, codepoints: 1, UnicodeWidthStr::width() == 2 - -한 Apropriate world - ^^^^^^^^^^ highlight here - ---- -Korean character (NFD). -Grapheme clusters: 1, codepoints: 3, UnicodeWidthStr::width() == 2 - -한 Apropriate world - ^^^^^^^^^^ highlight here - ---- -Eye in Speech Bubble Emoji (U+1F441 U+FE0F U+200D U+1F5E8 U+FE0F, Recommended Emoji ZWJ Sequences, v2.0) -Grapheme clusters: 1, codepoints: 5, UnicodeWidthStr::width() == 2 (Read NOTE: https://github.com/unicode-rs/unicode-width) - -👁️‍🗨️ Apropriate world - ^^^^^^^^^^ highlight here - ---- -Face with spiral eyes (U+1F635 U+200D U+1F4AB, Recommended Emoji ZWJ Sequence, v13.1) -Grapheme clusters: 1, codepoints: 3, UnicodeWidthStr::width() == 4 (Read NOTE: https://github.com/unicode-rs/unicode-width) - -😵‍💫 Apropriate world - ^^^^^^^^^^ highlight here - ---- -Horizontal tab (\t, U+09) -Grapheme clusters: 1, codepoints: 1, UnicodeWidthStr::width() == 0 - - Apropriate world - ^^^^^^^^^^ highlight here \ No newline at end of file diff --git a/crates/typos-cli/tests/cmd/stdin-failure-multiwidth.stdout b/crates/typos-cli/tests/cmd/stdin-failure-multiwidth.stdout deleted file mode 100644 index 64176a2..0000000 --- a/crates/typos-cli/tests/cmd/stdin-failure-multiwidth.stdout +++ /dev/null @@ -1,30 +0,0 @@ -error: `Apropriate` should be `Appropriate` - --> -:5:3 - | -5 | 한 Apropriate world - | ^^^^^^^^^^ - | -error: `Apropriate` should be `Appropriate` - --> -:12:3 - | -12 | 한 Apropriate world - | ^^^^^^^^^^ - | -error: `Apropriate` should be `Appropriate` - --> -:19:3 - | -19 | 👁️‍🗨️ Apropriate world - | ^^^^^^^^^^ - | -error: `Apropriate` should be `Appropriate` - --> -:26:3 - | -26 | 😵‍💫 Apropriate world - | ^^^^^^^^^^ - | -error: `Apropriate` should be `Appropriate` - --> -:33:2 - | -33 | Apropriate world - | ^^^^^^^^^^ - | diff --git a/crates/typos-cli/tests/cmd/stdin-failure-multiwidth.toml b/crates/typos-cli/tests/cmd/stdin-failure-multiwidth.toml index 18f517f..34d656d 100644 --- a/crates/typos-cli/tests/cmd/stdin-failure-multiwidth.toml +++ b/crates/typos-cli/tests/cmd/stdin-failure-multiwidth.toml @@ -1,3 +1,72 @@ bin.name = "typos" args = "-" -status.code = 2 \ No newline at end of file +status.code = 2 +stdin = ''' +--- +Korean character (NFC) +Grapheme clusters: 1, codepoints: 1, UnicodeWidthStr::width() == 2 + +한 Apropriate world + ^^^^^^^^^^ highlight here + +--- +Korean character (NFD). +Grapheme clusters: 1, codepoints: 3, UnicodeWidthStr::width() == 2 + +한 Apropriate world + ^^^^^^^^^^ highlight here + +--- +Eye in Speech Bubble Emoji (U+1F441 U+FE0F U+200D U+1F5E8 U+FE0F, Recommended Emoji ZWJ Sequences, v2.0) +Grapheme clusters: 1, codepoints: 5, UnicodeWidthStr::width() == 2 (Read NOTE: https://github.com/unicode-rs/unicode-width) + +👁️‍🗨️ Apropriate world + ^^^^^^^^^^ highlight here + +--- +Face with spiral eyes (U+1F635 U+200D U+1F4AB, Recommended Emoji ZWJ Sequence, v13.1) +Grapheme clusters: 1, codepoints: 3, UnicodeWidthStr::width() == 4 (Read NOTE: https://github.com/unicode-rs/unicode-width) + +😵‍💫 Apropriate world + ^^^^^^^^^^ highlight here + +--- +Horizontal tab (\t, U+09) +Grapheme clusters: 1, codepoints: 1, UnicodeWidthStr::width() == 0 + + Apropriate world + ^^^^^^^^^^ highlight here +''' +stdout = """ +error: `Apropriate` should be `Appropriate` + --> -:5:3 + | +5 | 한 Apropriate world + | ^^^^^^^^^^ + | +error: `Apropriate` should be `Appropriate` + --> -:12:3 + | +12 | 한 Apropriate world + | ^^^^^^^^^^ + | +error: `Apropriate` should be `Appropriate` + --> -:19:3 + | +19 | 👁️‍🗨️ Apropriate world + | ^^^^^^^^^^ + | +error: `Apropriate` should be `Appropriate` + --> -:26:3 + | +26 | 😵‍💫 Apropriate world + | ^^^^^^^^^^ + | +error: `Apropriate` should be `Appropriate` + --> -:33:2 + | +33 | Apropriate world + | ^^^^^^^^^^ + | +""" +stderr = "" diff --git a/crates/typos-cli/tests/cmd/stdin-failure.stdin b/crates/typos-cli/tests/cmd/stdin-failure.stdin deleted file mode 100644 index 78a4360..0000000 --- a/crates/typos-cli/tests/cmd/stdin-failure.stdin +++ /dev/null @@ -1 +0,0 @@ -Apropriate world diff --git a/crates/typos-cli/tests/cmd/stdin-failure.toml b/crates/typos-cli/tests/cmd/stdin-failure.toml index 74181fa..9428a78 100644 --- a/crates/typos-cli/tests/cmd/stdin-failure.toml +++ b/crates/typos-cli/tests/cmd/stdin-failure.toml @@ -1,3 +1,15 @@ bin.name = "typos" args = "-" status.code = 2 +stdin = ''' +Apropriate world +''' +stdout = """ +error: `Apropriate` should be `Appropriate` + --> -:1:1 + | +1 | Apropriate world + | ^^^^^^^^^^ + | +""" +stderr = "" diff --git a/crates/typos-cli/tests/cmd/stdin-success.stdin b/crates/typos-cli/tests/cmd/stdin-success.stdin deleted file mode 100644 index 802992c..0000000 --- a/crates/typos-cli/tests/cmd/stdin-success.stdin +++ /dev/null @@ -1 +0,0 @@ -Hello world diff --git a/crates/typos-cli/tests/cmd/stdin-success.toml b/crates/typos-cli/tests/cmd/stdin-success.toml index 15dd0dd..7c934bd 100644 --- a/crates/typos-cli/tests/cmd/stdin-success.toml +++ b/crates/typos-cli/tests/cmd/stdin-success.toml @@ -1,2 +1,7 @@ bin.name = "typos" args = "-" +stdin = ''' +Hello world +''' +stdout = "" +stderr = "" diff --git a/docs/reference.md b/docs/reference.md index 4ea0251..d5d69c6 100644 --- a/docs/reference.md +++ b/docs/reference.md @@ -31,4 +31,4 @@ Configuration is read from the following (in precedence order) | default.extend-ignore-identifiers-re | \- | list of [regexes](https://docs.rs/regex/latest/regex/index.html#syntax) | Pattern-match always-valid identifiers | | default.extend-words | \- | table of strings | Corrections for [words](./design.md#identifiers-and-words). When the correction is blank, the word is never valid. When the correction is the key, the word is always valid. | | type.\.\ | \ | \ | See `default.` for child keys. Run with `--type-list` to see available ``s | -| type.\.extend_globs | \- | list of strings | File globs for matching `` | +| type.\.extend-glob | \- | list of strings | File globs for matching `` |