Shopify / theme-check

The Ultimate Shopify Theme Linter
Other
337 stars 95 forks source link

How theme-check validates schema? #544

Closed tomaszs closed 2 years ago

tomaszs commented 2 years ago

I have noticed that the extension for VSCode shows errors on schema sometimes. It does not indicate where the error occurs, what makes it hard to debug.

I wanted to check with other JSON validator online, but all validators I check tell the schema is valid JSON.

Are there any specific settings of the validator above JSON standard?

charlespwd commented 2 years ago

I believe that you would have a longer explanation if you run theme-check from the command line instead of from the editor. Might be wrong.

It really is nothing more than JSON.parse(...). So probably a trailing comma or one of the tags with a duplicate brace e.g. {% schema %}} or {{% endschema %}.

tomaszs commented 2 years ago

I don't call it from command line. The extension calls it and shows an error.

Currently, it looks like this:

image

The issue is here that theme-check does not seem to indicate:

a) what is the problem with the schema b) in what place

I have checked the schema several times and nothing seems to stand out.

I have noticed one thing so far, theme-check expects arrays to be written like this:

"presets": [

]

And not like this:

"presets": [

]

A talented eye can notice the difference is that in second example there are spaces in the seemingly empty line.

It gave a JSON error from theme-check, but still, after adjusting it, the error mentioned on the screenshot occurs.

That is the reason for my question above, how JSON is validated. It seems like the validation goes beyond a regular JSON formatting rules. Since all validators indicate the schema is correct

charlespwd commented 2 years ago

Oh. In this case, it's a formatting issue. You should be able to click on the quickfix icon to fix it.

https://user-images.githubusercontent.com/4990691/152213802-0fab41ce-64c4-4b27-9c9e-9b9b42a91ce5.mp4

charlespwd commented 2 years ago

Agreed the messaging could be improved though. The error is at the top of the schema since we don't have a great way of highlighting all the formatting errors in a sane manner.

If you dislike this rule, you can turn it off with this in your .theme-check.yml file:

SchemaJsonFormat:
  enabled: false

See the documentation for the check for more details:

https://github.com/Shopify/theme-check/blob/main/docs/checks/schema_json_format.md

tomaszs commented 2 years ago

Thanks for info,

I have created a PR to update theme-check-vscode extension to mention that feature:

https://github.com/Shopify/theme-check-vscode/pull/64

It works pretty nicely