microsoft / pyright

Static Type Checker for Python
Other
13.13k stars 1.4k forks source link

inconsistent JSON formatting #2634

Closed Josverl closed 2 years ago

Josverl commented 2 years ago

Describe the bug Inconsistent JSON formatting for different types of errors makes it hard(er) to use the json output of pyright. specifically errors of type "message": "Non-default argument follows default argument", do not specify a rule node .

To Reproduce Steps to reproduce the behavior.

Expected behavior Expect the JSON report to have consistent schema and specify a rule of each reported error/warning. Expected 5 properties for each node in generalDiagnostics:

Actual Some of the reported errors do not include a rule. ( see below last reported error )

{
    "version": "1.1.190",
    "time": "1638216835976",
    "generalDiagnostics": [
//...
        {
            "file": "C:\\develop\\MyPython\\micropython-stubber\\all-stubs\\micropython-v1_17-Latest-docstubs\\pyb.py",
            "severity": "error",
            "message": "\"hid_mouse\" is unbound",
            "range": {
                "start": {
                    "line": 2279,
                    "character": 8
                },
                "end": {
                    "line": 2279,
                    "character": 17
                }
            },
            "rule": "reportUnboundVariable"
        },
        {
            "file": "C:\\develop\\MyPython\\micropython-stubber\\all-stubs\\micropython-v1_17-Latest-docstubs\\pyb.pyi",
            "severity": "error",
            "message": "Non-default argument follows default argument",
            "range": {
                "start": {
                    "line": 172,
                    "character": 46
                },
                "end": {
                    "line": 172,
                    "character": 55
                }
            }
        }
    ],
    "summary": {
        "filesAnalyzed": 17,
        "errorCount": 7,
        "warningCount": 7,
        "informationCount": 0,
        "timeInSec": 0.527
    }
}

Screenshots or Code

Inspected code files and configuration are located in this GIST

VS Code extension or command-line pyright is run from the commandline.

pyright --project .\tests\pyrightconfig.json --outputjson all-stubs\micropython-v1_17-Latest-docstubs\pyb.*  

Additional context

pyright is installed using python pip : https://pypi.org/project/pyright/

also note that in this case also the number of files inspected (filesAnalyzed) appears to be incorrect, as only 2 files were inspected image

    "summary": {
        "filesAnalyzed": 17,
        "errorCount": 7,
        "warningCount": 7,
        "informationCount": 0,
        "timeInSec": 0.555
    }
erictraut commented 2 years ago

Not all diagnostics have an associated diagnostic rule. For example, parse errors are emitted unconditionally and have no associated rule. Diagnostic rules are used only for diagnostics that can be disabled or enabled.

If a rule is associated with the diagnostic, it is included in the output. If it's not, the rule field is omitted from the JSON output. This is how it is designed to work. If you are consuming this output, your code should be prepared to handle the case where there is no rule.

Please refer to this documentation that documents the JSON schema. Note that rule has a question mark after it, indicating that it's not guaranteed to be included in the output.

Josverl commented 2 years ago

Understood, Still; may I suggest adding a few lines of documentation to explain this, as just a ? in a json example does not convey that much information.