Skip to content

Conversation

maciesielka
Copy link
Contributor

Description

Changes here add a ignoredFieldSelectors configuration to the no-unused-fields rule such that some fields are allowed to be unused.

Fixes #2280

Type of change

Please delete options that are not relevant.

  • New feature (non-breaking change which adds functionality)

Checklist:

  • I have followed the
    CONTRIBUTING doc and the
    style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests and linter rules pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

Copy link

changeset-bot bot commented May 3, 2024

🦋 Changeset detected

Latest commit: 0169da2

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@graphql-eslint/eslint-plugin Major

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

type: 'object',
additionalProperties: false,
properties: {
ignoredFieldSelectors: {
Copy link
Contributor Author

@maciesielka maciesielka May 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few other names I considered here were:

  • allowedUnusedFields
  • allowedUnusedFieldSelectors
  • ignoredFields

I think ignoredFieldSelectors avoids some of the oxymoronic qualities of allowedUnused* and provides useful context that this configuration uses ESLint selectors, but am open to other options.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer ignoredFieldSelectors too

description: [
'Fields that will be ignored and are allowed to be unused.',
'',
'> These fields are defined by ESLint [`selectors`](https://eslint.org/docs/developer-guide/selectors). Paste or drop code into the editor in [ASTExplorer](https://astexplorer.net) and inspect the generated AST to compose your selector.',
Copy link
Contributor Author

@maciesielka maciesielka May 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The naming-convention rule already makes use of ESLint selectors within configurations and it felt good to follow suit here. While this adds some clunkiness to the configuration (allowing an individual field looks like "FieldDefinition[name.value=field]" instead of "field"), there are benefits in that allowing fields with wildcards, based on their parent object, etc. are implicitly supported.

Copy link
Contributor

@dimaMachina dimaMachina Nov 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's fine to use selectors here instead of plain strings because we have the flexibility to choose parent name and parent pattern, see

[
  '[parent.name.value=PageInfo][name.value=endCursor]',
  '[parent.name.value=PageInfo][name.value=startCursor]',
  '[parent.name.value=PageInfo][name.value=hasNextPage]',
  '[parent.name.value=PageInfo][name.value=hasPreviousPage]',
  '[parent.name.value=/Edge$/][name.value=cursor]',
  '[parent.name.value=/Connection$/][name.value=pageInfo]',
]

we can specify ends with Edge and Connection, @maciesielka maybe we should update the default options to include it there?

@maciesielka maciesielka marked this pull request as ready for review May 3, 2024 19:18
Copy link
Contributor

@dimaMachina dimaMachina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for taking time merging it, great work!

@dimaMachina dimaMachina merged commit c53cb4e into graphql-hive:master Nov 17, 2024
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Add ignore list to no-unused-fields rule

2 participants