vuejs / eslint-plugin-vue

Official ESLint plugin for Vue.js
https://eslint.vuejs.org/
MIT License
4.47k stars 666 forks source link

`vue/func-call-spacing` schema invalid #2618

Open FloEdelmann opened 4 days ago

FloEdelmann commented 4 days ago

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 commented 4 days ago

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 ```js 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 commented 3 days ago

Hmm, but their test cases also pass only one option: https://github.com/eslint-stylistic/eslint-stylistic/blob/main/packages/eslint-plugin/rules/function-call-spacing/function-call-spacing._js_.test.ts

waynzh commented 3 days ago

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 commented 3 days ago

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 commented 3 days ago

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.