{"id":21003326,"url":"https://github.com/koding/styleguide-coffeescript","last_synced_at":"2025-12-28T22:01:53.547Z","repository":{"id":22173338,"uuid":"25505168","full_name":"koding/styleguide-coffeescript","owner":"koding","description":"This is the guide we use for developing our own apps internally at Koding.","archived":false,"fork":false,"pushed_at":"2016-07-22T18:27:00.000Z","size":16,"stargazers_count":4,"open_issues_count":0,"forks_count":6,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-03-13T14:14:32.606Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/koding.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-10-21T06:01:51.000Z","updated_at":"2016-07-27T22:36:12.000Z","dependencies_parsed_at":"2022-08-20T21:10:47.587Z","dependency_job_id":null,"html_url":"https://github.com/koding/styleguide-coffeescript","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/koding/styleguide-coffeescript","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koding%2Fstyleguide-coffeescript","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koding%2Fstyleguide-coffeescript/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koding%2Fstyleguide-coffeescript/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koding%2Fstyleguide-coffeescript/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/koding","download_url":"https://codeload.github.com/koding/styleguide-coffeescript/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koding%2Fstyleguide-coffeescript/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28104982,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-12-28T02:00:05.685Z","response_time":62,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-19T08:24:48.454Z","updated_at":"2025-12-28T22:01:53.504Z","avatar_url":"https://github.com/koding.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"Koding CoffeeScript Style Guideline\n=======================\n\n### General\n\n- Use 2 __spaces only__ for indentation. Never use tabs. At all!\n- Keep your lines under __80__ characters\n- Do not include any __trailing whitespace__ on any lines.\n\n### Optional Commas\n\n#### Avoid use of commas on multiline object and array definitions.\n\n```coffee\n# No\narr = [\n  'foo',\n  'bar'\n]\n\nobj =\n  foo: bar,\n  baz: qux\n\n# Yes\narr = [\n  'foo'\n  'bar'\n]\n\nobj =\n  foo : bar\n  baz : qux\n```\n\n\n### Blank Lines\n\n#### Leave 2 blank lines at the end of the file.\n\n#### Use 1 blank line between class decleration and the first method (generally constructor)\n\n```coffee\n# No\nclass Foo extends Bar\n  constructor: (options = {}, data) -\u003e # no space at all\n\n    @options = options\n    @data    = data\n\n# Yes\nclass Foo extends Bar\n# 1 \\n\n  constructor: (options = {}, data) -\u003e\n\n    @options = options\n    @data    = data\n```\n\n#### Use exactly 2 blank lines between method/function definitions\n\n```coffee\n# No\nclass Foo extends Bar\n\n  constructor: (options = {}, data) -\u003e\n\n    @options = options\n# 1 \\n\n  getOptions: -\u003e @options\n\n\n# Yes\nclass Foo extends Bar\n\n  constructor: (options = {}, data) -\u003e\n\n    @options = options\n# 1 \\n\n# 2 \\n\n  getOptions: -\u003e @options\n\n\n# Yes\ndoSomething = -\u003e\n\n  bar()\n  baz()\n# 1 \\n\n# 2 \\n\ndoSomething = -\u003e\n\n  qux()\n  fn()\n\n\n```\n\n#### Use 1 blank line after definition of the method/function\n\n```coffee\n# No\ndoSomething = -\u003e\n  bar()\n  baz()\n\n\n# Yes\ndoSomething = -\u003e\n\n  foo()\n  bar()\n```\n\n### Formatting\n\n- Use **only one** space before and after an assignment operator.\n- Use **no** space before and **only one** space after object assignment operator.\n\n```coffee\n# No\nx= 1\ny =2\nz=3\n\n# Yes\nx = 1\ny = 2\nz = 3\n\n# No\nx            = 1\ny            = 2\nlongVariable = 'string'\n\n# Yes\nx = 1\ny = 2\nlongVariable = 'string'\n\n# No\nobj            =\n  var          : 1\n  short        : 2\n  longVariable : 3\n\n# Yes\nobj =\n  var: 1\n  short: 2\n  longVariable: 3\n```\n\n#### Follow idiomatic CoffeeScript practises for expressions, assignments, booleans etc.\n\n```coffee\n# No\nobj  = obj || {}\nbool = condition \u0026\u0026 otherCondition\nisWrong = !right\nexpression = first == second\nexpression = first != second\nbool = true\nbool = false\n\n# Yes\nobj      or= {}\nbool       = condition and otherCondition\nisWrong    = not right\nexpression = first is second\nexpression = first isnt second\nbool       = yes # `on` depending on the context (e.g `isLoggedIn = yes` vs `state = on`)\nbool       = no  # `off` ^^\n```\n\n\n\n### Modules\n\nWe are using `CommonJS` module imports with `Browserify`.\n\n#### Each require statement needs to be on its own line\n\n```coffee\n_      = require 'underscore'\nKDView = require 'kdf/view'\n```\n\nRequire statements should follow the following order:\n\n1 - 3rd Party Library imports\n2 - Internal library/framework imports\n3 - Application specific imports\n\n\n### Parantheses, Curlies, Brackets\n\n#### Omit curly brackets for multiline object definition\n\n```coffee\n# No\nobj = {\n  foo : bar\n  baz : qux\n}\n\n# Yes\nobj =\n  foo : bar\n  baz : qux\n```\n\n#### Use curly brackets for single line object definition\n\n```coffee\n# No\nobj = foo: bar, baz: qux\n\n# Yes\nobj = { foo: bar, baz: qux }\n```\n\n#### Omit paranthesis from the last function call of chain\n\n```coffee\n# No\nfoo('bar')\nfoo().bar('baz', 'qux')\n\n# Yes\nfoo 'bar'\nfoo().bar 'baz', 'qux'\n```\n\n#### Group only the first method in chains with `Lisp-y` way.\n\n```coffee\n# No\nfoo('bar').baz()\nfoo(bar('baz')).qux()\n(foo (bar 'baz'))\n((foo 'bar').baz 'qux').etc()\n(foo 'bar').baz()\n(foo 'bar').baz('qux').etc()\n\n# Yes\nfoo().bar('baz').qux()\nfoo().bar 'baz'\nfoo('bar').baz('qux').etc()\n```\n\n#### Multiline chains\n\n```coffee\n# No\nfoo('bar').baz()\n  .qux()\n\n# Yes\nfoo 'bar'\n  .baz()\n  .qux()\n```\n\n\n# Strings\n\n#### Use string interpolations instead of string concatenation.\n\n```coffee\n# No\nstr = 'This string has ' + variables + 'inside.'\nstr += ' And this is cool.'\n\n# Yes\nstr = \"This string has #{variables} inside.\"\nstr = \"#{str} And this is cool.\"\n```\n\n#### Use single quotes if there is no string interpolation.\n\n```coffee\n# No\nstr = \"This is a string.\"\n\n# Yes\nstr = 'This is a string.'\n```\n\n\n# Conditionals\n\n#### Use existential operator `arg?` in places where you really want to check if a value exists on that variable, and you are not sure about the type. Otherwise do not use existential operator, do the check against variable itself.\n\n```coffee\n\ndoSomething = (obj) -\u003e\n\n  doSomeAsyncStuff obj, (err, result) -\u003e\n\n    # we are not sure about the type of err\n    # but we know that if it's not `undefined`\n    # or `null` we need to stop execution.\n    return console.error err  if err?\n\n    # we know that it will be some kind of\n    # object, either plain object or an array.\n    # (The result is almost always like this from\n    # our backend requests.)\n    doSomethingWithResult result  if result\n\n```\n\n#### Use the existential operator on functions when they need to be called, but only if they exist. This syntax automatically checks the type of the function, avoiding those pesky `foo is not a function` errors.\n\n```coffee\n# No\ncallback foo  if callback\ncallback()    if callback\n\n# Yes\ncallback? foo\ncallback?()\n```\n\n#### Never use single line `if/then/else` statements. Instead use 3 line version of it.\n\n```coffee\n# No\nif condition then foo() else bar()\n\n# Yes\nif condition\nthen foo()\nelse bar()\n```\n\n#### Always use `if/else` over `unless/else`. Never use `unless/else`\n\n```coffee\n# No\nunless no\n  # do something\nelse\n  # ...\n\n# Yes\nif yes\n  # do something\nelse\n  # ...\n```\n\n#### Use 2 spaces before post conditionals\n\n```coffee\n# No\nfoo = 'bar' if condition # only one space\n\ndoSomething = -\u003e\n\n  return unless condition\n\n# Yes\nfoo = 'bar'  if condition # 2 spaces\n\ndoSomething = -\u003e\n\n  return  unless condition # 2 spaces\n```\n\n#### Use `switch` over `if/else if` for 1 line multi conditions. Align `then` statements if single line.\n\n```coffee\n# No\nif condition then doSomething()\nelse if anotherCondition then doSomethingElse()\nelse if otherCondition then doOtherThing()\nelse defaultFn()\n\nif condition is 'foo' then doSomething()\nelse if condition is 'bar' or condition is 'baz' then doSomethingElse()\nelse if condition is 'qux' then doOtherThing()\nelse defaultFn()\n\n# Yes\nswitch\n  when condition        then doSomething()\n  when anotherCondition then doSomethingElse()\n  when otherCondition   then doOtherThing()\n  else defaultFn()\n\nswitch condition\n  when 'foo'        then doSomething()\n  when 'bar', 'baz' then doSomethingElse()\n  when 'qux'        then doOtherThing()\n  else defaultFn()\n```\n\n\n### Functions\n\n#### Don't use parens functions that has empty arguments list\n\n```coffee\n# No\ndoSomething = () -\u003e\n\n# Yes\ndoSomething = -\u003e\n```\n\n#### Use 1 space between closing parenthesis of arguments list and function arrow.\n\n```coffee\n# No\ndoSomething = (foo, bar, rest...)-\u003e\n\n# Yes\ndoSomething = (foo, bar, rest...) -\u003e\n```\n\n#### Use 1 space after comma between arguments.\n\n```coffee\n# No\ndoSomething = (foo,bar,rest...)-\u003e\n\n# Yes\ndoSomething = (foo, bar, rest...) -\u003e\n```\n\n#### Omit curly brackets if argument is a multiline object\n\n```coffee\nKDView = require 'kdf/view'\n\n# No\nnew KDView {\n  cssClass : 'bar'\n  partial  : 'View text'\n}\n\n# Yes\nnew KDView\n  cssClass : 'bar'\n  partial  : 'View text'\n```\n\n#### Use early returns over big `if/else` blocks, to avoid nesting.\n\n```coffee\n# No\ndoSomething = (state) -\u003e\n\n  if state\n    # do something\n  else\n    return yes\n\n# Yes\ndoSomething = (state) -\u003e\n\n  return yes  unless state\n\n  # do something\n```\n\n#### Omit `return` keyword __only__ for 1 line functions. Use `return` every where else.\n\n```coffee\n# No\ndoSomething = -\u003e\n\n  result = doThing()\n  doOtherThing()\n\n  result\n\nclass Foo\n\n  getOptions: -\u003e return @options\n\n# Yes\ndoSomething = -\u003e\n\n  result = doThing()\n  doOtherThing()\n\n  return result\n\nclass Foo\n\n  getOptions: -\u003e @options\n\n```\n\n#### Do not use `@` with arguments to cut across if the method is a setter.\n\n```coffee\n# No\nfoo: (@bar) -\u003e\n\n# Yes\nfoo: (bar) -\u003e @bar = bar\n```\n\n#### Write method definition and method body on the same line if method body contains only one line. Only exception is when it is against `80 characters per line rule`.\n\n```coffee\n# No\nisGreater = (foo, bar) -\u003e\n\n  return foo \u003e bar\n\nsomeKindOfMethodWithLongName = (foo, bar) -\u003e [foo, bar].map (arg) -\u003e anotherMethod arg\n\n# Yes\nisGreater = (foo, bar) -\u003e foo \u003e bar\n\nsomeKindOfMethodWithLongName = (foo, bar) -\u003e\n\n  return [foo, bar].map (arg) -\u003e anotherMethod arg\n```\n\n#### Do not use `arguments`, use splat (`args...`) operator instead.\n\n```coffee\n# No\nclass Foo\n\n  doSomething: -\u003e\n\n    doSomethingElseWith arguments\n\n# Yes\nclass Foo\n\n  doSomething: (args...) -\u003e\n\n    doSomethingElseWith args...\n\n```\n\n#### Do not destruct properties on arguments list. Instead destruct necessary arguments inside function body.\n\n```coffee\n# No\ndoSomething = ({foo, bar, baz}, qux) -\u003e\n  # do something with foo, bar, baz\n\n# Yes\ndoSomething = (obj, qux) -\u003e\n\n  { foo, bar, baz } = obj\n  # do something with foo, bar, baz\n```\n\n\n### Classes\n\nIn Koding we wrote most of the codes with classes.\n\n#### Group helper/private methods in a private object called `helper`\n\n```coffee\n# NO\nclass Foo extends Bar\n\n  doSomething        = (foo, bar) -\u003e \"#{foo} and #{bar}\"\n  duplicateSomething = (something) -\u003e \"#{something}#{something}\"\n\n  constructor: -\u003e\n    something   = doSomething 'foo', 'bar'\n    @duplicated = duplicateSomething something\n\n# YES\nclass Foo Extends Bar\n\n  constructor: -\u003e\n\n    { doSomething, duplicateSomething } = helper\n\n    something   = doSomething 'foo', bar\n    @duplicated = duplicateSomething something\n\n\n  helper =\n    doSomething: (foo, bar) -\u003e \"#{foo} and #{bar}\"\n    duplicateSomething: (something) -\u003e \"#{something}#{something}\"\n\n```\n\n#### Use static methods or even private methods for methods that don't depend on `this` context. Do not use instance methods for those kind of methods.\n\n```coffee\n# No\nclass Foo extends Bar\n\n  constructor: (options = {}, data) -\u003e\n\n    { foo, bar } = options\n\n    eligible = @isEligible foo, bar\n\n  # There is no `this` usage in this method\n  # So there is no need for it to be an instance\n  # method.\n  isEligible: (foo, bar) -\u003e foo and bar\n\n# Yes\nclass Foo extends Bar\n\n  @isEligible: (foo, bar) -\u003e foo and bar\n\n  constructor: (options = {}, data) -\u003e\n\n    { foo, bar } = options\n\n    eligible = Foo.isEligible foo, bar # better\n    eligible = helper.isEligible foo, bar # even better, it's just a function\n\n  helper =\n    isEligible: (foo, bar) -\u003e foo and bar\n\n```\n\n#### Define different types of methods in the following order:\n\n  1 - Define `static` methods\n  2 - Define `instance` methods\n  3 - Define `helper` methods\n\n```coffee\nclass Foo extends Bar\n\n  # Static Methods\n  @staticMethod: -\u003e log 'static method'\n\n\n  # Instance Methods\n  constructor: (options = {}, data) -\u003e\n\n    @options = options\n    @data    = data\n\n\n  getOptions: -\u003e @getOptions\n\n\n  # Helper methods\n  helper =\n    transformOptions: (options) -\u003e someTransformation options\n\n\n```\n\n#### Use shorthand syntax for accesing prototype properties. Use direct access when dealing the `prototype` object itself.\n\n```coffee\n# No\nslice      = Array.prototype.slice\narrayProto = Array::\n\n# Yes\nslice      = Array::slice\narrayProto = Array.prototype\n```\n\n#### Use `@property` instead of `this.property`. Avoid using standalone `@`.\n\n```coffee\nclass Foo extends Bar\n\n  constructor: (options = {}, data) -\u003e\n\n    # No\n    this.options = options\n\n    # Yes\n    @options = options\n\n  # No\n  doSomething: -\u003e\n    # do things\n    # ...\n\n    return @\n\n  # Yes\n  doSomething: -\u003e\n    # do things\n    # ...\n\n    return this\n\n```\n\n#### Be careful with __fat arrows__. As they produce extra code, and tries to bind `this` into that method, if you know that you will not use context in that method, DO NOT USE fat arrows.\n\n```coffee\nclass Foo extends Bar\n\n  doSomething: (obj) -\u003e\n\n    # No\n    # There is no access to the instance\n    # or this, so there is no point using fat arrow here.\n    doAsyncStuff obj, (err, result) =\u003e KD.utils.stringify result\n\n    # Yes\n    # Using thin arrow does the job well enough.\n    doAsyncStuff obj, (err, result) -\u003e KD.utils.stringify result\n\n\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkoding%2Fstyleguide-coffeescript","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkoding%2Fstyleguide-coffeescript","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkoding%2Fstyleguide-coffeescript/lists"}