Back to Rules

๐Ÿง  Copilot Rule โ€” JavaScript Code Quality & Completion Safety

OfficialPopular
Github copilotJavaScript
copilotjavascriptgithub-copilotcode-qualitysafetybest-practices

You are a JavaScript engineer using GitHub Copilot to generate code that is safe, readable, and consistent with modern standards.

โœ๏ธ Guide Copilot With Clear Intent

  • Write a comment that explains what and why, not just how
  • Include expected inputs, state transitions, and fail scenarios
  • Describe environment: Browser, Node, DOM, or API context
  • Copilot mirrors your clarity โ€” be precise to avoid guessing

๐Ÿ“ฆ Modern Module Structure

  • Prefer ES modules: import/export explicitly
  • Keep top-level functions pure where possible
  • Avoid polluting global scope โ€” name your boundaries

๐Ÿงช Ensure Generated Code is Testable

  • Ask Copilot to return simple values, not perform side effects
  • Encourage dependency injection for mocks and isolation
  • Keep behavior predictable for CI stability

๐Ÿ” Copilot Safety for JavaScript

  • Validate user input and async results
  • Never trust client-side security alone
  • Ask Copilot to sanitize DOM updates in UI code
  • Autocompletion doesn't know your threat model โ€” you must

๐Ÿš€ Performance By Default

  • Avoid creating unnecessary closures in hot paths
  • Batch DOM reads/writes to reduce layout thrash
  • Offload heavy lifting away from rendering frames

๐Ÿ“š Maintain a Shared Style

  • Use consistent naming and linting rules (ESLint + Prettier)
  • Keep prop ordering and function signatures predictable
  • Request refactors from Copilot for consistency checks

๐Ÿง  Knowing When to Say "Stop"

  • Review suggestions for silent bugs or subtle anti-patterns
  • Watch for legacy patterns like callback pyramids
  • Reject code that feels "too clever"
  • Copilot writes code quickly โ€” humans keep code maintainable

๐Ÿ”‘ JavaScript + Copilot Principles

  • Clear intent โ†’ clean generation
  • Testable code lasts longer
  • Security is not optional
  • Consistency beats creativity
  • You are the architect โ€” Copilot is the assistant
View Tool Page