From bcaeafdf8c837af621e39e0b139924f67e641c29 Mon Sep 17 00:00:00 2001 From: Nicolas Mercier Date: Sun, 12 Feb 2017 12:43:23 -0500 Subject: [PATCH 1/6] Eliminated semis --- snippets/async.cson | 6 +++--- snippets/bdd.cson | 20 ++++++++++---------- snippets/classes.cson | 4 ++-- snippets/dom.cson | 2 +- snippets/flow-control.cson | 4 ++-- snippets/functions.cson | 2 +- snippets/iterables.cson | 10 +++++----- snippets/misc.cson | 2 +- snippets/modules.cson | 8 ++++---- snippets/node-events.cson | 2 +- snippets/node-express.cson | 4 ++-- snippets/node-modules.cson | 10 +++++----- snippets/return.cson | 18 +++++++++--------- snippets/timers.cson | 8 ++++---- 14 files changed, 50 insertions(+), 50 deletions(-) diff --git a/snippets/async.cson b/snippets/async.cson index 6ef6cd9..72dbf23 100644 --- a/snippets/async.cson +++ b/snippets/async.cson @@ -1,6 +1,6 @@ ".source.js, .source.ts, .source.tsx, .source.js-semantic": "Node callback": - prefix: "cb" + prefix: "cbf" body: "function (err, ${1:value}) {${0}}" "Promise": prefix: "p", @@ -14,7 +14,7 @@ body: """ ${1:promise}.then(${2:value} => { \t${0} - }); + }) """ "chain then": prefix: ".then" @@ -24,7 +24,7 @@ body: """ ${1:promise}.catch(${2:err} => { \t${0} - }); + }) """ "chain catch": prefix: ".catch" diff --git a/snippets/bdd.cson b/snippets/bdd.cson index b5535b9..da21d4d 100644 --- a/snippets/bdd.cson +++ b/snippets/bdd.cson @@ -4,62 +4,62 @@ body: """ describe('${1:description}', function () { \t${0} - }); + }) """ "context": prefix: "cont" body: """ context('${1:description}', function () { \t${0} - }); + }) """ "it": prefix: "it" body: """ it('${1:description}', function () { \t${0} - }); + }) """ "it synchronous": prefix: "its" body: """ it('${1:description}', function () { \t${0} - }); + }) """ "it asynchronous": prefix: "ita" body: """ it('${1:description}', function (done) { \t${0} - \tdone(); - }); + \tdone() + }) """ "mocha before": prefix: "bf" body: """ before(function () { \t${0} - }); + }) """ "mocha beforeEach": prefix: "bfe" body: """ beforeEach(function () { \t${0} - }); + }) """ "mocha after": prefix: "aft" body: """ after(function () { \t${0} - }); + }) """ "mocha afterEach": prefix: "afe" body: """ afterEach(function () { \t${0} - }); + }) """ diff --git a/snippets/classes.cson b/snippets/classes.cson index ac2de4b..17743b1 100644 --- a/snippets/classes.cson +++ b/snippets/classes.cson @@ -13,7 +13,7 @@ body: """ class ${1:name} extends ${2:base} { \tconstructor(${3:arguments}) { - \t\tsuper(${3:arguments}); + \t\tsuper(${3:arguments}) \t\t${0} \t} } @@ -22,6 +22,6 @@ prefix: "ctor" body: """ constructor(${1:arguments}) { - \tsuper(${1:arguments});${0} + \tsuper(${1:arguments})${0} } """ diff --git a/snippets/dom.cson b/snippets/dom.cson index 33e1e50..9ca906e 100644 --- a/snippets/dom.cson +++ b/snippets/dom.cson @@ -4,7 +4,7 @@ body: """ ${1:document}.addEventListener('${2:event}', ${3:ev} => { \t${0} - }); + }) """ "getElementById": "prefix": "gi" diff --git a/snippets/flow-control.cson b/snippets/flow-control.cson index 56200b9..c69b1cd 100644 --- a/snippets/flow-control.cson +++ b/snippets/flow-control.cson @@ -93,8 +93,8 @@ body: """ switch (${1:expr}) { \tcase ${2:value}: - \t\treturn $0; + \t\treturn $0 \tdefault: - \t\treturn; + \t\treturn } """ diff --git a/snippets/functions.cson b/snippets/functions.cson index 2a85e54..1e8e121 100644 --- a/snippets/functions.cson +++ b/snippets/functions.cson @@ -14,7 +14,7 @@ body: """ (function (${1:arguments}) { \t${0} - })(${2}); + })(${2}) """ "function apply": prefix: "fa" diff --git a/snippets/iterables.cson b/snippets/iterables.cson index dca744a..bfd323d 100644 --- a/snippets/iterables.cson +++ b/snippets/iterables.cson @@ -9,7 +9,7 @@ body: """ ${1:iterable}.forEach((${2:item}) => { \t${0} - }); + }) """ "chain forEach": prefix: ".fe" @@ -19,7 +19,7 @@ body: """ ${1:iterable}.map((${2:item}) => { \t${0} - }); + }) """ "chain map": prefix: ".map" @@ -29,7 +29,7 @@ body: """ ${1:iterable}.reduce((${2:previous}, ${3:current}) => { \t${0} - }${4:, initial}); + }${4:, initial}) """ "chain reduce": prefix: ".reduce" @@ -39,7 +39,7 @@ body: """ ${1:iterable}.filter((${2:item}) => { \t${0} - }); + }) """ "chain filter": prefix: ".filter" @@ -49,7 +49,7 @@ body: """ ${1:iterable}.find((${2:item}) => { \t${0} - }); + }) """ "chain find": prefix: ".find" diff --git a/snippets/misc.cson b/snippets/misc.cson index 14abe10..929b026 100644 --- a/snippets/misc.cson +++ b/snippets/misc.cson @@ -1,4 +1,4 @@ ".source.js, .source.ts, .source.tsx, .source.js-semantic": "use strict": prefix: "us" - body: "'use strict';" + body: "'use strict'" diff --git a/snippets/modules.cson b/snippets/modules.cson index e2d92f2..a3089b6 100644 --- a/snippets/modules.cson +++ b/snippets/modules.cson @@ -1,13 +1,13 @@ ".source.js, .source.ts, .source.tsx, .source.js-semantic": "module export": prefix: "ex" - body: "export ${1:member};" + body: "export ${1:member}" "module default export": prefix: "exd" - body: "export default ${1:member};" + body: "export default ${1:member}" "import module": prefix: "im" - body: "import ${1:*} from '${2:module}';" + body: "import ${1:*} from '${2:module}'" "import module as": prefix: "ima" - body: "import ${1:*} as ${2:name} from '${3:module}';" + body: "import ${1:*} as ${2:name} from '${3:module}'" diff --git a/snippets/node-events.cson b/snippets/node-events.cson index 2b5e4e0..f391cd0 100644 --- a/snippets/node-events.cson +++ b/snippets/node-events.cson @@ -4,7 +4,7 @@ body: """ ${1:emitter}.on('${2:event}', (${3:arguments}) => { \t${0} - }); + }) """ "chain event handler": prefix: ".on" diff --git a/snippets/node-express.cson b/snippets/node-express.cson index 435e02b..f6b1684 100644 --- a/snippets/node-express.cson +++ b/snippets/node-express.cson @@ -2,14 +2,14 @@ "Express middleware": prefix: "xm" body: """ - function (req, res${1:, next}) { + (req, res${1:, next}) => { \t${0} } """ "Express error handler": prefix: "xerr" body: """ - function (err, req, res, next) { + (err, req, res, next) => { \t${0} } """ diff --git a/snippets/node-modules.cson b/snippets/node-modules.cson index 47b4bf7..a010f09 100644 --- a/snippets/node-modules.cson +++ b/snippets/node-modules.cson @@ -4,10 +4,10 @@ body: "require('${1:module}')" "exports.member": prefix: "em" - body: "exports.${1:member} = ${2:value};" + body: "exports.${1:member} = ${2:value}" "module.exports": prefix: "me" - body: "module.exports = ${1:name};" + body: "module.exports = ${1:name}" "module as class": prefix: "mc" body: """ @@ -15,8 +15,8 @@ \tfunction ${1:name}(${2:arguments}) { \t\t${0} \t} - \treturn ${1:name}; - })(); + \treturn ${1:name} + })() - module.exports = ${1:name}; + module.exports = ${1:name} """ diff --git a/snippets/return.cson b/snippets/return.cson index a43f9a9..3d55e0e 100644 --- a/snippets/return.cson +++ b/snippets/return.cson @@ -1,36 +1,36 @@ ".source.js, .source.ts, .source.tsx, .source.js-semantic": "return": prefix: "r" - body: "return ${0};" + body: "return ${0}" "return this": prefix: "rth" - body: "return this;" + body: "return this" "return null": prefix: "rn" - body: "return null;" + body: "return null" "return true": prefix: "rt" - body: "return true;" + body: "return true" "return false": prefix: "rf" - body: "return false;" + body: "return false" "return 0": prefix: "r0" - body: "return 0;" + body: "return 0" "return -1": prefix: "r-1" - body: "return -1;" + body: "return -1" "return complex value": prefix: "rc" body: """ return ( \t${0} - ); + ) """ "return promise": prefix: "rp" body: """ return new Promise((resolve, reject) => { \t${0} - }); + }) """ diff --git a/snippets/timers.cson b/snippets/timers.cson index b99b8cc..39b25f9 100644 --- a/snippets/timers.cson +++ b/snippets/timers.cson @@ -4,26 +4,26 @@ body: """ setTimeout(() => { \t${0} - }, ${1:delay}); + }, ${1:delay}) """ "setInterval": prefix: "si" body: """ setInterval(() => { \t${0} - }, ${1:delay}); + }, ${1:delay}) """ "setImmediate": prefix: "sim" body: """ setImmediate(() => { \t${0} - }); + }) """ "process nextTick": prefix: "nt" body: """ process.nextTick(() => { \t${1:} - }); + }) """ From 8b14531af90192a04316527a332028d536857131 Mon Sep 17 00:00:00 2001 From: Nicolas Mercier Date: Sun, 12 Feb 2017 12:46:22 -0500 Subject: [PATCH 2/6] Use `c` for const instead of classes, which should be more common --- snippets/classes.cson | 4 ++-- snippets/declarations.cson | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/snippets/classes.cson b/snippets/classes.cson index 17743b1..7a0536a 100644 --- a/snippets/classes.cson +++ b/snippets/classes.cson @@ -1,6 +1,6 @@ ".source.js, .source.ts, .source.tsx, .source.js-semantic": "class": - prefix: "c" + prefix: "cla" body: """ class ${1:name} { \tconstructor(${2:arguments}) { @@ -9,7 +9,7 @@ } """ "class extends": - prefix: "cex" + prefix: "clax" body: """ class ${1:name} extends ${2:base} { \tconstructor(${3:arguments}) { diff --git a/snippets/declarations.cson b/snippets/declarations.cson index 82b672b..109f20a 100644 --- a/snippets/declarations.cson +++ b/snippets/declarations.cson @@ -12,8 +12,8 @@ prefix: "l=" body: "let ${1:name} = ${2:value}" "const statement": - prefix: "co" + prefix: "c" body: "const ${1:name}" "const assignment": - prefix: "co=" + prefix: "c=" body: "const ${1:name} = ${2:value}" From 10bbf0a45141b63b06454a74ab223f5958325725 Mon Sep 17 00:00:00 2001 From: Nicolas Mercier Date: Mon, 13 Feb 2017 18:32:34 -0500 Subject: [PATCH 3/6] Refactored snippets according to the latest airbnb javascript guide https://github.com/airbnb/javascript --- snippets/declarations.cson | 6 ----- snippets/functions.cson | 48 +++++++++++++++----------------------- snippets/modules.cson | 8 +++---- snippets/objects.cson | 14 ----------- 4 files changed, 23 insertions(+), 53 deletions(-) diff --git a/snippets/declarations.cson b/snippets/declarations.cson index 109f20a..28238b2 100644 --- a/snippets/declarations.cson +++ b/snippets/declarations.cson @@ -1,10 +1,4 @@ ".source.js, .source.ts, .source.tsx, .source.js-semantic": - "var statement": - prefix: "v" - body: "var ${1:name}" - "var assignment": - prefix: "v=" - body: "var ${1:name} = ${2:value}" "let statement": prefix: "l" body: "let ${1:name}" diff --git a/snippets/functions.cson b/snippets/functions.cson index 1e8e121..72abf28 100644 --- a/snippets/functions.cson +++ b/snippets/functions.cson @@ -1,7 +1,17 @@ ".source.js, .source.ts, .source.tsx, .source.js-semantic": "anonymous function": prefix: "f" - body: "function (${1:arguments}) {${0}}" + body: "(${1:arguments}) => {${0}}" + "function with body": + prefix: "fb" + body: """ + (${1:arguments}) => { + \t${0} + } + """ + "async anonymous function": + prefix: "af" + body: "async (${1:arguments}) => {${0}}" "named function": prefix: "fn" body: """ @@ -9,6 +19,13 @@ \t${0} } """ + "async function": + prefix: "afn" + body: """ + async function ${1:name}(${2:arguments}) { + \t${0} + } + """ "immediately-invoked function expression": prefix: "iife" body: """ @@ -16,34 +33,7 @@ \t${0} })(${2}) """ - "function apply": - prefix: "fa" - body: """ - ${1:fn}.apply(${2:this}, ${3:arguments}) - """ - "function call": - prefix: "fc" - body: """ - ${1:fn}.call(${2:this}, ${3:arguments}) - """ - "function bind": - prefix: "fb" - body: """ - ${1:fn}.bind(${2:this}, ${3:arguments}) - """ - "arrow function": - prefix: "af" - body: """ - (${1:arguments}) => ${2:statement} - """ - "arrow function with body": - prefix: "afb" - body: """ - (${1:arguments}) => { - \t${0} - } - """ - "generator": + "generator": prefix: "gf" body: """ function* (${1:arguments}) { diff --git a/snippets/modules.cson b/snippets/modules.cson index a3089b6..4645d06 100644 --- a/snippets/modules.cson +++ b/snippets/modules.cson @@ -7,7 +7,7 @@ body: "export default ${1:member}" "import module": prefix: "im" - body: "import ${1:*} from '${2:module}'" - "import module as": - prefix: "ima" - body: "import ${1:*} as ${2:name} from '${3:module}'" + body: "import ${1:module} from '${1:module}'" + "import local module": + prefix: "iml" + body: "import ${1:module} from './${2:path}'" diff --git a/snippets/objects.cson b/snippets/objects.cson index db185b6..b70adc9 100644 --- a/snippets/objects.cson +++ b/snippets/objects.cson @@ -33,20 +33,6 @@ \t } """ - "prototype method": - prefix: "proto" - body: """ - ${1:Class}.prototype.${2:method} = function (${3:arguments}) { - \t${0} - }; - """ - "chain prototype method": - prefix: ".proto" - body: """ - .prototype.${2:methodName} = function (${3:arguments}) { - \t${0} - } - """ "Object.assign": prefix: "a" body: "Object.assign(${1:dest}, ${2:source})" From 64df05571996d2174e791b40527c675db74410ff Mon Sep 17 00:00:00 2001 From: Nicolas Mercier Date: Tue, 14 Feb 2017 14:41:37 -0500 Subject: [PATCH 4/6] Cleanup existing snippets --- snippets/async.cson | 7 ++----- snippets/bdd.cson | 11 ++--------- snippets/dom.cson | 20 ++++++++++---------- snippets/objects.cson | 2 +- 4 files changed, 15 insertions(+), 25 deletions(-) diff --git a/snippets/async.cson b/snippets/async.cson index 72dbf23..52180f0 100644 --- a/snippets/async.cson +++ b/snippets/async.cson @@ -1,7 +1,4 @@ ".source.js, .source.ts, .source.tsx, .source.js-semantic": - "Node callback": - prefix: "cbf" - body: "function (err, ${1:value}) {${0}}" "Promise": prefix: "p", body: """ @@ -16,7 +13,7 @@ \t${0} }) """ - "chain then": + "chain Promise.then": prefix: ".then" body: ".then(${1:value} => {${0}})" "Promise.catch": @@ -26,6 +23,6 @@ \t${0} }) """ - "chain catch": + "chain Promise.catch": prefix: ".catch" body: ".catch(${1:err} => {${0}})" diff --git a/snippets/bdd.cson b/snippets/bdd.cson index da21d4d..b6cb166 100644 --- a/snippets/bdd.cson +++ b/snippets/bdd.cson @@ -20,15 +20,8 @@ \t${0} }) """ - "it synchronous": - prefix: "its" - body: """ - it('${1:description}', function () { - \t${0} - }) - """ - "it asynchronous": - prefix: "ita" + "it with callback": + prefix: "itc" body: """ it('${1:description}', function (done) { \t${0} diff --git a/snippets/dom.cson b/snippets/dom.cson index 9ca906e..347003c 100644 --- a/snippets/dom.cson +++ b/snippets/dom.cson @@ -7,17 +7,17 @@ }) """ "getElementById": - "prefix": "gi" - "body": "${1:document}.getElementById('${2:id}')" + prefix: "gi" + body: "${1:document}.getElementById('${2:id}')" "getElementsByClassName": - "prefix": "gc" - "body": "Array.from(${1:document}.getElementsByClassName('${2:class}'))" + prefix: "gc" + body: "Array.from(${1:document}.getElementsByClassName('${2:class}'))" "getElementsByTagName": - "prefix": "gt" - "body": "Array.from(${1:document}.getElementsByTagName('${2:tag}'))" + prefix: "gt" + body: "Array.from(${1:document}.getElementsByTagName('${2:tag}'))" "querySelector": - "prefix": "qs" - "body": "${1:document}.querySelector('${2:selector}')" + prefix: "qs" + body: "${1:document}.querySelector('${2:selector}')" "querySelectorAll": - "prefix": "qsa" - "body": "Array.from(${1:document}.querySelectorAll('${2:selector}'))" + prefix: "qsa" + body: "Array.from(${1:document}.querySelectorAll('${2:selector}'))" diff --git a/snippets/objects.cson b/snippets/objects.cson index b70adc9..1c4710c 100644 --- a/snippets/objects.cson +++ b/snippets/objects.cson @@ -36,6 +36,6 @@ "Object.assign": prefix: "a" body: "Object.assign(${1:dest}, ${2:source})" - "Object.assign copy": + "Object.assign clone": prefix: "ac" body: "Object.assign({}, ${1:original}, ${2:source})" From 695d3cfbefde684bee36adebd3b989c96552bfb9 Mon Sep 17 00:00:00 2001 From: Nicolas Mercier Date: Tue, 14 Feb 2017 14:41:51 -0500 Subject: [PATCH 5/6] Reworked class snippets --- snippets/classes.cson | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/snippets/classes.cson b/snippets/classes.cson index 7a0536a..16387dc 100644 --- a/snippets/classes.cson +++ b/snippets/classes.cson @@ -1,6 +1,6 @@ ".source.js, .source.ts, .source.tsx, .source.js-semantic": "class": - prefix: "cla" + prefix: "class" body: """ class ${1:name} { \tconstructor(${2:arguments}) { @@ -9,7 +9,7 @@ } """ "class extends": - prefix: "clax" + prefix: "classx" body: """ class ${1:name} extends ${2:base} { \tconstructor(${3:arguments}) { From aae58858c5742ab9f8f61075f936530173822582 Mon Sep 17 00:00:00 2001 From: Nicolas Mercier Date: Tue, 14 Feb 2017 14:41:59 -0500 Subject: [PATCH 6/6] Moved node callback --- snippets/functions.cson | 3 +++ 1 file changed, 3 insertions(+) diff --git a/snippets/functions.cson b/snippets/functions.cson index 72abf28..d886957 100644 --- a/snippets/functions.cson +++ b/snippets/functions.cson @@ -26,6 +26,9 @@ \t${0} } """ + "Node callback": + prefix: "cbf" + body: "(err, ${1:value}) => {${0}}" "immediately-invoked function expression": prefix: "iife" body: """