stylelint / stylelint-demo

The online demo on the Stylelint website
https://stylelint.io/demo/
MIT License
15 stars 8 forks source link

Add JSON Schema support for `.stylelintrc.json` #425

Closed ybiquitous closed 2 months ago

ybiquitous commented 2 months ago

Which issue, if any, is this issue related to?

None.

Is there anything in the PR that needs further explanation?

The 3rd-party JSON schema provides auto-completion, validation, etc. https://json.schemastore.org/stylelintrc

Screenshot 2024-09-13 at 1 38 10 image

See also the Monaco Editor Playground.


FYI, @Mouvedia has recently improved the schema with https://github.com/SchemaStore/schemastore/pull/4057. I appreciate that work. πŸ‘πŸΌ

netlify[bot] commented 2 months ago

Deploy Preview for chimerical-trifle-8d3c21 ready!

Name Link
Latest commit f808a7aba5d321620af9299b7533dfc3073691d9
Latest deploy log https://app.netlify.com/sites/chimerical-trifle-8d3c21/deploys/66e8e485dd50b60008e4d3d6
Deploy Preview https://deploy-preview-425--chimerical-trifle-8d3c21.netlify.app
Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Mouvedia commented 2 months ago

Wait.

I have got a better one. Ill link it here tomorrow.

Mouvedia commented 2 months ago

@ybiquitous https://gist.github.com/Mouvedia/f7459c8d94c9a219f9e32af50b080c96

I didn't put the id's value because it will be the url of where you will decide to store it. Good luck reviewing it!

ybiquitous commented 2 months ago

I may not understand well yet. What do you mean with your gist version? Replace?

Mouvedia commented 2 months ago

The one linked on schemastore.org has deprecated rules and has been originally generated by someone else. The one that I have provided is generated from the code itself, is using the last draft of JSON Schema and doesn't have group indirections. i.e. it is stricter, simpler and use 2020-12 JSON Schema e.g.

As explained in this comment, we shouldn't share the same schema.

Replace?

Save it somewhere.

e.g.

                schemas: [
                    {
                        uri: 'https://stylelint.io/path/to/',
                        fileMatch: ['stylelint.schema.json'],
                    },
                ],
ybiquitous commented 2 months ago

Got it. Thanks for the help ☺️ I'll save your gist version in this repo and read it in the setup code.

Mouvedia commented 2 months ago

Got it. Thanks for the help ☺️

πŸ‘

You might get stuck on microsoft/monaco-editor#3160. If that happens you will have to convert it to a previous draft. It shouldn't be hard.

I'll save your gist version in this repo and read it in the setup code.

Remember to set the id.

ybiquitous commented 2 months ago

@Mouvedia Thank you. I pushed 036674f to use your schema. Can you take a look when you have time?

You might get stuck on https://github.com/microsoft/monaco-editor/issues/3160.

I didn't come across the issue, but I may miss it. If something wrong happens, please let me know.

Mouvedia commented 2 months ago

I didn't come across the issue, but I may miss it.

If the main goal is auto-completion, it's fine.

The issue states that you might have no errors when you add additional properties. i.e. "unevaluatedProperties": false It was added in 2019-09 draft. e.g. if someone use deprecated rules It's not a big deal.

Can you take a look when you have time?

To tell you the truth, I don't want to review a 6000 lines file. Most of the file is autogenerated by a script so that I don't have to review it. I had to make some corrections in revision 1. The other revisions after that are just refactors to slim the json file a bit. i.e. removing repetition using $defs

ybiquitous commented 2 months ago

Ah, you don't need to review your gist file in this PR! I want you to confirm your file is imported expectedly in this PR. πŸ˜„

E.g., the following way:

$ curl https://gist.githubusercontent.com/Mouvedia/f7459c8d94c9a219f9e32af50b080c96/raw/1c09516f3b8abee77b1a25aed1fdee9efec3a6d2/stylelint.schema.json > src/schema/stylelintrc.json

$ npm run format

$ git diff

should produce:

diff --git a/src/schema/stylelintrc.json b/src/schema/stylelintrc.json
index f860a85..8eb87dd 100644
--- a/src/schema/stylelintrc.json
+++ b/src/schema/stylelintrc.json
@@ -1,6 +1,6 @@
 {
    "$schema": "https://json-schema.org/draft/2020-12/schema",
-   "$id": "https://stylelint.io/schema/stylelintrc.json",
+   "$id": "",
    "$defs": {
        "arrayOfString": {
            "type": "array",
Mouvedia commented 2 months ago
-       "$id": "https://stylelint.io/schema/stylelintrc.json",
+       "$id": "",

πŸ‘

Mouvedia commented 2 months ago

I found a bug but we can fix it in a separate PR. It's not important because users shan't use files in the playground.

try

{
  "rules": {},
  "overrides": [
    {
      "files": ["foo"]
    }
  ]
}

It's probably related to https://github.com/microsoft/monaco-editor/issues/3160. i.e. properties doesn't extend $ref

I think a simple "allOf": [] should do the trick. i.e. something like

"overrides": {
    "type": "array",
    "items": {
        "allOf": [
            {
                "$ref": "#",
            },
            {
                "properties": {
                    "files": {
                        "$ref": "#/$defs/arrayOfString"
                    }
                },
            },
        ],
        "not": {
            "required": [
                "overrides"
            ]
        },
        "unevaluatedProperties": false
    }
},
ybiquitous commented 2 months ago

Great. Fixed with f808a7a as you suggested. Can you take a look?

Mouvedia commented 2 months ago

Can you take a look?

Fixed it.

Mouvedia commented 2 months ago

We can add the deprecated rules later if we feel like it. Or we could version the json files so that it can be switched depending on the version of stylelint used in the dependencies tab.

This is great as is.

ybiquitous commented 2 months ago

@Mouvedia Thanks a lot for your support! πŸ˜„

@jeddy3 Do you have any concerns about this feature? I welcome your feedback. I'm not in a hurry to merge.