Skip to content

Commit 28cd50a

Browse files
authored
Merge pull request #833 from epage/fix
fix(cli): Dont correct O_WRONLY
2 parents 5edf45b + 5fd0df2 commit 28cd50a

File tree

5 files changed

+35
-14
lines changed

5 files changed

+35
-14
lines changed

crates/typos-cli/src/dict.rs

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@ impl BuiltIn {
2020

2121
pub fn correct_ident<'s>(
2222
&'s self,
23-
_ident: typos::tokens::Identifier<'_>,
23+
ident_token: typos::tokens::Identifier<'_>,
2424
) -> Option<Status<'s>> {
25-
None
25+
let ident = ident_token.token();
26+
self.correct_ident_with_dict(ident)
2627
}
2728

2829
pub fn correct_word<'s>(&'s self, word_token: typos::tokens::Word<'_>) -> Option<Status<'s>> {
@@ -32,7 +33,7 @@ impl BuiltIn {
3233

3334
let word = word_token.token();
3435
let word_case = unicase::UniCase::new(word);
35-
let mut corrections = if let Some(corrections) = self.correct_with_dict(word_case) {
36+
let mut corrections = if let Some(corrections) = self.correct_word_with_dict(word_case) {
3637
if corrections.is_empty() {
3738
Status::Invalid
3839
} else {
@@ -50,15 +51,32 @@ impl BuiltIn {
5051

5152
#[cfg(feature = "dict")]
5253
impl BuiltIn {
54+
fn correct_ident_with_dict<'s>(&self, ident: &str) -> Option<Status<'s>> {
55+
match ident {
56+
"O_WRONLY" => Some(Status::Valid),
57+
_ => None,
58+
}
59+
}
60+
5361
// Not using `Status` to avoid the allocations
54-
fn correct_with_dict(&self, word: unicase::UniCase<&str>) -> Option<&'static [&'static str]> {
62+
fn correct_word_with_dict(
63+
&self,
64+
word: unicase::UniCase<&str>,
65+
) -> Option<&'static [&'static str]> {
5566
typos_dict::WORD_TRIE.find(&word).copied()
5667
}
5768
}
5869

5970
#[cfg(not(feature = "dict"))]
6071
impl BuiltIn {
61-
fn correct_with_dict(&self, _word: unicase::UniCase<&str>) -> Option<&'static [&'static str]> {
72+
fn correct_ident_with_dict<'s>(&self, _ident: &str) -> Option<Status<'s>> {
73+
None
74+
}
75+
76+
fn correct_word_with_dict(
77+
&self,
78+
_word: unicase::UniCase<&str>,
79+
) -> Option<&'static [&'static str]> {
6280
None
6381
}
6482
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1+
import os
2+
13
from numpy.typing import NDArray # should work
4+
5+
print(os.O_WRONLY) # should work

crates/typos-dict/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
mod dict_codegen;
1+
mod word_codegen;
22

3-
pub use crate::dict_codegen::*;
3+
pub use crate::word_codegen::WORD_TRIE;
File renamed without changes.

crates/typos-dict/tests/codegen.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
1-
const DICT: &[u8] = include_bytes!("../assets/words.csv");
2-
31
#[test]
42
fn codegen() {
53
let mut content = vec![];
6-
generate(&mut content);
4+
const DICT: &[u8] = include_bytes!("../assets/words.csv");
5+
generate(&mut content, "WORD", DICT);
76

87
let content = String::from_utf8(content).unwrap();
98
let content = codegenrs::rustfmt(&content, None).unwrap();
10-
snapbox::assert_eq_path("./src/dict_codegen.rs", content);
9+
snapbox::assert_eq_path("./src/word_codegen.rs", content);
1110
}
1211

13-
fn generate<W: std::io::Write>(file: &mut W) {
12+
fn generate<W: std::io::Write>(file: &mut W, prefix: &str, dict: &[u8]) {
1413
writeln!(
1514
file,
1615
"// This file is @generated by {}",
@@ -23,13 +22,13 @@ fn generate<W: std::io::Write>(file: &mut W) {
2322
let records: Vec<_> = csv::ReaderBuilder::new()
2423
.has_headers(false)
2524
.flexible(true)
26-
.from_reader(DICT)
25+
.from_reader(dict)
2726
.records()
2827
.map(|r| r.unwrap())
2928
.collect();
3029
dictgen::generate_trie(
3130
file,
32-
"WORD",
31+
prefix,
3332
"&'static [&'static str]",
3433
records.iter().map(|record| {
3534
let mut record_fields = record.iter();

0 commit comments

Comments
 (0)