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

Invalid line number for reporting diagnostics at first line #821

Open
dhruvmanila opened this issue May 21, 2023 · 2 comments
Open

Invalid line number for reporting diagnostics at first line #821

dhruvmanila opened this issue May 21, 2023 · 2 comments
Labels
bug Something isn't working

Comments

@dhruvmanila
Copy link

Jupyter notebook content

import math
import random

Cell count: 1

Command

$ nbqa --nbqa-shell ruff /path/to/notebook.ipynb --select=ALL

OR

$ nbqa --nbqa-shell flake8 /path/to/notebook.ipynb

Output

Note: Output is truncated to only keep the relevant lines

Ruff:

...
/Users/dhruv/playground/python/ruff_test.ipynb:cell_1:0:1: D100 Missing docstring in public module
/Users/dhruv/playground/python/ruff_test.ipynb:cell_1:2:8: F401 [*] `random` imported but unused
...

Flake8:

/Users/dhruv/playground/python/ruff_test.ipynb:cell_1:0:1: D100 Missing docstring in public module
/Users/dhruv/playground/python/ruff_test.ipynb:cell_1:2:1: F401 'random' imported but unused

Notice that D100 is reported at line 0 while F401 is reported at line 2. The former suggests that it's 0-indexed while the latter suggests it's 1-indexed. This is happening because of the CODE_SEPARATOR inserted between each code cells:

# %%NBQA-CELL-SEP8e47a4
import math
import random

  • Ruff version: 0.0.269
  • nbqa version: 1.7.0
  • flake8 --version:
     6.0.0 (flake8-bugbear: 23.5.9, flake8-docstrings: 1.7.0, flake8-pyi: 23.5.0, flake8_implicit_str_concat: 0.4.0, mccabe: 0.7.0, pycodestyle: 2.10.0, pyflakes: 3.0.1) CPython 3.11.3 on Darwin
    
@MarcoGorelli
Copy link
Collaborator

thanks for the report - could you show what happens when you run these tools on a Python script with the same content (no nbqa involved)?

@dhruvmanila
Copy link
Author

Sure!

$ ruff check --select=ALL t.py                  
t.py:1:1: D100 Missing docstring in public module
t.py:1:8: F401 [*] `math` imported but unused
t.py:2:8: F401 [*] `random` imported but unused
Found 3 errors.
[*] 2 potentially fixable with the --fix option.

$ flake8 t.py       
t.py:1:1: D100 Missing docstring in public module
t.py:1:1: F401 'math' imported but unused
t.py:2:1: F401 'random' imported but unused

@MarcoGorelli MarcoGorelli added bug Something isn't working and removed needs info labels May 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants