pylint icon indicating copy to clipboard operation
pylint copied to clipboard

Exporting to JSON does not honor score option

Open Yenthe666 opened this issue 5 years ago • 10 comments

Steps to reproduce

  1. Run pylint on some random Python file or module:
pylint  ~/Desktop/pylint_test.py

As you can see this outputs some warnings/scoring:

************* Module pylint_test
/home/administrator/Desktop/pylint_test.py:1:0: C0111: Missing module docstring (missing-docstring)
/home/administrator/Desktop/pylint_test.py:1:0: W0611: Unused import requests (unused-import)

------------------------------------------------------------------
Your code has been rated at 0.00/10 (previous run: 0.00/10, +0.00)
  1. Now run the same command but with -f json to export it to JSON:
pylint ~/Desktop/pylint_test.py  -f json

The output doesn't contain the scores now anymore:

[
    {
        "type": "convention",
        "module": "pylint_test",
        "obj": "",
        "line": 1,
        "column": 0,
        "path": "/home/administrator/Desktop/pylint_test.py",
        "symbol": "missing-docstring",
        "message": "Missing module docstring",
        "message-id": "C0111"
    },
    {
        "type": "warning",
        "module": "pylint_test",
        "obj": "",
        "line": 1,
        "column": 0,
        "path": "/home/administrator/Desktop/pylint_test.py",
        "symbol": "unused-import",
        "message": "Unused import requests",
        "message-id": "W0611"
    }
]
  1. Now execute it with -f json again but also supply the --score=y option:
[
    {
        "type": "convention",
        "module": "pylint_test",
        "obj": "",
        "line": 1,
        "column": 0,
        "path": "/home/administrator/Desktop/pylint_test.py",
        "symbol": "missing-docstring",
        "message": "Missing module docstring",
        "message-id": "C0111"
    },
    {
        "type": "warning",
        "module": "pylint_test",
        "obj": "",
        "line": 1,
        "column": 0,
        "path": "/home/administrator/Desktop/pylint_test.py",
        "symbol": "unused-import",
        "message": "Unused import requests",
        "message-id": "W0611"
    }
]

Current behavior

The score is not outputted when exporting to JSON, not even when --score=y is activated.

Expected behavior

The score is added to the JSON, at least when --score=y is activated.

pylint --version output

pylint 2.3.0
astroid 2.2.0
Python 3.7.5 (default, Nov 20 2019, 09:21:52) 
[GCC 9.2.1 20191008]

Yenthe666 avatar Apr 21 '20 13:04 Yenthe666

Thank you for the report, I can reproduce this bug.

Pierre-Sassoulas avatar Apr 22 '20 06:04 Pierre-Sassoulas

I have a fix, but I think this has the potential to break countless continuous integration and annoy a lot of persons, so I'm going to wait for a review by someone else before merging.

Pierre-Sassoulas avatar Apr 26 '20 12:04 Pierre-Sassoulas

The fix is not going to be merged before a major version see https://github.com/PyCQA/pylint/pull/3514#issuecomment-619834791

Pierre-Sassoulas avatar Apr 27 '20 09:04 Pierre-Sassoulas

Ahh that's a pity that it won't come in a minor release :( Is there an estimate on when 3.0 more or less lands?

Yenthe666 avatar Apr 28 '20 07:04 Yenthe666

Yeah, sorry about that. I don't think there is a release date for 3.0.0 yet, @PCManticore might want to correct me though.

Pierre-Sassoulas avatar Apr 28 '20 08:04 Pierre-Sassoulas

Shouldn't you have a branch for your next major release so things like this won't bitrot?

doctormo avatar May 31 '20 07:05 doctormo

I created a 3.0.0.alpha branch, where it's fixed. Will close if we release alpha version 3.0.0a0.

Pierre-Sassoulas avatar Mar 07 '21 09:03 Pierre-Sassoulas

Released in 3.0.0a0.

Pierre-Sassoulas avatar Mar 29 '21 20:03 Pierre-Sassoulas

🥳 thanks a lot @Pierre-Sassoulas!

Yenthe666 avatar Mar 30 '21 06:03 Yenthe666

Reopening because the change was reverted in the 3.0 alpha branch. We can also simply add a new reporter for json directly in 2.x branch and deprecate the other json reporter.

Pierre-Sassoulas avatar Jul 04 '22 08:07 Pierre-Sassoulas