-
Notifications
You must be signed in to change notification settings - Fork 107
Code Style Guide
-
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 thesetup
function defined inlib/cache_store.js
:setup: function(config){ var self = this; self.outputDir = config.output_dir; }
-
Always use
self
to refer to the current module. Usingthis
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 theself
. -
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
.