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

Feature request: add line numbers to the output #359

Open
piotr-kubiak opened this issue Nov 28, 2023 · 3 comments
Open

Feature request: add line numbers to the output #359

piotr-kubiak opened this issue Nov 28, 2023 · 3 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@piotr-kubiak
Copy link

piotr-kubiak commented Nov 28, 2023

Please consider adding line numbers to the output when schema validation errors are detected.
It would be much easier to locate errors when running as a pre-commit hook, especially in big JSON files.

@sirosen sirosen added enhancement New feature or request help wanted Extra attention is needed labels Nov 28, 2023
@sirosen
Copy link
Member

sirosen commented Nov 28, 2023

Although I'd like to offer this, I'm not sure how it would be possible today. We'd need a line number recorded during parsing -- perhaps there's a suitable JSON parser -- and then we'd need to get those line numbers back from the jsonschema library.

There are two research areas here, and we need to be confident that both parts will succeed before trying anything. Help and information about how to preserve this information from the parse and associate it with validation errors would be welcome.

@piotr-kubiak
Copy link
Author

@sirosen
Well, I did some research, and it seems that tools like VS Code are able to show (underline) errors in the JSON file when validating against a schema file, so I assumed that this information is already in the parser.

But event if it is not, clearly it is implemented in yaml-language-server, which claims to be using JSON Schema specification, exactly as the jsonschema library (although different implementation for sure). So maybe the research you are talking about has already been completed, and we need only porting of the same solution?

@sirosen
Copy link
Member

sirosen commented Nov 28, 2023

Neither of those products are implemented in Python, which check-jsonschema is, so the fact that they have such capabilities isn't really topical or useful for this project.

The JSON parser in the Python stdlib doesn't preserve line numbers (and has no extension point for doing so). It is possible to do this with alternative parsers -- but most of them are many times slower, and several of the available implementations are abandonware.

If there is a Python or Rust parser with the right characteristics (correct, fast, currently maintained), I could look into using it. But it's only even worth doing so if the information can be returned from jsonschema on ValidationErrors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants