AI CodingThrive Editorial

25 prompts d’IA pour refactoriser du code

La refactorisation doit préserver le comportement du code. Ces prompts demandent les tests existants, une modification ciblée et un diff vérifiable avant de valider le nettoyage.

14 min de lecture
Développeur réorganisant des modules logiciels enchevêtrés en une structure claire.

La version courte

  • La refactorisation doit préserver le comportement du code. Ces prompts demandent les tests existants, une modification ciblée et un diff vérifiable avant de valider le nettoyage.
  • Ne transmettez jamais d’identifiants, de données client privées ou de dépôts propriétaires complets à un assistant non autorisé. Exécutez les commandes et les tests proposés dans votre environnement. Un correctif plausible ne prouve pas que la modification fonctionne.

La refactorisation doit préserver le comportement du code. Ces prompts demandent les tests existants, une modification ciblée et un diff vérifiable avant de valider le nettoyage.

Ne transmettez jamais d’identifiants, de données client privées ou de dépôts propriétaires complets à un assistant non autorisé. Exécutez les commandes et les tests proposés dans votre environnement. Un correctif plausible ne prouve pas que la modification fonctionne.

Comment utiliser cette collection

Choisissez la tâche la plus proche de votre travail. Copiez le prompt, remplacez la scène ou le contexte générique par vos informations et conservez les contraintes utiles pour évaluer le résultat. Modifiez une variable à la fois afin d’identifier ce qui s’améliore.

Cette méthode reprend les recommandations du guide de prompt engineering de GitHub Copilot : fournir un contexte précis et vérifier la réponse, sans supposer qu’un premier résultat soigné est correct.

Prompts de diagnostic

Cette série porte sur le diagnostic. Fournissez votre code et votre commande de test avant de valider la réponse.

1. Une longue chaîne de conditions

Help with a long conditional chain in my existing codebase. Ask for the relevant file, expected behavior, actual behavior and test command if I have not supplied them. Then state competing hypotheses, request a minimal reproduction and identify evidence that separates them. Preserve public interfaces unless evidence requires a change. Show assumptions, a focused diff and the exact command I should run. Do not invent files, test results or security guarantees.

Vérification : Exécutez le scénario de reproduction proposé avant d’appliquer un correctif.

2. Une règle de validation dupliquée

Help with a duplicated validation rule in my existing codebase. Ask for the relevant file, expected behavior, actual behavior and test command if I have not supplied them. Then state competing hypotheses, request a minimal reproduction and identify evidence that separates them. Preserve public interfaces unless evidence requires a change. Show assumptions, a focused diff and the exact command I should run. Do not invent files, test results or security guarantees.

Vérification : Exécutez le scénario de reproduction proposé avant d’appliquer un correctif.

3. Un utilitaire de base de données avec effets de bord

Help with a database helper with side effects in my existing codebase. Ask for the relevant file, expected behavior, actual behavior and test command if I have not supplied them. Then state competing hypotheses, request a minimal reproduction and identify evidence that separates them. Preserve public interfaces unless evidence requires a change. Show assumptions, a focused diff and the exact command I should run. Do not invent files, test results or security guarantees.

Vérification : Exécutez le scénario de reproduction proposé avant d’appliquer un correctif.

4. Un grand composant React

Help with a large React component in my existing codebase. Ask for the relevant file, expected behavior, actual behavior and test command if I have not supplied them. Then state competing hypotheses, request a minimal reproduction and identify evidence that separates them. Preserve public interfaces unless evidence requires a change. Show assumptions, a focused diff and the exact command I should run. Do not invent files, test results or security guarantees.

Vérification : Exécutez le scénario de reproduction proposé avant d’appliquer un correctif.

5. Un contrôleur d’API enchevêtré

Help with a tangled API controller in my existing codebase. Ask for the relevant file, expected behavior, actual behavior and test command if I have not supplied them. Then state competing hypotheses, request a minimal reproduction and identify evidence that separates them. Preserve public interfaces unless evidence requires a change. Show assumptions, a focused diff and the exact command I should run. Do not invent files, test results or security guarantees.

Vérification : Exécutez le scénario de reproduction proposé avant d’appliquer un correctif.

6. Une configuration avec chaînes magiques

Help with a magic-string configuration in my existing codebase. Ask for the relevant file, expected behavior, actual behavior and test command if I have not supplied them. Then state competing hypotheses, request a minimal reproduction and identify evidence that separates them. Preserve public interfaces unless evidence requires a change. Show assumptions, a focused diff and the exact command I should run. Do not invent files, test results or security guarantees.

Vérification : Exécutez le scénario de reproduction proposé avant d’appliquer un correctif.

7. Un utilitaire aux noms vagues

Help with a utility with vague names in my existing codebase. Ask for the relevant file, expected behavior, actual behavior and test command if I have not supplied them. Then state competing hypotheses, request a minimal reproduction and identify evidence that separates them. Preserve public interfaces unless evidence requires a change. Show assumptions, a focused diff and the exact command I should run. Do not invent files, test results or security guarantees.

Vérification : Exécutez le scénario de reproduction proposé avant d’appliquer un correctif.

8. Une boucle lente

Help with a slow loop in my existing codebase. Ask for the relevant file, expected behavior, actual behavior and test command if I have not supplied them. Then state competing hypotheses, request a minimal reproduction and identify evidence that separates them. Preserve public interfaces unless evidence requires a change. Show assumptions, a focused diff and the exact command I should run. Do not invent files, test results or security guarantees.

Vérification : Exécutez le scénario de reproduction proposé avant d’appliquer un correctif.

9. Une ancienne chaîne de callbacks

Help with a legacy callback chain in my existing codebase. Ask for the relevant file, expected behavior, actual behavior and test command if I have not supplied them. Then state competing hypotheses, request a minimal reproduction and identify evidence that separates them. Preserve public interfaces unless evidence requires a change. Show assumptions, a focused diff and the exact command I should run. Do not invent files, test results or security guarantees.

Vérification : Exécutez le scénario de reproduction proposé avant d’appliquer un correctif.

A tangled software function reorganized into three smaller modules.

10. Un contrôle de permissions dispersé

Help with a scattered permission check in my existing codebase. Ask for the relevant file, expected behavior, actual behavior and test command if I have not supplied them. Then state competing hypotheses, request a minimal reproduction and identify evidence that separates them. Preserve public interfaces unless evidence requires a change. Show assumptions, a focused diff and the exact command I should run. Do not invent files, test results or security guarantees.

Vérification : Exécutez le scénario de reproduction proposé avant d’appliquer un correctif.

Prompts de mise en œuvre

Cette série porte sur la mise en œuvre. Fournissez votre code et votre commande de test avant de valider la réponse.

11. Une longue chaîne de conditions

Help with a long conditional chain in my existing codebase. Ask for the relevant file, expected behavior, actual behavior and test command if I have not supplied them. Then make the smallest change that satisfies the stated behavior and show a focused diff. Preserve public interfaces unless evidence requires a change. Show assumptions, a focused diff and the exact command I should run. Do not invent files, test results or security guarantees.

Vérification : Vérifiez que le diff ne contient ni modification hors sujet ni accès aux données non prévu.

12. Une règle de validation dupliquée

Help with a duplicated validation rule in my existing codebase. Ask for the relevant file, expected behavior, actual behavior and test command if I have not supplied them. Then make the smallest change that satisfies the stated behavior and show a focused diff. Preserve public interfaces unless evidence requires a change. Show assumptions, a focused diff and the exact command I should run. Do not invent files, test results or security guarantees.

Vérification : Vérifiez que le diff ne contient ni modification hors sujet ni accès aux données non prévu.

13. Un utilitaire de base de données avec effets de bord

Help with a database helper with side effects in my existing codebase. Ask for the relevant file, expected behavior, actual behavior and test command if I have not supplied them. Then make the smallest change that satisfies the stated behavior and show a focused diff. Preserve public interfaces unless evidence requires a change. Show assumptions, a focused diff and the exact command I should run. Do not invent files, test results or security guarantees.

Vérification : Vérifiez que le diff ne contient ni modification hors sujet ni accès aux données non prévu.

14. Un grand composant React

Help with a large React component in my existing codebase. Ask for the relevant file, expected behavior, actual behavior and test command if I have not supplied them. Then make the smallest change that satisfies the stated behavior and show a focused diff. Preserve public interfaces unless evidence requires a change. Show assumptions, a focused diff and the exact command I should run. Do not invent files, test results or security guarantees.

Vérification : Vérifiez que le diff ne contient ni modification hors sujet ni accès aux données non prévu.

15. Un contrôleur d’API enchevêtré

Help with a tangled API controller in my existing codebase. Ask for the relevant file, expected behavior, actual behavior and test command if I have not supplied them. Then make the smallest change that satisfies the stated behavior and show a focused diff. Preserve public interfaces unless evidence requires a change. Show assumptions, a focused diff and the exact command I should run. Do not invent files, test results or security guarantees.

Vérification : Vérifiez que le diff ne contient ni modification hors sujet ni accès aux données non prévu.

16. Une configuration avec chaînes magiques

Help with a magic-string configuration in my existing codebase. Ask for the relevant file, expected behavior, actual behavior and test command if I have not supplied them. Then make the smallest change that satisfies the stated behavior and show a focused diff. Preserve public interfaces unless evidence requires a change. Show assumptions, a focused diff and the exact command I should run. Do not invent files, test results or security guarantees.

Vérification : Vérifiez que le diff ne contient ni modification hors sujet ni accès aux données non prévu.

17. Un utilitaire aux noms vagues

Help with a utility with vague names in my existing codebase. Ask for the relevant file, expected behavior, actual behavior and test command if I have not supplied them. Then make the smallest change that satisfies the stated behavior and show a focused diff. Preserve public interfaces unless evidence requires a change. Show assumptions, a focused diff and the exact command I should run. Do not invent files, test results or security guarantees.

Vérification : Vérifiez que le diff ne contient ni modification hors sujet ni accès aux données non prévu.

Three-step code workflow: brief the work, inspect the result, edit and verify.

18. Une boucle lente

Help with a slow loop in my existing codebase. Ask for the relevant file, expected behavior, actual behavior and test command if I have not supplied them. Then make the smallest change that satisfies the stated behavior and show a focused diff. Preserve public interfaces unless evidence requires a change. Show assumptions, a focused diff and the exact command I should run. Do not invent files, test results or security guarantees.

Vérification : Vérifiez que le diff ne contient ni modification hors sujet ni accès aux données non prévu.

19. Une ancienne chaîne de callbacks

Help with a legacy callback chain in my existing codebase. Ask for the relevant file, expected behavior, actual behavior and test command if I have not supplied them. Then make the smallest change that satisfies the stated behavior and show a focused diff. Preserve public interfaces unless evidence requires a change. Show assumptions, a focused diff and the exact command I should run. Do not invent files, test results or security guarantees.

Vérification : Vérifiez que le diff ne contient ni modification hors sujet ni accès aux données non prévu.

20. Un contrôle de permissions dispersé

Help with a scattered permission check in my existing codebase. Ask for the relevant file, expected behavior, actual behavior and test command if I have not supplied them. Then make the smallest change that satisfies the stated behavior and show a focused diff. Preserve public interfaces unless evidence requires a change. Show assumptions, a focused diff and the exact command I should run. Do not invent files, test results or security guarantees.

Vérification : Vérifiez que le diff ne contient ni modification hors sujet ni accès aux données non prévu.

Prompts de test des limites

Cette série porte sur les tests de limites. Fournissez votre code et votre commande de test avant de valider la réponse.

21. Une longue chaîne de conditions

Help with a long conditional chain in my existing codebase. Ask for the relevant file, expected behavior, actual behavior and test command if I have not supplied them. Then add unit or integration cases for empty, invalid and concurrent inputs as appropriate. Preserve public interfaces unless evidence requires a change. Show assumptions, a focused diff and the exact command I should run. Do not invent files, test results or security guarantees.

Vérification : Exécutez les tests et, si possible, vérifiez qu’ils échouent avant le correctif.

22. Une règle de validation dupliquée

Help with a duplicated validation rule in my existing codebase. Ask for the relevant file, expected behavior, actual behavior and test command if I have not supplied them. Then add unit or integration cases for empty, invalid and concurrent inputs as appropriate. Preserve public interfaces unless evidence requires a change. Show assumptions, a focused diff and the exact command I should run. Do not invent files, test results or security guarantees.

Vérification : Exécutez les tests et, si possible, vérifiez qu’ils échouent avant le correctif.

23. Un utilitaire de base de données avec effets de bord

Help with a database helper with side effects in my existing codebase. Ask for the relevant file, expected behavior, actual behavior and test command if I have not supplied them. Then add unit or integration cases for empty, invalid and concurrent inputs as appropriate. Preserve public interfaces unless evidence requires a change. Show assumptions, a focused diff and the exact command I should run. Do not invent files, test results or security guarantees.

Vérification : Exécutez les tests et, si possible, vérifiez qu’ils échouent avant le correctif.

24. Un grand composant React

Help with a large React component in my existing codebase. Ask for the relevant file, expected behavior, actual behavior and test command if I have not supplied them. Then add unit or integration cases for empty, invalid and concurrent inputs as appropriate. Preserve public interfaces unless evidence requires a change. Show assumptions, a focused diff and the exact command I should run. Do not invent files, test results or security guarantees.

Vérification : Exécutez les tests et, si possible, vérifiez qu’ils échouent avant le correctif.

25. Un contrôleur d’API enchevêtré

Help with a tangled API controller in my existing codebase. Ask for the relevant file, expected behavior, actual behavior and test command if I have not supplied them. Then add unit or integration cases for empty, invalid and concurrent inputs as appropriate. Preserve public interfaces unless evidence requires a change. Show assumptions, a focused diff and the exact command I should run. Do not invent files, test results or security guarantees.

Vérification : Exécutez les tests et, si possible, vérifiez qu’ils échouent avant le correctif.

Que vérifier avant d’utiliser le résultat

Ne transmettez jamais d’identifiants, de données client privées ou de dépôts propriétaires complets à un assistant non autorisé. Exécutez les commandes et les tests proposés dans votre environnement. Un correctif plausible ne prouve pas que la modification fonctionne.

Si le résultat ne répond pas à la tâche, raccourcissez le prompt et précisez l’information ou la contrainte manquante. Conservez la version utilisée pour pouvoir reproduire le visuel final ou la modification du code.

Pour aller plus loin

Poursuivre avec un guide associé

Mise en pratique

Votre prochaine étape

Vous avez une question ou une correction?

Contacter Thrive

Continuez à lire

Pour en savoir plus sur le journal

Tous les articles