Skip to content
This repository was archived by the owner on Jan 8, 2025. It is now read-only.

Latest commit

 

History

History
42 lines (31 loc) · 1.73 KB

javascript.md

File metadata and controls

42 lines (31 loc) · 1.73 KB

JavaScript coding standards

Follow the rules in the ESLint configuration.

The Dojo style guide provides a lot of good guidance. There may be some differences in our ESLint configuration, in that case those take precedence.

  1. Use single quotes for string values, unless the string contains a single quote, in which case it is preferable to use double quotes and avoid escaping the single quotes in the content.
  2. Only quote property names when necessary (e.g. if they contain a dash or begin with '0')

Modules

  1. Module names should be camel cased
  2. Modules that primarily export a class should have the same name as the class (which should be CamelCase)
  3. Modules that do not export a class should have a descriptive name starting with lower case (camelCase)
  4. Modules should use named exports instead of default exports (further reading), e.g.:
    • Functions and variables should be included in the final export:
function classHelper () {}
class MyClass {}
export { MyClass };
// or
export {
	classHelper,
	MyClass,
};

This export style makes it very easy to see in one place all exports from a module.

Import order

Module imports should be grouped:

  1. External dependencies (packages from Node.js or node_modules)
  2. Project dependencies outside the current folder (../**)
  3. Project dependencies from within the current folder (./**)
  4. CSS imports (import './MyModule.css';)

Sorting within each group should be by package path and name, case-insensitive, and ignoring leading @