Menu

Code Style

Patrick Brunschwig Nicolai Josuttis

<= =>

Code Style Used in Enigmail

The code style used in Enigmail is derived from the standard code style of js-beautify. We use js-beautify with the following non-default options:

  • indent-size: 2
  • end-with-newline: true
  • brace-style: end-expand

These defaults are committed to the top level source tree and will be automatically used by js-beautify.

Example:

/**
 * This is just a sample script.
 */

function tmp(a, b, c) {

  try {
    if (a === 1 && b.search(/an_example/)) {
      of_beautifer();
    }
    else {
      var a = b ? (c % d) : e[f];
    }

    switch (x) {
      case 1:
        doSomething();
        break;
      default:
        doDefault(x);
    }
  }
  catch (e) {
    // some comment
    handleEx();
  }

}

Writing Code

Please try to avoid statements that are hard to read such as:

let isError = getStatusFunc()
(isError ? handleError : handleFailure)(a, b c);

We prefer code that is readable code, even if it requires more typing. E.g.:

let isError = getStatusFunc()
if (isError) {
  handleError(a,b c);
}
else {
  handleFailure(a, b c);
}

Related

Developer Wiki: Development Environment
Developer Wiki: Home
Developer Wiki: Planning for version 1.9

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.