Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support for blank lines & comments #334

Open
dmctavish opened this issue Nov 6, 2021 · 1 comment
Open

support for blank lines & comments #334

dmctavish opened this issue Nov 6, 2021 · 1 comment

Comments

@dmctavish
Copy link

Hi
I was hoping it wouldn't be too much of a hassle to add support for blank lines as well as comment lines?

@dmctavish
Copy link
Author

A couple of questions hopefully for @terryyin

I started tinkering, and thought I could model this after the bool extension, but I wanted confirmation that "comment" tokens aren't skipped over.
my theory is: if I use the reader.get_comment_from_token() I can determine if we are in a "comment", and if so, increment the counter

One thing I'm also noting is that the Python language does not have support for multi-line comments within triple quotes - I'll raise that separately

'''
This is an extension of lizard, that counts the number of comment lines
'''

class LizardExtension(): # pylint: disable=R0903

FUNCTION_INFO = {"comment_count": {"caption": " comments "}}

def __call__(self, tokens, reader):
    if not hasattr(reader.context.current_function, "comment_count"):
        reader.context.current_function.comment_count = 0

    for token in tokens:
        comment = reader.get_comment_from_token(token)
        if comment is not None:
            reader.context.current_function.comment_count += 1
        yield token

def cross_file_process(self, fileinfos):
    '''
    Combine the statistics from each file.
    '''
    for fileinfo in fileinfos:
        if hasattr(fileinfo, "comment_count"):
            self.total_comments += fileinfo.comment_count
        yield fileinfo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant