Simple email application for Android. Original source code: https://framagit.org/dystopia-project/simple-email
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

222 lines
5.6 KiB

  1. .TH "NPM\-CODING\-STYLE" "7" "August 2018" "" ""
  2. .SH "NAME"
  3. \fBnpm-coding-style\fR \- npm's "funny" coding style
  4. .SH DESCRIPTION
  5. .P
  6. npm's coding style is a bit unconventional\. It is not different for
  7. difference's sake, but rather a carefully crafted style that is
  8. designed to reduce visual clutter and make bugs more apparent\.
  9. .P
  10. If you want to contribute to npm (which is very encouraged), you should
  11. make your code conform to npm's style\.
  12. .P
  13. Note: this concerns npm's code not the specific packages that you can download from the npm registry\.
  14. .SH Line Length
  15. .P
  16. Keep lines shorter than 80 characters\. It's better for lines to be
  17. too short than to be too long\. Break up long lists, objects, and other
  18. statements onto multiple lines\.
  19. .SH Indentation
  20. .P
  21. Two\-spaces\. Tabs are better, but they look like hell in web browsers
  22. (and on GitHub), and node uses 2 spaces, so that's that\.
  23. .P
  24. Configure your editor appropriately\.
  25. .SH Curly braces
  26. .P
  27. Curly braces belong on the same line as the thing that necessitates them\.
  28. .P
  29. Bad:
  30. .P
  31. .RS 2
  32. .nf
  33. function ()
  34. {
  35. .fi
  36. .RE
  37. .P
  38. Good:
  39. .P
  40. .RS 2
  41. .nf
  42. function () {
  43. .fi
  44. .RE
  45. .P
  46. If a block needs to wrap to the next line, use a curly brace\. Don't
  47. use it if it doesn't\.
  48. .P
  49. Bad:
  50. .P
  51. .RS 2
  52. .nf
  53. if (foo) { bar() }
  54. while (foo)
  55. bar()
  56. .fi
  57. .RE
  58. .P
  59. Good:
  60. .P
  61. .RS 2
  62. .nf
  63. if (foo) bar()
  64. while (foo) {
  65. bar()
  66. }
  67. .fi
  68. .RE
  69. .SH Semicolons
  70. .P
  71. Don't use them except in four situations:
  72. .RS 0
  73. .IP \(bu 2
  74. \fBfor (;;)\fP loops\. They're actually required\.
  75. .IP \(bu 2
  76. null loops like: \fBwhile (something) ;\fP (But you'd better have a good
  77. reason for doing that\.)
  78. .IP \(bu 2
  79. \fBcase 'foo': doSomething(); break\fP
  80. .IP \(bu 2
  81. In front of a leading \fB(\fP or \fB[\fP at the start of the line\.
  82. This prevents the expression from being interpreted
  83. as a function call or property access, respectively\.
  84. .RE
  85. .P
  86. Some examples of good semicolon usage:
  87. .P
  88. .RS 2
  89. .nf
  90. ;(x || y)\.doSomething()
  91. ;[a, b, c]\.forEach(doSomething)
  92. for (var i = 0; i < 10; i ++) {
  93. switch (state) {
  94. case 'begin': start(); continue
  95. case 'end': finish(); break
  96. default: throw new Error('unknown state')
  97. }
  98. end()
  99. }
  100. .fi
  101. .RE
  102. .P
  103. Note that starting lines with \fB\-\fP and \fB+\fP also should be prefixed
  104. with a semicolon, but this is much less common\.
  105. .SH Comma First
  106. .P
  107. If there is a list of things separated by commas, and it wraps
  108. across multiple lines, put the comma at the start of the next
  109. line, directly below the token that starts the list\. Put the
  110. final token in the list on a line by itself\. For example:
  111. .P
  112. .RS 2
  113. .nf
  114. var magicWords = [ 'abracadabra'
  115. , 'gesundheit'
  116. , 'ventrilo'
  117. ]
  118. , spells = { 'fireball' : function () { setOnFire() }
  119. , 'water' : function () { putOut() }
  120. }
  121. , a = 1
  122. , b = 'abc'
  123. , etc
  124. , somethingElse
  125. .fi
  126. .RE
  127. .SH Quotes
  128. .P
  129. Use single quotes for strings except to avoid escaping\.
  130. .P
  131. Bad:
  132. .P
  133. .RS 2
  134. .nf
  135. var notOk = "Just double quotes"
  136. .fi
  137. .RE
  138. .P
  139. Good:
  140. .P
  141. .RS 2
  142. .nf
  143. var ok = 'String contains "double" quotes'
  144. var alsoOk = "String contains 'single' quotes or apostrophe"
  145. .fi
  146. .RE
  147. .SH Whitespace
  148. .P
  149. Put a single space in front of \fB(\fP for anything other than a function call\.
  150. Also use a single space wherever it makes things more readable\.
  151. .P
  152. Don't leave trailing whitespace at the end of lines\. Don't indent empty
  153. lines\. Don't use more spaces than are helpful\.
  154. .SH Functions
  155. .P
  156. Use named functions\. They make stack traces a lot easier to read\.
  157. .SH Callbacks, Sync/async Style
  158. .P
  159. Use the asynchronous/non\-blocking versions of things as much as possible\.
  160. It might make more sense for npm to use the synchronous fs APIs, but this
  161. way, the fs and http and child process stuff all uses the same callback\-passing
  162. methodology\.
  163. .P
  164. The callback should always be the last argument in the list\. Its first
  165. argument is the Error or null\.
  166. .P
  167. Be very careful never to ever ever throw anything\. It's worse than useless\.
  168. Just send the error message back as the first argument to the callback\.
  169. .SH Errors
  170. .P
  171. Always create a new Error object with your message\. Don't just return a
  172. string message to the callback\. Stack traces are handy\.
  173. .SH Logging
  174. .P
  175. Logging is done using the npmlog \fIhttps://github\.com/npm/npmlog\fR
  176. utility\.
  177. .P
  178. Please clean up logs when they are no longer helpful\. In particular,
  179. logging the same object over and over again is not helpful\. Logs should
  180. report what's happening so that it's easier to track down where a fault
  181. occurs\.
  182. .P
  183. Use appropriate log levels\. See npm help 7 \fBnpm\-config\fP and search for
  184. "loglevel"\.
  185. .SH Case, naming, etc\.
  186. .P
  187. Use \fBlowerCamelCase\fP for multiword identifiers when they refer to objects,
  188. functions, methods, properties, or anything not specified in this section\.
  189. .P
  190. Use \fBUpperCamelCase\fP for class names (things that you'd pass to "new")\.
  191. .P
  192. Use \fBall\-lower\-hyphen\-css\-case\fP for multiword filenames and config keys\.
  193. .P
  194. Use named functions\. They make stack traces easier to follow\.
  195. .P
  196. Use \fBCAPS_SNAKE_CASE\fP for constants, things that should never change
  197. and are rarely used\.
  198. .P
  199. Use a single uppercase letter for function names where the function
  200. would normally be anonymous, but needs to call itself recursively\. It
  201. makes it clear that it's a "throwaway" function\.
  202. .SH null, undefined, false, 0
  203. .P
  204. Boolean variables and functions should always be either \fBtrue\fP or
  205. \fBfalse\fP\|\. Don't set it to 0 unless it's supposed to be a number\.
  206. .P
  207. When something is intentionally missing or removed, set it to \fBnull\fP\|\.
  208. .P
  209. Don't set things to \fBundefined\fP\|\. Reserve that value to mean "not yet
  210. set to anything\."
  211. .P
  212. Boolean objects are forbidden\.
  213. .SH SEE ALSO
  214. .RS 0
  215. .IP \(bu 2
  216. npm help 7 developers
  217. .IP \(bu 2
  218. npm help npm
  219. .RE