Search code examples
eslinttypescript-eslinteslint-rule-schema

How do I specify eslint rule schema with array of objects


Trying to set a schema for my eslint rule. The intended configuration is as follows:

'my-rule': ['error', [
  {'any-key': ['array', 'of', 'strings']},
  {'some-other-key': ['array', 'of', 'strings']},
  ...etc
]]

I found out that it is possible to allow any non-enum property names, but I'm not sure how to specify their value types:

    schema: [
        {
            type: 'array',
            items: {
                type: 'object',
                propertyNames: {
                    type: 'string',
                    // ??? - how do I specify array of strings here?
                },
            }
        }
    ],

Is this possible at all?


Solution

  • I don't think you can use propertyNames to specify the value types.

    Wouldn't patternProperties work better for your purpose?

    schema: [
        {
            type: 'array',
            items: {
                type: 'object',
                patternProperties: {
                    ".": {
                        type: "array",
                        items: {type: "string"}
                    }
                },
            }
        }
    ]