Skip to content

Latest commit

 

History

History
93 lines (70 loc) · 1.06 KB

coffeescript.md

File metadata and controls

93 lines (70 loc) · 1.06 KB

CoffeeScript

Largely inspired by Airbnb's JavaScript style guide

Indentation & Spaces

4 spaces.. not 2, no tabs

RequireJS define

Array of dependencies are line-delimited.

# good
require [
    'foo'
    'bar'
    'qux'
], (foo, bar, qux) ->

# bad
require ['foo', 'bar', 'baz'], (foo, bar, baz) ->

Commas

No trailing commas for line-delimited arrays or objects.

# good
foo = [
    'foo'
    'bar'
    'baz'
]

bar =
  foo: 1
  bar: 2
  baz: 3

# bad
foo = [
    'foo',
    'bar',
    'baz'
]

bar =
  foo: 1,
  bar: 2,
  baz: 3

Strings

Single quotes always, unless a single quote is used in the string itself

# good
foo = 'hello'
bar = "can't"

# bad
foo = "bar"
bar = 'can\'t'

Classes and Functions

No parenthesis with arguments that span multiple lines.

# good
foo = new Foo
    bar: 1
    qux: false

foo = bar
    bar: 1
    qux: false

# bad
foo = new Foo(
    bar: 1
    qux; false
)

foo = bar(
    bar: 1
    qux: false
)