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

[#2291] Support the '...' group for alphabetizing fragment spreads #2293

Merged

Conversation

yoavsion
Copy link
Contributor

@yoavsion yoavsion commented May 9, 2024

Description

Adds a group type to the groups property of the alphabetize rule indicating where fragment spreads should be in a selection set.

Similarly to the '*' group, which stands for "everything else," the '...' stands for "all fragment spreads."

Fixes #2291

Type of change

  • New feature (non-breaking change which adds functionality)
  • This change requires a documentation update

How Has This Been Tested?

Added the following unit tests, ran yarn test and verified that the error messages match the expected ones:

  • should sort selections by group when ... is at the start
  • should sort selections by group when ... is between
  • should sort selections by group when ... is at the end

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

Further comments

When working on this change, the display name for a fragment spread was showing undefined <fragment name>, which was because there was no name mapping for that Kind — so I went ahead and added display names for all Kind values, and sorted the map.

Copy link

changeset-bot bot commented May 9, 2024

🦋 Changeset detected

Latest commit: 52ef9cc

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 Minor

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

[Kind.OBJECT_TYPE_EXTENSION]: 'type',
[Kind.INTERFACE_TYPE_DEFINITION]: 'interface',
[Kind.INTERFACE_TYPE_EXTENSION]: 'interface',
const DisplayNodeNameMap: Record<Kind, string> = {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added display name for all Kind enum values, and sorted the list

@yoavsion yoavsion marked this pull request as ready for review May 17, 2024 05:38
renovate bot and others added 27 commits November 14, 2024 16:43
…ql-hive#2435)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
…hql-hive#2446)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
…hive#2436)

* fix(deps): update dependency @theguild/components to v6.6.3

* fix

* a

* aa

* aa

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Dimitri POSTOLOV <dmytropostolov@gmail.com>
…ql-hive#2447)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
* chore(deps): update dependency vitest to v2

* fix

* aa

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Dimitri POSTOLOV <dmytropostolov@gmail.com>
…raphql-hive#1648)

* chore(deps): update dependency eslint-plugin-eslint-plugin to v5.5.1

* aa

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Dimitri POSTOLOV <dmytropostolov@gmail.com>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
…hive#2453)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
* chore(deps): update dependency eslint to v9

* upd

* upd

* upd

* more

* more

* more

* more

* prettier

* fix type check

* fix type check

* fix type check

* fix type check

* fix bob check

* more work

* pnpm i

* fix prebuild

* Update website/src/components/graphql-editor.tsx

* fix types error

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
…les for multi projects (graphql-hive#2455)

* aa

* update tests

* fix lint
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
…r` to be compatible with ESLint 9 (graphql-hive#2458)

* fix lint

* aa

* aa

* more

* more

* more

* more

* more

* more

* format

* fix examples test

* fix website

* fix

* aa

* try

* okk

* nowww
…raphql-hive#2459)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
…#2463)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
…aphql-hive#2465)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
renovate bot and others added 21 commits November 14, 2024 16:43
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
* add new docs

* more

* more

* add

* more

* more

* more

* more

* more

* fix generate docs prettier, incorrectly formatted _meta.ts

* add baseUrl

* update eslint patch

* fix snapshots

* fix lint
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
* add new docs

* more

* more

* add

* more

* more

* more

* more

* more

* fix generate docs prettier, incorrectly formatted _meta.ts

* add baseUrl

* update eslint patch

* fix snapshots

* fix lint

* move

* more

* more

* more

* more

* more

* prettier

* more

* more

* more

* prettier

* more

* prettier

* more

* more

* more

* prettier

* fix for generate-configs

* pnpm dedupe
* add new docs

* more

* more

* add

* more

* more

* more

* more

* more

* fix generate docs prettier, incorrectly formatted _meta.ts

* add baseUrl

* update eslint patch

* fix snapshots

* fix lint

* move

* more

* more

* more

* more

* more

* prettier

* more

* more

* more

* prettier

* more

* prettier

* more

* more

* more

* prettier

* fix for generate-configs

* test legacy configs examples

* more

* more

* prettier

* more

* more

* more

* run tests for examples with legacy configs

* lint

* polish introduction

* add banner

* fill usages

* more

* more

* more

* polish configs

* more

* new link

* more

* more

* more

* more

* more

* new link

* more

* more
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
* add new docs

* more

* more

* add

* more

* more

* more

* more

* more

* fix generate docs prettier, incorrectly formatted _meta.ts

* add baseUrl

* update eslint patch

* fix snapshots

* fix lint

* move

* more

* more

* more

* more

* more

* prettier

* more

* more

* more

* prettier

* more

* prettier

* more

* more

* more

* prettier

* fix for generate-configs

* test legacy configs examples

* more

* more

* prettier

* more

* more

* more

* run tests for examples with legacy configs

* lint

* Add Vue usage instructions

* prettier

* 1. graphql plugin can now we specified with

```js
plugins: { '@graphql-eslint': graphqlPlugin },
```

2. config rules now should be specified with accessing `rules` property

```diff
  rules: {
-   ...graphqlESLint.configs['flat/operations-recommended']
+   ...graphqlESLint.configs['flat/operations-recommended'].rules
```

3. processor can now be specified with accessing `processor` property

```js
processor: graphqlPlugin.processor
```

4. plugin can now be imported with default import

```js
import graphqlPlugin from '@graphql-eslint/eslint-plugin'
```

* improve

* fix indent

---------

Co-authored-by: Dimitri POSTOLOV <dmytropostolov@gmail.com>
* runs tests of Windows

* fix

* prettier

* fix lint

* set ``"moduleResolution": "bundler"`

* set `"module": "esnext"`

* try to fix examples.spec.ts

* use optional chaining

* add log

* fix

* should fix

* fix new line on windows

* fix

* and here

* maybe this

* try

* try

* try

* attempt to fix schema.spec

* add shell: true

* improve

* try

* try

* try

* try

* try

* try

* try fix prettier example on windows

* try

* try now

* try now

* more

* try

* upd banner

* merge

* more

* more

* more

* fix

* log

* more

* now

* more

* try slash for filePath

* yoyo

* more

* try

* add changeset

* aa

* more

* i know the problem

* fix eslint tailwindcss

* see

* aa

* use `"eslint-plugin-tailwindcss": "3.17.3"`

* yes

* should be all good now

* try now

* thiiis
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Comment on lines +410 to +440

function getIndex({
node,
groups,
}: {
node: GraphQLESTreeNode<ASTNode>;
groups: string[];
}): number {
// Try an exact match
let index = groups.indexOf(getName(node));

// Check for the fragment spread group
if (index === -1 && node.kind === Kind.FRAGMENT_SPREAD) {
index = groups.indexOf('...');
}

// Check for the catch-all group
if (index === -1) {
index = groups.indexOf('*');
}
return index;
}

function getName(node: GraphQLESTreeNode<ASTNode>): string {
return (
('alias' in node && node.alias?.value) ||
//
('name' in node && node.name?.value) ||
''
);
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

refactored a bit for better readability

@@ -203,7 +203,7 @@ export const rule: GraphQLESLintRule<RuleOptions> = {
selections: selectionsEnum,
variables: true,
arguments: [Kind.FIELD, Kind.DIRECTIVE],
groups: ['id', '*', 'createdAt', 'updatedAt'],
groups: ['id', '*', 'createdAt', 'updatedAt', '...'],
Copy link
Collaborator

Choose a reason for hiding this comment

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

why this preference? I think the start is better?

Copy link
Collaborator

@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.

I refactored a bit duplicated code

I have only 1 comment https://github.com/dimaMachina/graphql-eslint/pull/2293/files#r1841895177

Thanks for contribution

@dimaMachina dimaMachina merged commit 01f7087 into graphql-hive:master Nov 16, 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.

Support the fragment spread group when defining alphabetize rule's groups
6 participants