Skip to content

Expose valid types for eslint rules #2881

Open
@dr3

Description

@dr3

Is your feature request related to a problem? Please describe.

Now that Eslint 9 allows JS configs, you can use type safety around rules

You can currently access types via

import type graphqlPlugin from '@graphql-eslint/eslint-plugin';

type Groups = Partial<typeof graphqlPlugin['configs']>
type GraphQLRules = Partial<NonNullable<Groups[keyof Groups]>['rules']>;

const graphqlRules = {
  '@graphql-eslint/alphabetize': [
    'error',
    {
        selections: ['OperationDefinition']
    },
  ],
} satisfies GraphQLRules;

export default graphqlRules;

However this produces error

Type '{ selections: string[]; }' is missing the following properties from type '{ definitions: boolean; selections: string[]; variables: boolean; arguments: string[]; groups: string[]; }': definitions, variables, arguments, groupsts(2739)

Despite the docs implying that you don't need to set all arguments to the rule

Image

Describe the solution you'd like

Expose GraphQLRules as a export (to avoid the consumer having to dig for it), and correctly type optional fields

Describe alternatives you've considered

Additional context

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions