Skip to content

Latest commit

 

History

History
159 lines (117 loc) · 3.53 KB

CONTRIBUTING.md

File metadata and controls

159 lines (117 loc) · 3.53 KB

Test status

CONTRIBUTING.md

TOC

  1. Patch Requirements
  2. Logging
  3. Style Guide
  4. Unit Tests

Final Patch Requirements

  1. 1 commit per issue PR.
  2. Tests pass locally on your machine. See the README for the most up-to-date way to run tests
  3. Confirm that travis-ci is passing

Travis-ci states

In the PR, confirm that travis-ci has passed the tests. In every pull request, you'll see this when travis-ci is running:

screen shot 2015-02-03 at 12 17 22 am


screen shot 2015-02-03 at 12 17 16 am

And this when tests have passed:

screen shot 2015-02-03 at 12 16 43 am


screen shot 2015-02-03 at 12 16 52 am


Logging

Our logging module provides four logging methods:

var log = require('./bin/logger');

log.info(...);
log.warn(...);
log.error(...);
log.fatal(...);

Whenever a successful request occurs, after a response is sent, log the req, res and data objects using info:

res.status(200).send(student);
log.info({
  req: req,
  res: res,
  student: student
});

If a request is unsuccessful, our error handling middleware will catch and log it with warn on a 404, or error on anything else.

If you are programming an error case that is guaranteed to crash the program, or should cause the server to abort, log the error with fatal:

case 'EADDRINUSE':
  log.fatal(bind + ' is already in use');
  process.exit(1);
  break;

Style-guide

Follow this styling for all code commited on the front or back end:

// Single line comments to explain stuff
var camelCaseVariableNames;

/**
 * Multiline comments for section names ONLY
 */
function CapitalizedCamelClassNames() {
  // Constructor logic here
}

function camelCasedFunctionNames() {
  /**
   * Prefer early returns, like this:
   */
  if (failCondition) {  // `failCondition == true` or `failCondition != undefined` is usually unnecessary
    // Conditional logic here
    return;
  }
  if (!otherCondition) {
    // Conditional logic here
    return;
  }

  /**
   * Instead of this:
   */
  if (failCondition) {
    // Conditional logic here
  }  else if(!otherCondition) {
    // Conditional logic here
  }
}

// Space before curly braces:
function codeBlock() {}

// vs

function codeBlock(){}

xx// Two
xxxx// Space
xxxxxx// Indents
function niceAndCompact {
  If (derp) {
    return;
  }
}

// Simple single statement if conditions:
if (err) throw err;

// vs
if (err) {
  throw err;
}

// Comments directly above code block they relate to
function blah() {
	// ...
}
// vs

// Comments not directly above code block

function blah() {
	// ...
}

Unit Tests

All of our unit tests are required into 1 main test file - /tests/index.js. Please be sure to add in your new test suite to this file, since our automated test runners all point to this location.

Any reusable helper functions that can be placed in a new module test should be added to utils.js, and all of the api route tests are logically placed in the api subfolder.