Skip to content

Commit

Permalink
Print correct index
Browse files Browse the repository at this point in the history
  • Loading branch information
VariantXYZ committed Jun 23, 2024
1 parent 4455412 commit 800333a
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions scripts/test_spellcheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class Line:
class File:
name: str
lines: list[Line]
indices: list[int]


def parse_arguments():
Expand Down Expand Up @@ -84,8 +85,9 @@ def main():
# Saving lines for later output
indices.append(index)
lines.append(Line(words))

base_filename = os.path.basename(filename)
file = File(base_filename, lines)
file = File(base_filename, lines, indices)

# Spellcheck unknown words
for word in unknown:
Expand All @@ -110,11 +112,11 @@ def main():
# Add the correction to the dictionary
corrections[word.lower()] = correction

for i, line in enumerate(file.lines, 1):
for i, (line, index) in enumerate(zip(file.lines, file.indices), 1):
for word in line.words:
# If the word is misspelled
if word.lower() in corrections:
print(f"Spellcheck: {file.name}:{indices[i]}\t{word} -> {corrections[word.lower()]}")
print(f"Spellcheck: {file.name}:{index}\t{word} -> {corrections[word.lower()]}")

if __name__ == "__main__":
main()

0 comments on commit 800333a

Please sign in to comment.