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

Function parse_lines

codespell_lib/_codespell.py:937–1083  ·  view source on GitHub ↗
(
    fragment: tuple[bool, int, list[str]],
    filename: str,
    colors: TermColors,
    summary: Optional[Summary],
    misspellings: dict[str, Misspelling],
    ignore_words_cased: set[str],
    exclude_lines: set[str],
    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

935
936
937def parse_lines(
938 fragment: tuple[bool, int, list[str]],
939 filename: str,
940 colors: TermColors,
941 summary: Optional[Summary],
942 misspellings: dict[str, Misspelling],
943 ignore_words_cased: set[str],
944 exclude_lines: set[str],
945 word_regex: Pattern[str],
946 ignore_word_regex: Optional[Pattern[str]],
947 uri_regex: Pattern[str],
948 uri_ignore_words: set[str],
949 context: Optional[tuple[int, int]],
950 options: argparse.Namespace,
951) -> tuple[int, bool, list[tuple[int, str, str]]]:
952 bad_count = 0
953 changed = False
954 changes_made: list[tuple[int, str, str]] = []
955
956 _, fragment_line_number, lines = fragment
957
958 for i, line in enumerate(lines):
959 line = line.rstrip()
960 if not line or line in exclude_lines:
961 continue
962 line_number = fragment_line_number + i
963
964 extra_words_to_ignore = set()
965 match = (
966 inline_ignore_regex.search(line) if codespell_ignore_tag in line else None
967 )
968 if match:
969 extra_words_to_ignore = set(
970 filter(None, (match.group("words") or "").split(","))
971 )
972 if not extra_words_to_ignore:
973 continue
974
975 fixed_words = set()
976 asked_for = set()
977
978 # If all URI spelling errors will be ignored, erase any URI before
979 # extracting words. Otherwise, apply ignores after extracting words.
980 # This ensures that if a URI ignore word occurs both inside a URI and
981 # outside, it will still be a spelling error.
982 if "*" in uri_ignore_words:
983 line = uri_regex.sub(" ", line)
984 check_matches = extract_words_iter(line, word_regex, ignore_word_regex)
985 if "*" not in uri_ignore_words:
986 check_matches = apply_uri_ignore_words(
987 check_matches,
988 line,
989 word_regex,
990 ignore_word_regex,
991 uri_regex,
992 uri_ignore_words,
993 )
994 for match in check_matches:

Callers 1

parse_fileFunction · 0.85

Calls 7

extract_words_iterFunction · 0.85
apply_uri_ignore_wordsFunction · 0.85
fix_caseFunction · 0.85
print_contextFunction · 0.85
ask_for_word_fixFunction · 0.85
_format_colored_outputFunction · 0.85
updateMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…