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

Incorrect reported line #73

Closed
sobolevn opened this issue Aug 13, 2019 · 4 comments
Closed

Incorrect reported line #73

sobolevn opened this issue Aug 13, 2019 · 4 comments
Labels
bug Something isn't working released Feature/fix is released

Comments

@sobolevn
Copy link

Expected Behavior

» flake8 .

./tests/test_version.py

  0:1      NIP001 File mypy.toml has an incorrect style. Invalid TOML:
TomlDecodeError: This float doesn't have a leading digit (line 2 column 1 char 19)

Current Behavior

» flake8 .

./tests/test_version.py

  1:1      NIP001 File mypy.toml has an incorrect style. Invalid TOML:
TomlDecodeError: This float doesn't have a leading digit (line 2 column 1 char 19)
  # -*- coding: utf-8 -*-
  ^

When you report violations on line 0 they are not bound to any source line.
When you report violation on line 1 they are bound to the first line and since this moment --show-source works incorrectly and report this part:

# -*- coding: utf-8 -*-
  ^

(This is my first line from ./tests/test_version.py)

I would also like to highlight that ./tests/test_version.py does not hav anything to do with the reported violation. It might create some interesting situations.

I know that flake8 has quite a strange violation reporting API, but can we consider reporting this violation on files like nitpick-style.toml or similar?

@sobolevn sobolevn added the bug Something isn't working label Aug 13, 2019
@andreoliwa
Copy link
Owner

When you report violations on line 0 they are not bound to any source line.

I believe Nitpick is reporting the correct line.
I forced an error on some TOML, and then ran those commands below.
Notice the line_number=1 on the Violation.

11:45 $ git diff
diff --git a/styles/mypy.toml b/styles/mypy.toml
index 8b7753f..f928725 100644
--- a/styles/mypy.toml
+++ b/styles/mypy.toml
@@ -1,5 +1,5 @@
 ["setup.cfg".mypy]
-check_untyped_defs = true
+check_untyped_defs = True
 ignore_errors = false
 ignore_missing_imports = true
 strict_optional = true~/Desktop/wemake-python-styleguide [master|✚ 1]
11:45 $ flake8 -vvv ./tests/test_version.py 2>&1 | grep -i nip001
flake8.style_guide        MainProcess    422 DEBUG    Deciding if "NIP001" should be reported
flake8.style_guide        MainProcess    422 DEBUG    The user configured "NIP001" to be "Ignored.Implicitly", "Selected.Implicitly"
flake8.style_guide        MainProcess    422 DEBUG    "NIP001" will be "Decision.Selected"
flake8.style_guide        MainProcess    422 DEBUG    Violation(code='NIP001', filename='./tests/test_version.py', line_number=1, column_number=1, text="File mypy.toml has an incorrect style. Invalid TOML:\x1b[92m\nTomlDecodeError: This float doesn't have a leading digit (line 2 column 1 char 19)\x1b[0m", physical_line='# -*- coding: utf-8 -*-\n') is not inline ignored

I don't know what might be happening here.
I would guess that some plugin is interfering with that output.
I added some invalid TOML on this project to test it.
Notice ./setup.py:1:1 below:

11:57 $ git diff nitpick-style.toml
diff --git a/nitpick-style.toml b/nitpick-style.toml
index 11b2f8a..0a2643d 100644
--- a/nitpick-style.toml
+++ b/nitpick-style.toml
@@ -3,6 +3,7 @@

 [nitpick]
 minimum_version = "0.10.0"
+invalid_toml = True

 [nitpick.styles]
 include = [
(nitpick) ✔ ~/Code/nitpick [develop|✚ 6…1]
11:59 $ flake8
./setup.py:1:1: NIP001 File nitpick-style.toml has an incorrect style. Invalid TOML:
TomlDecodeError: This float doesn't have a leading digit (line 6 column 1 char 153)

I would also like to highlight that ./tests/test_version.py does not hav anything to do with the reported violation. It might create some interesting situations.
I know that flake8 has quite a strange violation reporting API, but can we consider reporting this violation on files like nitpick-style.toml or similar?

Yeah, it's weird, I know.
Back when I started this project, I couldn't find a way to make flake8 run on non-Python files.
By default, flake8 or flake8 . will only run on *.py files.

When you explicitly run flake8 on the project files, it reports filename and lines.
But it also parses them as Python files, and then we get this result below.
Also Nitpick errors are currently not shown, because they are all reported on the first Python file found on the project, and not on the file itself.

$ flake8 --filename='*setup.cfg,*pyproject.toml'
./pyproject.toml:6:5: E226 missing whitespace around arithmetic operator
./pyproject.toml:27:39: E999 SyntaxError: invalid syntax
./pyproject.toml:38:7: E226 missing whitespace around arithmetic operator
./pyproject.toml:44:46: E226 missing whitespace around arithmetic operator
./pyproject.toml:47:12: E226 missing whitespace around arithmetic operator
./pyproject.toml:49:17: E226 missing whitespace around arithmetic operator
./pyproject.toml:53:7: E226 missing whitespace around arithmetic operator
./pyproject.toml:54:7: E226 missing whitespace around arithmetic operator
./pyproject.toml:61:7: E226 missing whitespace around arithmetic operator
./pyproject.toml:63:6: E226 missing whitespace around arithmetic operator
./setup.cfg:2:24: E999 SyntaxError: invalid syntax
./setup.cfg:6:22: E226 missing whitespace around arithmetic operator
./setup.cfg:6:30: E226 missing whitespace around arithmetic operator
./setup.cfg:18:23: E226 missing whitespace around arithmetic operator
./setup.cfg:22:26: E226 missing whitespace around arithmetic operator
./setup.cfg:35:14: E231 missing whitespace after ','
./setup.cfg:35:19: E231 missing whitespace after ','
./setup.cfg:35:24: E231 missing whitespace after ','
./setup.cfg:35:29: E231 missing whitespace after ','
./setup.cfg:35:34: E231 missing whitespace after ','
./setup.cfg:35:39: E231 missing whitespace after ','
./setup.cfg:35:44: E231 missing whitespace after ','
./setup.cfg:36:4: E226 missing whitespace around arithmetic operator
./setup.cfg:36:9: E226 missing whitespace around arithmetic operator
./setup.cfg:37:15: E231 missing whitespace after ','
./setup.cfg:37:20: E231 missing whitespace after ','
./setup.cfg:38:4: E226 missing whitespace around arithmetic operator
./setup.cfg:39:7: E226 missing whitespace around arithmetic operator
./setup.cfg:43:12: E231 missing whitespace after ','
./setup.cfg:43:17: E231 missing whitespace after ','
./setup.cfg:48:26: E231 missing whitespace after ','
./setup.cfg:49:28: E231 missing whitespace after ','
./setup.cfg:49:33: E231 missing whitespace after ','
./setup.cfg:49:39: E231 missing whitespace after ','
./setup.cfg:49:50: E231 missing whitespace after ','
./setup.cfg:49:59: E231 missing whitespace after ','
./setup.cfg:49:71: E231 missing whitespace after ','
./setup.cfg:49:93: E231 missing whitespace after ','
./setup.cfg:49:100: E231 missing whitespace after ','
./setup.cfg:49:109: E231 missing whitespace after ','
./setup.cfg:49:119: E231 missing whitespace after ','
./setup.cfg:49:126: E231 missing whitespace after ','
./setup.cfg:49:134: E231 missing whitespace after ','
./setup.cfg:49:151: E231 missing whitespace after ','
./setup.cfg:49:164: E231 missing whitespace after ','
./setup.cfg:60:15: E225 missing whitespace around operator
./setup.cfg:60:23: E226 missing whitespace around arithmetic operator

12:02 $ flake8 setup.cfg pyproject.toml
setup.cfg:2:24: E999 SyntaxError: invalid syntax
setup.cfg:6:22: E226 missing whitespace around arithmetic operator
setup.cfg:6:30: E226 missing whitespace around arithmetic operator
setup.cfg:18:23: E226 missing whitespace around arithmetic operator
setup.cfg:22:26: E226 missing whitespace around arithmetic operator
setup.cfg:35:14: E231 missing whitespace after ','
setup.cfg:35:19: E231 missing whitespace after ','
setup.cfg:35:24: E231 missing whitespace after ','
setup.cfg:35:29: E231 missing whitespace after ','
setup.cfg:35:34: E231 missing whitespace after ','
setup.cfg:35:39: E231 missing whitespace after ','
setup.cfg:35:44: E231 missing whitespace after ','
setup.cfg:36:4: E226 missing whitespace around arithmetic operator
setup.cfg:36:9: E226 missing whitespace around arithmetic operator
setup.cfg:37:15: E231 missing whitespace after ','
setup.cfg:37:20: E231 missing whitespace after ','
setup.cfg:38:4: E226 missing whitespace around arithmetic operator
setup.cfg:39:7: E226 missing whitespace around arithmetic operator
setup.cfg:43:12: E231 missing whitespace after ','
setup.cfg:43:17: E231 missing whitespace after ','
setup.cfg:48:26: E231 missing whitespace after ','
setup.cfg:49:28: E231 missing whitespace after ','
setup.cfg:49:33: E231 missing whitespace after ','
setup.cfg:49:39: E231 missing whitespace after ','
setup.cfg:49:50: E231 missing whitespace after ','
setup.cfg:49:59: E231 missing whitespace after ','
setup.cfg:49:71: E231 missing whitespace after ','
setup.cfg:49:93: E231 missing whitespace after ','
setup.cfg:49:100: E231 missing whitespace after ','
setup.cfg:49:109: E231 missing whitespace after ','
setup.cfg:49:119: E231 missing whitespace after ','
setup.cfg:49:126: E231 missing whitespace after ','
setup.cfg:49:134: E231 missing whitespace after ','
setup.cfg:49:151: E231 missing whitespace after ','
setup.cfg:49:164: E231 missing whitespace after ','
setup.cfg:60:15: E225 missing whitespace around operator
setup.cfg:60:23: E226 missing whitespace around arithmetic operator
pyproject.toml:6:5: E226 missing whitespace around arithmetic operator
pyproject.toml:27:39: E999 SyntaxError: invalid syntax
pyproject.toml:38:7: E226 missing whitespace around arithmetic operator
pyproject.toml:44:46: E226 missing whitespace around arithmetic operator
pyproject.toml:47:12: E226 missing whitespace around arithmetic operator
pyproject.toml:49:17: E226 missing whitespace around arithmetic operator
pyproject.toml:53:7: E226 missing whitespace around arithmetic operator
pyproject.toml:54:7: E226 missing whitespace around arithmetic operator
pyproject.toml:61:7: E226 missing whitespace around arithmetic operator
pyproject.toml:63:6: E226 missing whitespace around arithmetic operator

I could try to change this default and automatically use the --filename flake8 option somehow.
Just running flake8 must be enough.
I don't want to make developers explicit write the file names when running flake8 (like flake8 setup.cfg pyproject.toml).


Another solution I once thought is running Nitpick as a standalone CLI command, without the need for flake8 to be installed.
It would output something like this:

12:10 $ nitpick run
./setup.cfg:1:1: NIP324 Section [isort] has some missing key/value pairs. Use this:
[isort]
include_trailing_comma = True
multi_line_output = 3
skip = .tox,build
./pyproject.toml:1:1: NIP319 Different values. Use this:
[tool.black]
line-length = 120

But then the flake8 reporting tools could not be used, nor any of the plugins.


I still don't have a solution for all of this, I will think about it.
If you have any suggestion, let me know.

@sobolevn
Copy link
Author

@andreoliwa sorry, my intention was not clear: I suggest to report violations on line 0, not 1 as it is reported now.

@andreoliwa
Copy link
Owner

@sobolevn My bad, I was sleepy.
Reading it again now, I see the "expected" and "current" behaviours in the description.

andreoliwa pushed a commit that referenced this issue Aug 13, 2019
# [0.20.0](v0.19.0...v0.20.0) (2019-08-13)

### Bug Fixes

* report errors on line 0 instead of 1 ([31b13ea](31b13ea)), closes [#73](#73)

### Features

* add config to check files that should be present ([408440f](408440f)), closes [#74](#74)
@andreoliwa
Copy link
Owner

🎉 This issue has been resolved in version 0.20.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working released Feature/fix is released
Projects
None yet
Development

No branches or pull requests

2 participants