MCPcopy Index your code
hub / github.com/codespell-project/codespell / parse_file

Function parse_file

codespell_lib/_codespell.py:1086–1214  ·  view source on GitHub ↗
(
    filename: str,
    colors: TermColors,
    summary: Optional[Summary],
    misspellings: dict[str, Misspelling],
    ignore_words_cased: set[str],
    exclude_lines: set[str],
    file_opener: FileOpener,
    word_regex: Pattern[str],
    ignore_word_regex: Optional[Pattern[str]],
    uri_regex: Pattern[str],
    uri_ignore_words: set[str],
    context: Optional[tuple[int, int]],
    options: argparse.Namespace,
)

Source from the content-addressed store, hash-verified

1084
1085
1086def parse_file(
1087 filename: str,
1088 colors: TermColors,
1089 summary: Optional[Summary],
1090 misspellings: dict[str, Misspelling],
1091 ignore_words_cased: set[str],
1092 exclude_lines: set[str],
1093 file_opener: FileOpener,
1094 word_regex: Pattern[str],
1095 ignore_word_regex: Optional[Pattern[str]],
1096 uri_regex: Pattern[str],
1097 uri_ignore_words: set[str],
1098 context: Optional[tuple[int, int]],
1099 options: argparse.Namespace,
1100) -> int:
1101 bad_count = 0
1102 fragments = None
1103
1104 # Read lines.
1105 if filename == "-":
1106 f = sys.stdin
1107 encoding = "utf-8"
1108 fragments = file_opener.get_lines(f)
1109 else:
1110 if options.check_filenames:
1111 for word in extract_words(filename, word_regex, ignore_word_regex):
1112 if word in ignore_words_cased:
1113 continue
1114 lword = word.lower()
1115 if lword not in misspellings:
1116 continue
1117 fix = misspellings[lword].fix
1118 fixword = fix_case(word, misspellings[lword].data)
1119
1120 if summary and fix:
1121 summary.update(lword)
1122
1123 cfilename, _, cwrongword, crightword = _format_colored_output(
1124 filename, colors, 0, word, fixword
1125 )
1126
1127 reason = misspellings[lword].reason
1128 if reason:
1129 if options.quiet_level & QuietLevels.DISABLED_FIXES:
1130 continue
1131 creason = f" | {colors.FILE}{reason}{colors.DISABLE}"
1132 else:
1133 if options.quiet_level & QuietLevels.NON_AUTOMATIC_FIXES:
1134 continue
1135 creason = ""
1136
1137 bad_count += 1
1138
1139 print(f"{cfilename}: {cwrongword} ==> {crightword}{creason}")
1140
1141 # ignore irregular files
1142 if not os.path.isfile(filename):
1143 return bad_count

Callers 1

mainFunction · 0.85

Calls 8

extract_wordsFunction · 0.85
fix_caseFunction · 0.85
_format_colored_outputFunction · 0.85
is_text_fileFunction · 0.85
parse_linesFunction · 0.85
get_linesMethod · 0.80
updateMethod · 0.80
openMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…