Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions codespell_lib/_spellchecker.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,9 @@ def build_dict(
translate_tables = [(x, str.maketrans(x, y)) for x, y in alt_chars]
for line in f:
[key, data] = line.split("->")
# TODO: For now, convert both to lower.
# Someday we can maybe add support for fixing caps.
# Only convert key to lower case.
# Do not modify data to lower case. Leave it as per dictionary.
key = key.lower()
data = data.lower()
if key not in ignore_words:
add_misspelling(key, data, misspellings)
# generate alternative misspellings/fixes
Expand Down
43 changes: 39 additions & 4 deletions codespell_lib/_text_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,46 @@
"""


def is_camel_case_word(input_word: str) -> bool:
return (
(input_word != input_word.lower())
and (input_word != input_word.upper())
and ("_" not in input_word)
and ("-" not in input_word)
and (" " not in input_word)
)


def is_camel_case_string(input_string: str) -> bool:
return any(is_camel_case_word(word) for word in input_string.split(","))


def fix_case(word: str, fixword: str) -> str:
if word == word.capitalize():
return ", ".join(w.strip().capitalize() for w in fixword.split(","))
if fixword == fixword.upper():
# abbreviation, acronym: fixword is in all upper case.
# Use fixword as per dictionary.
# Eg. asscii->ASCII
return fixword
if word == word.capitalize() and fixword == fixword.lower():
# word is capitalized and fixword(s) in lower.
# Capitalize/Title fixword(s).
# Eg. Weather, Whether,
return fixword.title()
if word == word.capitalize() and not is_camel_case_string(fixword):
# word is capitalized and fixword(s) contain mixed with no camelCase.
# Capitalize/Title fixword(s).
# Eg. skipt->skip, Skype, skipped,
return fixword.title()
if word == word.upper():
# word is in all upper case, change fixword to upper.
# Eg. MONDAY
return fixword.upper()
# they are both lower case
# or we don't have any idea
if word.lower() == fixword.lower():
# Special feature only meant for private custom dictionary.
# word is valid but fixword required in CamelCase.
# Use fixword as per dictionary.
# Eg. mysql->MySQL
return fixword
# word is in lower, capitalize, CamelCase or whatever.
# Use fixword as per dictionary.
return fixword
Loading
Loading