3939 Tuple ,
4040)
4141
42+ from ._spellchecker import Misspelling , build_dict
43+ from ._text_util import fix_case
44+
4245# autogenerated by setuptools_scm
4346from ._version import ( # type: ignore[import-not-found]
4447 __version__ as VERSION , # noqa: N812
5255 "(\\ b(?:https?|[ts]?ftp|file|git|smb)://[^\\ s]+(?=$|\\ s)|"
5356 "\\ b[\\ w.%+-]+@[\\ w.-]+\\ b)"
5457)
55- # Pass all misspellings through this translation table to generate
56- # alternative misspellings and fixes.
57- alt_chars = (("'" , "’" ),) # noqa: RUF001
5858inline_ignore_regex = re .compile (r"[^\w\s]\s?codespell:ignore\b(\s+(?P<words>[\w,]*))?" )
5959USAGE = """
6060\t %prog [OPTIONS] [file1 file2 ... fileN]
@@ -167,13 +167,6 @@ def match(self, filename: str) -> bool:
167167 return any (fnmatch .fnmatch (filename , p ) for p in self .pattern_list )
168168
169169
170- class Misspelling :
171- def __init__ (self , data : str , fix : bool , reason : str ) -> None :
172- self .data = data
173- self .fix = fix
174- self .reason = reason
175-
176-
177170class TermColors :
178171 def __init__ (self ) -> None :
179172 self .FILE = "\033 [33m"
@@ -703,48 +696,6 @@ def build_ignore_words(
703696 )
704697
705698
706- def add_misspelling (
707- key : str ,
708- data : str ,
709- misspellings : Dict [str , Misspelling ],
710- ) -> None :
711- data = data .strip ()
712-
713- if "," in data :
714- fix = False
715- data , reason = data .rsplit ("," , 1 )
716- reason = reason .lstrip ()
717- else :
718- fix = True
719- reason = ""
720-
721- misspellings [key ] = Misspelling (data , fix , reason )
722-
723-
724- def build_dict (
725- filename : str ,
726- misspellings : Dict [str , Misspelling ],
727- ignore_words : Set [str ],
728- ) -> None :
729- with open (filename , encoding = "utf-8" ) as f :
730- translate_tables = [(x , str .maketrans (x , y )) for x , y in alt_chars ]
731- for line in f :
732- [key , data ] = line .split ("->" )
733- # TODO: For now, convert both to lower.
734- # Someday we can maybe add support for fixing caps.
735- key = key .lower ()
736- data = data .lower ()
737- if key not in ignore_words :
738- add_misspelling (key , data , misspellings )
739- # generate alternative misspellings/fixes
740- for x , table in translate_tables :
741- if x in key :
742- alt_key = key .translate (table )
743- alt_data = data .translate (table )
744- if alt_key not in ignore_words :
745- add_misspelling (alt_key , alt_data , misspellings )
746-
747-
748699def is_hidden (filename : str , check_hidden : bool ) -> bool :
749700 bfilename = os .path .basename (filename )
750701
@@ -759,16 +710,6 @@ def is_text_file(filename: str) -> bool:
759710 return b"\x00 " not in s
760711
761712
762- def fix_case (word : str , fixword : str ) -> str :
763- if word == word .capitalize ():
764- return ", " .join (w .strip ().capitalize () for w in fixword .split ("," ))
765- if word == word .upper ():
766- return fixword .upper ()
767- # they are both lower case
768- # or we don't have any idea
769- return fixword
770-
771-
772713def ask_for_word_fix (
773714 line : str ,
774715 match : Match [str ],
0 commit comments