This repository has been archived by the owner on Sep 6, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Brackets Coding Conventions
gruehle edited this page May 15, 2012
·
29 revisions
Brackets uses some specific coding conventions. All of the pull requests that come in should adhere to the following rules:
- All JavaScript files have a single module definition using the following format:
define(function (require, exports, module) {
// Load dependent modules
var Module = require("Module");
function someFunction() {
// ...
}
// Export public APIs
exports.someFunction = someFunction;
}
- Must pass JSLint. The default settings for JSLint are:
/*jslint vars: true, plusplus: true, devel: true, nomen: true, indent: 4, maxerr: 50 */
/*global define */
Variable and function names use camelCase (not under_scores): > Do this: > > ``` > var editorHolder; > function getText(); > ``` > > Not this: > > ``` > var editor_holder; // Don't use underscore! > function get_text(); // Don't use underscore! > ```
Use $ prefixes on variables referring to jQuery objects: > Do this: > > ``` > var $sidebar = $("#sidebar"); > ``` > > Not this: > > ``` > var sidebar = $("#sidebar"); // Use '$' to prefix variables referring to jQuery objects > ```
Use _ prefixes on private variables/methods: > Do this: > > ``` > var _privateVar = 42; > function _privateFunction() > ``` > > Not this: > > ``` > var privateVar = 42; // Private vars should start with _ > function privateFunction() // Private functions should start with _ > ```
Classes and id's in HTML use all lower-case with dashes (-), not camelCase or under_scores: > Do this: > > ``` >
>
> ```
>
> Not this:
>
> ```
>
// Don't use camel-case for ids
> // Don't use underscore
> ```
Use semicolons: > Do this: > > ``` > var someVar; > someVar = 2 + 2; > ``` > > Not this: > > ``` > var someVar // Missing semicolon! > someVar = 2 + 2 // Missing semicolon! > ```
Use double quotes in JavaScript: > Do this: > > ``` > var aString = "Hello"; > someFunction("This is awesome!"); > ``` > > Not this: > > ``` > var aString = 'Hello'; // Use double quotes! > someFunction("This is awesome!"); // Use double quotes! > ```
Use semicolons: > Do this: > > ``` > var someVar; > someVar = 2 + 2; > ``` > > Not this: > > ``` > var someVar // Missing semicolon! > someVar = 2 + 2 // Missing semicolon! > ```
Use double quotes in JavaScript: > Do this: > > ``` > var aString = "Hello"; > someFunction("This is awesome!"); > ``` > > Not this: > > ``` > var aString = 'Hello'; // Use double quotes! > someFunction("This is awesome!"); // Use double quotes! > ```
- Closure vars should go at the top of the code block they're scoped to
- use of Array.forEach() instead of $.each()
- 4-space indents (soft tabs)
- All comments should be C++ single line style //comment.
- Even multiline comments should use // at the start of each line
- Use C style /* comments */ for notices at the top and bottom of the file
- Annotations should use the /** annotation */
- Annotate all functions