o
    DD©i^  ã                   @   s\   d dl Z d dlmZmZmZ d dlZd dlmZ d dl	m
Z
 d dlmZ G dd„ de
ƒZdS )é    N)ÚDictÚPatternÚUnion)ÚCodemodContext)ÚContextAwareVisitor)ÚPositionProviderc                       sz   e Zd ZdZefZdededdf‡ fdd„Zde	j
defd	d
„Zde	jdefdd„Zdee	j
e	jf ddfdd„Z‡  ZS )ÚGatherCommentsVisitora²  
    Collects all comments matching a certain regex and their line numbers.
    This visitor is useful for capturing special-purpose comments, for example
    ``noqa`` style lint suppression annotations.

    Standalone comments are assumed to affect the line following them, and
    inline ones are recorded with the line they are on.

    After visiting a CST, matching comments are collected in the ``comments``
    attribute.
    ÚcontextÚcomment_regexÚreturnNc                    s"   t ƒ  |¡ i | _t |¡| _d S )N)ÚsuperÚ__init__ÚcommentsÚreÚcompileÚ_comment_matcher)Úselfr	   r
   ©Ú	__class__© úa/var/www/Datamplify/venv/lib/python3.10/site-packages/libcst/codemod/visitors/_gather_comments.pyr      s   zGatherCommentsVisitor.__init__Únodec                 C   ó   |j d ur
|  |¡ dS ©NF©ÚcommentÚhandle_comment©r   r   r   r   r   Úvisit_EmptyLine'   ó   

z%GatherCommentsVisitor.visit_EmptyLinec                 C   r   r   r   r   r   r   r   Úvisit_TrailingWhitespace,   r   z.GatherCommentsVisitor.visit_TrailingWhitespacec                 C   sV   |j }|d us	J ‚| j |j¡sd S |  t|¡jj}t|t	j
ƒr$|d7 }|| j|< d S )Né   )r   r   ÚmatchÚvalueÚget_metadatar   ÚstartÚlineÚ
isinstanceÚcstÚ	EmptyLiner   )r   r   r   r&   r   r   r   r   1   s   z$GatherCommentsVisitor.handle_comment)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   ÚMETADATA_DEPENDENCIESr   Ústrr   r(   r)   Úboolr   ÚTrailingWhitespacer    r   r   Ú__classcell__r   r   r   r   r      s    	ÿþr   )r   Útypingr   r   r   Úlibcstr(   Úlibcst.codemod._contextr   Úlibcst.codemod._visitorr   Úlibcst.metadatar   r   r   r   r   r   Ú<module>   s   