Skip to content

Instantly share code, notes, and snippets.

@dave-burke
Last active March 13, 2023 16:59
Show Gist options
  • Save dave-burke/09676ebe95f0e9edcf900fa8e353a53c to your computer and use it in GitHub Desktop.
Save dave-burke/09676ebe95f0e9edcf900fa8e353a53c to your computer and use it in GitHub Desktop.
Simple comparison of the Airbnb and StandardJs style guides

Simple comparison of the Airbnb and StandardJs style guides

Based on the things I actually care about.

Rule Airbnb Standard
Semicolons Required Never
Trailing Comma Required Never
Re-assign function param Never Allowed
++ Never Allowed
Iterators (for(x of arr)) Never Allowed
console.log Never Allowed
space after function name No Yes
{
"extends": "airbnb-base",
"rules": {
"no-plusplus": ["error", { "allowForLoopAfterthoughts": true }],
"no-console": ["warn"],
"no-restricted-syntax": [
"error",
{
selector: "ForInStatement",
message: "for..in loops iterate over the entire prototype chain, which is virtually never what you want. Use Object.{keys,values,entries}, and iterate over the resulting array.",
},
{
selector: "LabeledStatement",
message: "Labels are a form of GOTO; using them makes code confusing and hard to maintain and understand.",
},
{
selector: "WithStatement",
message: "`with` is disallowed in strict mode because it makes code impossible to predict and optimize.",
}
]
}
}
function add(a, b) {
return a + b;
}
function upper(word) {
const upperWord = word.upperCase();
return upperWord;
}
const words = [
'one',
'two',
'three',
];
const numbers = [1, 2, 3];
words.forEach((word) => upper(word));
for (let i = 0; i < numbers.length; i += 1) {
if (i % 2 === 0) {
add(numbers[i], 1);
}
}
--- airbnb.js 2020-08-21 09:26:31.224780202 -0500
+++ standard.js 2020-08-21 09:28:41.003412758 -0500
@@ -1,24 +1,30 @@
-function add(a, b) {
- return a + b;
+function add (a, b) {
+ return a + b
}
-function upper(word) {
- const upperWord = word.upperCase();
- return upperWord;
+function upper (word) {
+ const upperWord = word.upperCase()
+ return upperWord
}
const words = [
'one',
'two',
- 'three',
-];
+ 'three'
+]
-const numbers = [1, 2, 3];
+const numbers = [1, 2, 3]
-words.forEach((word) => upper(word));
+words.forEach(word => upper(word))
+
+for (const word of words) {
+ upper(word)
+}
for (let i = 0; i < numbers.length; i += 1) {
if (i % 2 === 0) {
- add(numbers[i], 1);
+ add(numbers[i], 1)
}
}
+
+console.log('Done!')
{
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
},
"eslint.validate": ["javascript"]
}
function add (a, b) {
return a + b
}
function upper (word) {
const upperWord = word.upperCase()
return upperWord
}
const words = [
'one',
'two',
'three'
]
const numbers = [1, 2, 3]
words.forEach(word => upper(word))
for (const word of words) {
upper(word)
}
for (let i = 0; i < numbers.length; i += 1) {
if (i % 2 === 0) {
add(numbers[i], 1)
}
}
console.log('Done!')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment