3 If you've taken to hacking Pentadactyl source code, we hope that you'll share
4 your changes. In case you do, please keep the following in mind, and we'll be
5 happy to accept your patches.
9 First of all, all new features and all user-visible changes to existing
10 features need to be documented. That means editing the appropriate help files
11 and adding a NEWS entry where appropriate. When editing the NEWS file, you
12 should add your change to the top of the list of changes. If your change
13 alters an interface (key binding, command) and is likely to cause trouble,
14 prefix it with 'IMPORTANT:', otherwise, place it below the other 'IMPORTANT'
15 entries. If you're not sure if your change merits a news entry, or if it's
16 important, please ask.
20 In general: Just look at the existing source code!
22 === The most important style issues are: ===
24 * Use 4 spaces to indent things, no tabs, not 2, nor 8 spaces. If you use Vim,
25 this should be taken care of automatically by the modeline (like the
28 * No trailing whitespace.
30 * Use " for enclosing strings instead of ', unless using ' avoids escaping of lots of "
31 Example: alert("foo") instead of alert('foo');
33 * Use // regexp literals rather than RegExp constructors, unless
34 you're constructing an expression on the fly, or RegExp
35 constructors allow you to escape less /s than the additional
36 escaping of special characters required by string quoting.
38 Good: /application\/xhtml\+xml/
39 Bad: RegExp("application/xhtml\\+xml")
40 Good: RegExp("http://(www\\.)vimperator.org/(.*)/(.*)")
41 Bad: /http:\/\/(www\.)vimperator.org\/(.*)\/(.*)/
43 * Exactly one space after if/for/while/catch etc. and after a comma, but none
44 after a parenthesis or after a function call:
45 for (pre; condition; post)
49 * Bracing is formatted as follows:
50 function myFunction () {
58 var quux = frob("you",
67 When in doubt, look for similar code.
69 * No braces for one-line conditional statements:
76 * Prefer lambda-style functions where suitable:
77 Right: list.filter(function (elem) elem.good != elem.BAD);
78 Wrong: list.filter(function (elem) { return elem.good != elem.BAD });
79 Right: list.forEach(function (elem) { window.alert(elem); });
80 Wrong: list.forEach(function (elem) window.alert(elem));
82 * Anonymous function definitions should be formatted with a space after the
83 keyword "function". Example: function () {}, not function() {}.
85 * Prefer the use of let over var i.e. only use var when required.
87 https://developer.mozilla.org/en/New_in_JavaScript_1.7#Block_scope_with_let
89 * Reuse common local variable names E.g. "elem" is generally used for element,
90 "win" for windows, "func" for functions, "res" for return values etc.
92 * Prefer // over /* */ comments (exceptions for big comments are usually OK)
93 Right: if (HACK) // TODO: remove hack
94 Wrong: if (HACK) /* TODO: remove hack */
96 * Documentation comment blocks use /** ... */ Wrap these lines at 80
99 * Only wrap lines if it makes the code obviously clearer. Lines longer than 132
100 characters should probably be broken up rather than wrapped anyway.
102 * Use UNIX new lines (\n), not windows (\r\n) or old Mac ones (\r)
104 * Use Iterators or Array#forEach to iterate over arrays. for (let i
105 in ary) and for each (let i in ary) include members in an
106 Array.prototype, which some extensions alter.
108 for (let [,elem] in Iterator(ary))
109 for (let [k, v] in Iterator(obj))
110 ary.forEach(function (elem) { ...
112 for each (let elem in ary)
114 The exceptions to this rule are for objects with __iterator__ set,
115 and for XML objects (see README.E4X).
117 * Avoid using 'new' with constructors where possible, and use [] and
118 {} rather than new Array/new Object.
120 RegExp("^" + foo + "$")
124 new RegExp("^" + foo + "$")
126 Date() // Right if you want a string-representation of the date
128 * Don't use abbreviations for public methods
130 function splitString()...
132 let cmds = ...; // Since it's only used locally, abbreviations are ok, but so are the full names
138 Functional tests are implemented using the Mozmill automated testing framework
139 -- https://developer.mozilla.org/en/Mozmill_Tests.
141 A fresh profile is created for the duration of the test run.
143 The host application binary tested can be overridden via the HOSTAPP_PATH
144 makefile variable. E.g.,
145 $ HOSTAPP_PATH=/path/to/firefox make -e -C pentadactyl test
147 // vim: fdm=marker sw=4 ts=4 et ai: