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

Fix crash in case of empty file in directory #217

Merged
merged 1 commit into from
Aug 8, 2022
Merged

Fix crash in case of empty file in directory #217

merged 1 commit into from
Aug 8, 2022

Conversation

mutt0-ds
Copy link

I have added a simple check for the issue #214, that skips the regex check SKIP_PATTERN when there are no lines to analyze.

I think that the fact that there is an empty file in the directory should be flagged as en error, but i would like to hear your opinion first before working on it.

Thanks for your work :)

@@ -181,8 +181,10 @@ def push(self, filtrate: bool = True, **params):
err = Error(filename=self.filename, **params)
number = err.number

if SKIP_PATTERN(self.lines[err.lnum - 1]):
return None
if bool(len(self.lines)):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about

if (err.lnum - 1 not in range(len(self.lines)) or                       
        SKIP_PATTERN(self.lines[err.lnum - 1])):                        
    return None

here?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about that but with this code pylama doesn't raise the D100 issue when executed with an empty file like mentioned in the example, there must be two if blocks
errors.py:1:1 D100 Missing docstring in public module [pydocstyle]

One alternative could be

if err.lnum - 1 in range(len(self.lines):
    if SKIP_PATTERN(self.lines[err.lnum - 1]):                        
        return None

@klen klen merged commit e795dd0 into klen:develop Aug 8, 2022
@klen
Copy link
Owner

klen commented Aug 8, 2022

@mutt0-ds Thank you!

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

Successfully merging this pull request may close these issues.

3 participants