aider: Refactored the find_filenames_and_linenums function to search for occurrences of <filename>:\d+ in the text and return a list of matches.

# Aider chat conversation:

USER: do the todo

ASSISTANT: To implement the TODO, we need to:

1. Search the text for all occurrences of `<filename>:\d+` where `<filename>` is one of the filenames in the list `fnames`.
2. Make a list of these occurrences.

Here is the *SEARCH/REPLACE* block:

aider/linter.py
```python
<<<<<<< SEARCH
def find_filenames_and_linenums(text, fnames):
    # TODO:
    # search text for all occurrances of <filename>:\d+ and make a list of them
    # where <filename> is one of the filenames in the list `fnames`
    pass
=======
import re

def find_filenames_and_linenums(text, fnames):
    """
    Search text for all occurrences of <filename>:\d+ and make a list of them
    where <filename> is one of the filenames in the list `fnames`.
    """
    pattern = re.compile(r'(\b(?:' + '|'.join(re.escape(fname) for fname in fnames) + r'):\d+\b)')
    matches = pattern.findall(text)
    return matches
>>>>>>> REPLACE
```
This commit is contained in:
Paul Gauthier 2024-05-18 19:35:37 -07:00
parent ef286f0de6
commit 9e0f20bb9a

View file

@ -162,11 +162,16 @@ def traverse_tree(node):
return errors
import re
def find_filenames_and_linenums(text, fnames):
# TODO:
# search text for all occurrances of <filename>:\d+ and make a list of them
# where <filename> is one of the filenames in the list `fnames`
pass
"""
Search text for all occurrences of <filename>:\d+ and make a list of them
where <filename> is one of the filenames in the list `fnames`.
"""
pattern = re.compile(r'(\b(?:' + '|'.join(re.escape(fname) for fname in fnames) + r'):\d+\b)')
matches = pattern.findall(text)
return matches
def main():
"""