Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Code Style Guide

KenanY edited this page · 3 revisions
  • Run JSHint, to see if your contributions are in accordance with the style followed by Punch. The .jshintrc file in the root directory defines the common JavaScript coding styles used in the project.

  • Please read Caolan Mcmahon's excellent article on "Node.js: Style and structure". Punch's source is written following similar conventions.

  • Use setup function to set the initial state for a module. For example, check the setup function defined in lib/cache_store.js:

    setup: function(config){
        var self = this;
        self.outputDir = config.output_dir;
    }
  • Always use self to refer to the current module. Using this as a reference to the module could be confusing, especially when there are nested callbacks. If you are adding a new function to a module, start by defining the self.

  • Use camel case (setContentType) for exported variables and underscored names (asset_bundler) for private variables.

  • Scope private variables (and functions) to the immediate function they are used. Scope them to the module only if they are used by multiple functions in the module. If you want to use some function in multiple modules, make it into a utility module (check lib/utils).

  • Use nouns for module names (PageRenderer) and verb clauses (getHelpers) for functions.

  • All exported modules should be added to lib/index.js.

Something went wrong with that request. Please try again.