| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
# No
arr = [
'foo',
'bar'
]
obj =
foo: bar,
baz: qux
# Yes
arr = [
'foo'
'bar'
]
obj =
foo : bar
baz : qux# No
class Foo extends Bar
constructor: (options = {}, data) -> # no space at all
@options = options
@data = data
# Yes
class Foo extends Bar
# 1 \n
constructor: (options = {}, data) ->
@options = options
@data = data# No
class Foo extends Bar
constructor: (options = {}, data) ->
@options = options
# 1 \n
getOptions: -> @options
# Yes
class Foo extends Bar
constructor: (options = {}, data) ->
@options = options
# 1 \n
# 2 \n
getOptions: -> @options
# Yes
doSomething = ->
bar()
baz()
# 1 \n
# 2 \n
doSomething = ->
qux()
fn()
# No
doSomething = ->
bar()
baz()
# Yes
doSomething = ->
foo()
bar()# No
x= 1
y =2
z=3
# Yes
x = 1
y = 2
z = 3
# No
x = 1
y = 2
longVariable = 'string'
# Yes
x = 1
y = 2
longVariable = 'string'
# No
obj =
var : 1
short : 2
longVariable : 3
# Yes
obj =
var: 1
short: 2
longVariable: 3# No
obj = obj || {}
bool = condition && otherCondition
isWrong = !right
expression = first == second
expression = first != second
bool = true
bool = false
# Yes
obj or= {}
bool = condition and otherCondition
isWrong = not right
expression = first is second
expression = first isnt second
bool = yes # `on` depending on the context (e.g `isLoggedIn = yes` vs `state = on`)
bool = no # `off` ^^We are using CommonJS module imports with Browserify.
_ = require 'underscore'
KDView = require 'kdf/view'Require statements should follow the following order:
1 - 3rd Party Library imports 2 - Internal library/framework imports 3 - Application specific imports
# No
obj = {
foo : bar
baz : qux
}
# Yes
obj =
foo : bar
baz : qux# No
obj = foo: bar, baz: qux
# Yes
obj = { foo: bar, baz: qux }# No
foo('bar')
foo().bar('baz', 'qux')
# Yes
foo 'bar'
foo().bar 'baz', 'qux'# No
foo('bar').baz()
foo(bar('baz')).qux()
(foo (bar 'baz'))
((foo 'bar').baz 'qux').etc()
(foo 'bar').baz()
(foo 'bar').baz('qux').etc()
# Yes
foo().bar('baz').qux()
foo().bar 'baz'
foo('bar').baz('qux').etc()# No
foo('bar').baz()
.qux()
# Yes
foo 'bar'
.baz()
.qux()# No
str = 'This string has ' + variables + 'inside.'
str += ' And this is cool.'
# Yes
str = "This string has #{variables} inside."
str = "#{str} And this is cool."# No
str = "This is a string."
# Yes
str = 'This is a string.'doSomething = (obj) ->
doSomeAsyncStuff obj, (err, result) ->
# we are not sure about the type of err
# but we know that if it's not `undefined`
# or `null` we need to stop execution.
return console.error err if err?
# we know that it will be some kind of
# object, either plain object or an array.
# (The result is almost always like this from
# our backend requests.)
doSomethingWithResult result if result
# No
callback foo if callback
callback() if callback
# Yes
callback? foo
callback?()# No
if condition then foo() else bar()
# Yes
if condition
then foo()
else bar()# No
unless no
# do something
else
# ...
# Yes
if yes
# do something
else
# ...# No
foo = 'bar' if condition # only one space
doSomething = ->
return unless condition
# Yes
foo = 'bar' if condition # 2 spaces
doSomething = ->
return unless condition # 2 spaces# No
if condition then doSomething()
else if anotherCondition then doSomethingElse()
else if otherCondition then doOtherThing()
else defaultFn()
if condition is 'foo' then doSomething()
else if condition is 'bar' or condition is 'baz' then doSomethingElse()
else if condition is 'qux' then doOtherThing()
else defaultFn()
# Yes
switch
when condition then doSomething()
when anotherCondition then doSomethingElse()
when otherCondition then doOtherThing()
else defaultFn()
switch condition
when 'foo' then doSomething()
when 'bar', 'baz' then doSomethingElse()
when 'qux' then doOtherThing()
else defaultFn()# No
doSomething = () ->
# Yes
doSomething = -># No
doSomething = (foo, bar, rest...)->
# Yes
doSomething = (foo, bar, rest...) -># No
doSomething = (foo,bar,rest...)->
# Yes
doSomething = (foo, bar, rest...) ->KDView = require 'kdf/view'
# No
new KDView {
cssClass : 'bar'
partial : 'View text'
}
# Yes
new KDView
cssClass : 'bar'
partial : 'View text'# No
doSomething = (state) ->
if state
# do something
else
return yes
# Yes
doSomething = (state) ->
return yes unless state
# do something# No
doSomething = ->
result = doThing()
doOtherThing()
result
class Foo
getOptions: -> return @options
# Yes
doSomething = ->
result = doThing()
doOtherThing()
return result
class Foo
getOptions: -> @options
# No
foo: (@bar) ->
# Yes
foo: (bar) -> @bar = bar# No
isGreater = (foo, bar) ->
return foo > bar
someKindOfMethodWithLongName = (foo, bar) -> [foo, bar].map (arg) -> anotherMethod arg
# Yes
isGreater = (foo, bar) -> foo > bar
someKindOfMethodWithLongName = (foo, bar) ->
return [foo, bar].map (arg) -> anotherMethod arg# No
class Foo
doSomething: ->
doSomethingElseWith arguments
# Yes
class Foo
doSomething: (args...) ->
doSomethingElseWith args...
# No
doSomething = ({foo, bar, baz}, qux) ->
# do something with foo, bar, baz
# Yes
doSomething = (obj, qux) ->
{ foo, bar, baz } = obj
# do something with foo, bar, bazIn Koding we wrote most of the codes with classes.
# NO
class Foo extends Bar
doSomething = (foo, bar) -> "#{foo} and #{bar}"
duplicateSomething = (something) -> "#{something}#{something}"
constructor: ->
something = doSomething 'foo', 'bar'
@duplicated = duplicateSomething something
# YES
class Foo Extends Bar
constructor: ->
{ doSomething, duplicateSomething } = helper
something = doSomething 'foo', bar
@duplicated = duplicateSomething something
helper =
doSomething: (foo, bar) -> "#{foo} and #{bar}"
duplicateSomething: (something) -> "#{something}#{something}"
# No
class Foo extends Bar
constructor: (options = {}, data) ->
{ foo, bar } = options
eligible = @isEligible foo, bar
# There is no `this` usage in this method
# So there is no need for it to be an instance
# method.
isEligible: (foo, bar) -> foo and bar
# Yes
class Foo extends Bar
@isEligible: (foo, bar) -> foo and bar
constructor: (options = {}, data) ->
{ foo, bar } = options
eligible = Foo.isEligible foo, bar # better
eligible = helper.isEligible foo, bar # even better, it's just a function
helper =
isEligible: (foo, bar) -> foo and bar
1 - Define static methods 2 - Define instance methods 3 - Define helper methods
class Foo extends Bar
# Static Methods
@staticMethod: -> log 'static method'
# Instance Methods
constructor: (options = {}, data) ->
@options = options
@data = data
getOptions: -> @getOptions
# Helper methods
helper =
transformOptions: (options) -> someTransformation options
# No
slice = Array.prototype.slice
arrayProto = Array::
# Yes
slice = Array::slice
arrayProto = Array.prototypeclass Foo extends Bar
constructor: (options = {}, data) ->
# No
this.options = options
# Yes
@options = options
# No
doSomething: ->
# do things
# ...
return @
# Yes
doSomething: ->
# do things
# ...
return this
class Foo extends Bar
doSomething: (obj) ->
# No
# There is no access to the instance
# or this, so there is no point using fat arrow here.
doAsyncStuff obj, (err, result) => KD.utils.stringify result
# Yes
# Using thin arrow does the job well enough.
doAsyncStuff obj, (err, result) -> KD.utils.stringify result
| Back | FazBrowse Home | New Git URL |