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.

192 lines
5.3 KiB

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