Difference between revisions of "Styleguide"

From diaspora* project wiki
Jump to: navigation, search
(First version)
 
m
Line 1: Line 1:
{{Work in progress}}
 
 
 
Please adhere to the following styleguides for your contributions. Transform existing code you touch to follow them.
 
Please adhere to the following styleguides for your contributions. Transform existing code you touch to follow them.
  
Line 27: Line 25:
  
 
= JavaScript =
 
= JavaScript =
 +
 +
{{Work in progress}}
  
 
To be decided, please see https://www.loomio.org/d/bLH78pEh/styleguides
 
To be decided, please see https://www.loomio.org/d/bLH78pEh/styleguides
  
 
= SCSS =
 
= SCSS =
 +
 +
{{Work in progress}}
  
 
To be decided, please see https://www.loomio.org/d/bLH78pEh/styleguides
 
To be decided, please see https://www.loomio.org/d/bLH78pEh/styleguides
  
  
[[Category:Developer]]
+
[[Category:Developers]]

Revision as of 04:21, 16 March 2015

Please adhere to the following styleguides for your contributions. Transform existing code you touch to follow them.

Ruby

We follow bbatsov's styleguide for Ruby, with the following derivations and choices:

  • Maximum line length is 120 characters.
  • Always use raise, never use fail. Use abort to exit on a fatal error condition.
  • No assignment in conditions, not even so called (safe = assignment).
  • No enforced variable names for inject, use names that properly describe the data.
  • Do not use Class.new to define exceptions, use the regular class keyword.
  • Do not add spaces inside string interpolation, "a #{b} c" is valid, "a #{ b } c" is not.
  • Do not do control flow with && and || outside conditionals. The only valid uses of && and || are in a condition and to compute a predicate that’s returned from a method.
  • Do not add spaces around = when used to define default arguments in method definitions. def foo(a, b=c) is valid, def foo(a, b = c) is not.
  • Default to using double quotes ("), only use single quotes (') when you want to use a double quote in your string. Use a percent literal if you want to use both in the string.
  • Use the %i percent literal to define an array of symbols.
  • Prefer Hash#has_key? and Hash#has_value? over Hash#key? and Hash#value?.
  • Prefer String#% over Kernel#sprintf.
  • Prefer inject over reduce.
  • Do not put put a space between the opening brace and a block argument. foo {|a| } is valid, foo { |a| } is not.
  • Do not put a space after the opening brace or before the closing brace of a hash literal. {foo: bar} is valid, { foo: bar } is not.
  • Use Weirichs rule when deciding about about the block syntax to use.
  • Use an appropriate name for the argument when defining an operator method, don't just default to other.


JavaScript

»» Work in progress
This article is a work in progress, it may contain incomplete or inaccurate information. There may be additional information on the talk page.


To be decided, please see https://www.loomio.org/d/bLH78pEh/styleguides

SCSS

»» Work in progress
This article is a work in progress, it may contain incomplete or inaccurate information. There may be additional information on the talk page.


To be decided, please see https://www.loomio.org/d/bLH78pEh/styleguides