mbarkhau / pylint-ignore

MIT License
14 stars 8 forks source link

Trailing whitespace in otherwise empty lines can't be ignored #4

Closed agraul closed 3 years ago

agraul commented 3 years ago

First of all, thank you for this project. I gave it a quick test yesterday and really like the improvement over stock pylint. Having used rupocop in the past, this is a feature I am really missing from pylint. We want to (re-)introduce pylint to our code base and pylint-ignore will be of great help.

The issue I have is that, after running pylint-ignore --update-ignorefile, pylint-ignore still reports "Trailing whitespace" messages. I tracked it down to lines that are empty except for whitespace and also took a look at the code, but didn't yet find a way to fix it myself.

This is a minimal reproducer: Content of ~/tmp/pylint-ignore-repro/repro.py (note the whitespace in the empty line):

def repro():

    return None

Initial pylint-ignore execution:

~/tmp/pylint-ignore-repro  
$ pylint-ignore repro.py
************* Module repro
repro.py:4:0: C0303: Trailing whitespace (trailing-whitespace)
repro.py:1:0: C0114: Missing module docstring (missing-module-docstring)
repro.py:3:0: C0116: Missing function or method docstring (missing-function-docstring)

------------------------------------
Your code has been rated at -5.00/10

Updating pylint-ignore.md:

~/tmp/pylint-ignore-repro  
$ pylint-ignore repro.py --update-ignorefile

---------------------------------------------------------------------
Your code has been rated at 10.00/10 (previous run: -5.00/10, +15.00)

Running pylint-ignore again:

~/tmp/pylint-ignore-repro  
$ pylint-ignore repro.py                    
************* Module repro
repro.py:4:0: C0303: Trailing whitespace (trailing-whitespace)

-------------------------------------------------------------------
Your code has been rated at 5.00/10 (previous run: 10.00/10, -5.00)

I put the resulting pylint-ignore.md in the Details drawer below because it's pretty large. I can also attach it in another format if needed. The "suprising" thing is that the EntryHeader has no line number. When I manually added the line number (but nothing else!), the message got ignored as expected.

~/tmp/pylint-ignore-repro $ cat pylint-ignore.md # Pylint-Ignore **WARNING: This file is programatically generated.** This file is parsed by [`pylint-ignore`](https://pypi.org/project/pylint-ignore/) to determine which [Pylint messages](https://pylint.pycqa.org/en/stable/technical_reference/features.html) should be ignored. - Do not edit this file manually. - To update, use `pylint-ignore --update-ignorefile` The recommended approach to using `pylint-ignore` is: 1. If a message refers to a valid issue, update your code rather than ignoring the message. 2. If a message should *always* be ignored (globally), then to do so via the usual `pylintrc` or `setup.cfg` files rather than this `pylint-ignore.md` file. 3. If a message is a false positive, add a comment of this form to your code: `# pylint:disable= ; explain why this is a false positive` # Overview - [C0114: missing-module-docstring (1x)](#c0114-missing-module-docstring) - [C0116: missing-function-docstring (1x)](#c0116-missing-function-docstring) - [C0303: trailing-whitespace (1x)](#c0303-trailing-whitespace) # C0114: missing-module-docstring ## File repro.py - C0114 (missing-module-docstring) - `message: Missing module docstring` - `author : Alexander Graul ` - `date : 2021-06-24T15:21:44` # C0116: missing-function-docstring ## File repro.py - Line 3 - C0116 (missing-function-docstring) - `message: Missing function or method docstring` - `author : Alexander Graul ` - `date : 2021-06-24T15:21:44` ``` 1: #!/usr/bin/python3 2: > 3: def repro(): 4: 5: return None ``` # C0303: trailing-whitespace ## File repro.py - C0303 (trailing-whitespace) - `message: Trailing whitespace` - `author : Alexander Graul ` - `date : 2021-06-24T15:21:44`

Versions in my virtual environment:

~/tmp/pylint-ignore-repro  
$ python --version            
Python 3.9.5

~/tmp/pylint-ignore-repro  
$ pip list                    
Package           Version
----------------- ---------
astroid           2.5.6
isort             5.9.1
lazy-object-proxy 1.6.0
mccabe            0.6.1
pathlib2          2.3.5
pip               21.1.2
pylev             1.4.0
pylint            2.8.3
pylint-ignore     2021.1018
setuptools        56.0.0
six               1.16.0
toml              0.10.2
wrapt             1.12.1

If you have any pointers I could give fixing this another try. If you need anything else, I'm happy to hand over any information that helps you.

mbarkhau commented 3 years ago

It appears I live a sheltered life, working on projects where people use "trim_trailing_white_space_on_save": true,.

agraul commented 3 years ago

haha, I had to change my editor to write the reproducer, my main one didn't let me preserve the trailing whitespace... Apparently this was not the case for all authors of (at the time) spacewalk.