Skip to content

Instantly share code, notes, and snippets.

@alystair
Last active March 6, 2021 00:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alystair/9c393edef88d2bd8d1d6004e0f7db853 to your computer and use it in GitHub Desktop.
Save alystair/9c393edef88d2bd8d1d6004e0f7db853 to your computer and use it in GitHub Desktop.
Punctuation-first style (comma first style)
function foo() {
const target = document.getElementById('menu')
, debugTarget = document.getElementById('debugMenu')
, roles = document.body.classList;
return randomBool
? someFunction()
: someOtherFunction();
}
let obj = {
foo: 123
, bar: [4,5,6]
, someDef: 'someString'
, anotherLongProperty: 'fizz buzz'
, fizz(){
return true;
}
, buzz(){
return false;
}
};
@alystair
Copy link
Author

alystair commented May 4, 2020

Benefits

  • Easily spot missing marks visually without IDE
  • I think it looks cleaner 👍

Enforcement

To enforce this style using eslint add the following to your .eslintrc: "comma-style":[2,"first"]

Gotchas

  • Many (if not all) IDEs ignore docblocks before functions in a list, as the comma comes after the docblock, but before the function name :/
  • Haters will hate 🔥

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment