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

Refactoring suggestions #72

Open
FluorescentHallucinogen opened this issue Oct 5, 2020 · 5 comments · Fixed by #1334
Open

Refactoring suggestions #72

FluorescentHallucinogen opened this issue Oct 5, 2020 · 5 comments · Fixed by #1334
Labels

Comments

@FluorescentHallucinogen
Copy link

Idea: find similar things and suggest refactorings. Is it possible?

E.g. find similar types and suggest to extract them into interface, find similar sets of fields in operations and suggest to extract them into fragments, find similar input values and suggest to extract them into variables.

Or vice versa: find fragments and variables that used only in one place and suggest to inline them.

@dotansimha
Copy link
Collaborator

This sounds very interesting. Any idea how can we locate those in a robust way what won't create incorrect results?
We can find similar selection sets (with TypeInfo) and suggest on moving to fragments, but that might not fit all use-cases...

@ilyavolodin
Copy link
Collaborator

ilyavolodin commented Oct 5, 2020

ESlint has a feature for this: https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions
Suggestions are not fixes, they will not be applied automatically, but will require the user to take an action to apply them. It was added specifically for the cases where there's no way to be sure that automatic change will make sense to the end user.

Finding duplicate code, however, is an np-complete problem, that's not trivial to implement even with a low guarantee.

@FluorescentHallucinogen
Copy link
Author

Some of them already implemented in GraphQL Altair: altair-graphql/altair#745 (comment).

@ilyavolodin
Copy link
Collaborator

One other thing to keep in mind: ESLint operates on one file at a time, so if you have duplicate code across multiple files, ESLint will not be able to handle that, it will only be able to make a suggestion if it sees duplicate code in the same file.

@dimaMachina
Copy link
Owner

no-one-place-fragments will be included in next release 3.14.0 to catch

find fragments that are used only in one place and suggest inline them.

@dimaMachina dimaMachina reopened this Dec 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants