Skip to content

Coding Guidelines

Brett Cannon edited this page Jun 10, 2019 · 2 revisions

Interfaces

  • Always aim for small, targeted interfaces
  • IDisposable & IAsynDisposable
    • Classes that require disposing of resources must implement the IDisposable interface
    • Classes that require disposing of resources in an async manner must implement the IAsynDisposable interface
  • IExtensionActivationService
    • Classes that require code to be executed during the startup of the extension must implement IExtensionActivationService

Object management

  • Timers/Timeouts
    • All timers/timeouts (setTimeout/setInterval) must be cleared in the dispose method of the class
    • This ensure we do not have any dangling timeouts preventing the process from gracefully exiting.
  • Async Methods
    • Async must be awaited where possible.
    • If awaiting on async methods is not required or not possible always use ignoreErrors to ensure we do not leave any dangling promises (i.e. promises where we do not handle exceptions).
    • Note: Not doing so could (in a future version of Node.js) crash the entire process.

Miscellaneous

  • Write code to be testable
  • Localization
    • All messages displayed to the user must be localized.
Clone this wiki locally