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

vue/func-call-spacing schema invalid #2618

Open
FloEdelmann opened this issue Nov 20, 2024 · 5 comments
Open

vue/func-call-spacing schema invalid #2618

FloEdelmann opened this issue Nov 20, 2024 · 5 comments
Labels

Comments

@FloEdelmann
Copy link
Member

Yesterday, tests in all PRs started to fail for the vue/func-call-spacing extension rule, e.g. here: https://github.com/vuejs/eslint-plugin-vue/actions/runs/11925499375/job/33237692823?pr=2611

Error: Schema for rule func-call-spacing is invalid: default is ignored for: data1.allowNewlines

It is likely related to changes in eslint-stylistic v2.11.0, since with @stylistic/eslint-plugin v2.10.1, the tests still pass.
Relevant changes: eslint-stylistic/eslint-stylistic@v2.10.1...v2.11.0#diff-b89bec3716

Unfortunately, I can't figure out how those changes influence our extension rule and tests, so @ota-meshi (or anyone else), could you please have a look at that?

@waynzh
Copy link
Member

waynzh commented Nov 20, 2024

It might just be a schema configuration bug that needs to be fixed upstream.
The error occurs when ajv compiles the schema, and the message indicates that the default is ignored, which is correct, as we can just configure one item ["never"]?

more info
    it.only("throw invalid defaults in rules", () => {
        const ruleWithInvalidDefaults = {
            meta: {
                schema: {
                    anyOf: [
                      {
                        type: "array",
                        items: [
                          {
                            type: "string",
                            enum: ["never"]
                          }
                        ],
                        minItems: 0,
                        maxItems: 1
                      },
                      {
                        type: "array",
                        items: [
                          {
                            type: "string",
                            enum: ["always"]
                          },
                          {
                            type: "object",
                            properties: {
                              allowNewlines: {
                                type: "boolean",
                                default: false
                              },
                              optionalChain: {
                                type: "object",
                                properties: {
                                  before: {
                                    type: "boolean",
                                    default: true
                                  },
                                  after: {
                                    type: "boolean",
                                    default: true
                                  }
                                },
                                additionalProperties: false
                              }
                            },
                            additionalProperties: false
                          }
                        ],
                        minItems: 0,
                        maxItems: 2
                      }
                    ]
                  },
            },
            create: () => ({})
        };

        assert.throws(() => {
            ruleTester.run("invalid-defaults", ruleWithInvalidDefaults, {
                valid: [
                    {
                        code: "foo",
                        options: [{}]
                    }
                ],
                invalid: []
            });
        }, /Schema for rule invalid-defaults is invalid: default is ignored for: data1\.allowNewlines/u);
    });

@FloEdelmann
Copy link
Member Author

@waynzh
Copy link
Member

waynzh commented Nov 21, 2024

I haven't compared them in detail, but seems like eslint-stylistic uses eslint-vitest-rule-tester. I'm not sure if it has a pre-check for the schema like eslint.RuleTester does internally.

@FloEdelmann
Copy link
Member Author

default inside anyOf is indeed actually invalid: https://ajv.js.org/guide/modifying-data.html#assigning-defaults

With useDefaults option default keywords throws exception during schema compilation when used in:

  • not in properties or items subschemas
  • in schemas inside anyOf, oneOf and not (see #42)
  • in if schema
  • in schemas generated by user-defined macro keywords

So I'll report this to eslint-stylistic. Thanks for your help investigating!

@FloEdelmann
Copy link
Member Author

I've opened an issue and a PR in eslint-stylistic:

I'll leave this issue open until a fixed version of eslint-stylistic is released.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants