diff --git a/ftplugin/javascript.vim b/ftplugin/javascript.vim index 93c0df25..1b25d6a5 100644 --- a/ftplugin/javascript.vim +++ b/ftplugin/javascript.vim @@ -23,7 +23,7 @@ let b:doge_patterns = [] " Matches the following pattern: " : = -let s:parameters_match_pattern = '\m\%(\%(public\|private\|protected\)\?\s*\)\?\([[:alnum:]_$]\+\)\%(\s*:\s*\([[:alnum:][:space:]._|]\+\%(\[[[:alnum:][:space:]_[\],]*\]\)\?\)\)\?\%(\s*=\s*\([^,]\+\)\+\)\?' +let s:parameters_match_pattern = '\m\%(\%(public\|private\|protected\)\?\s*\)\?\([[:alnum:]_$]\+\)\%(\s*:\s*\([[:alnum:][:space:]._|]\+\%(\[[[:alnum:][:space:]_[\],]*\]\)\?\)\)\?\%(\s*=\s*\([[:alnum:]_.]\+(.\{-})\|[^,]\+\)\+\)\?' " ============================================================================== " Matches fat-arrow / functions inside objects. @@ -45,7 +45,7 @@ call add(b:doge_patterns, { \ 'match': s:parameters_match_pattern, \ 'match_group_names': ['name', 'type'], \ 'format': { -\ 'jsdoc': '@param {{type|!type}} {name} !description', +\ 'jsdoc': '@param {{type|!type}} {name} - !description', \ }, \ }, \ 'comment': { @@ -54,7 +54,6 @@ call add(b:doge_patterns, { \ 'jsdoc': [ \ '/**', \ ' * !description', -\ ' *', \ '%(async| * @{async})%', \ ' * @function {funcName|}', \ '%(parameters| * {parameters})%', @@ -87,7 +86,6 @@ call add(b:doge_patterns, { \ 'jsdoc': [ \ '/**', \ ' * !description', -\ ' *', \ '%(parentClassName| * @extends {parentClassName})%', \ '%(interfaceName| * @implements {interfaceName})%', \ ' */', @@ -119,7 +117,7 @@ call add(b:doge_patterns, { \ 'match': s:parameters_match_pattern, \ 'match_group_names': ['name', 'type'], \ 'format': { -\ 'jsdoc': '@param {{type|!type}} {name} !description', +\ 'jsdoc': '@param {{type|!type}} {name} - !description', \ }, \ }, \ 'comment': { @@ -128,7 +126,6 @@ call add(b:doge_patterns, { \ 'jsdoc': [ \ '/**', \ ' * !description', -\ ' *', \ '%(async| * @{async})%', \ '%(parameters| * {parameters})%', \ '%(returnType| * @return {{returnType}} !description)%', @@ -156,7 +153,7 @@ call add(b:doge_patterns, { \ 'match': s:parameters_match_pattern, \ 'match_group_names': ['name', 'type'], \ 'format': { -\ 'jsdoc': '@param {{type|!type}} {name} !description', +\ 'jsdoc': '@param {{type|!type}} {name} - !description', \ }, \ }, \ 'comment': { @@ -165,7 +162,6 @@ call add(b:doge_patterns, { \ 'jsdoc': [ \ '/**', \ ' * !description', -\ ' *', \ '%(async| * @{async})%', \ ' * @function {className}#{funcName}', \ '%(parameters| * {parameters})%', @@ -206,7 +202,7 @@ call add(b:doge_patterns, { \ 'match': s:parameters_match_pattern, \ 'match_group_names': ['name', 'type'], \ 'format': { -\ 'jsdoc': '@param {{type|!type}} {name} !description', +\ 'jsdoc': '@param {{type|!type}} {name} - !description', \ }, \ }, \ 'comment': { @@ -215,7 +211,6 @@ call add(b:doge_patterns, { \ 'jsdoc': [ \ '/**', \ ' * !description', -\ ' *', \ '%(async| * @{async})%', \ ' * @function {funcName|}', \ '%(parameters| * {parameters})%', diff --git a/ftplugin/typescript.vim b/ftplugin/typescript.vim index de69c8a7..df53c6fd 100644 --- a/ftplugin/typescript.vim +++ b/ftplugin/typescript.vim @@ -26,7 +26,7 @@ let b:doge_patterns = [] " Matches the following pattern: " : = -let s:parameters_match_pattern = '\m\%(\%(public\|private\|protected\)\?\s*\)\?\([[:alnum:]_$]\+\)\%(\s*:\s*\([[:alnum:][:space:]._|]\+\%(\[[[:alnum:][:space:]_[\],]*\]\)\?\)\)\?\%(\s*=\s*\([^,]\+\)\+\)\?' +let s:parameters_match_pattern = '\m\%(\%(public\|private\|protected\)\?\s*\)\?\([[:alnum:]_$]\+\)\%(\s*:\s*\([[:alnum:][:space:]._|]\+\%(\[[[:alnum:][:space:]_[\],]*\]\)\?\)\)\?\%(\s*=\s*\([[:alnum:]_.]\+(.\{-})\|[^,]\+\)\+\)\?' " ============================================================================== " Matches fat-arrow / functions inside objects. @@ -42,13 +42,13 @@ let s:parameters_match_pattern = '\m\%(\%(public\|private\|protected\)\?\s*\)\?\ " " myKey: async (p1, p2) => {} call add(b:doge_patterns, { -\ 'match': '\m^\([[:alnum:]_]\+\)\s*:\s*\(async\)\?\%(function\)\?\s*\%([[:alnum:]_]\+\)\?(\(.\{-}\))\%(\s*:\s*(\?\([[:alnum:][:space:]_[\].,|<>]\+\))\?\)\?\%(\s*=>\s*\)\?\s*[({]', +\ 'match': '\m^[[:punct:]]\?\([[:alnum:]_-]\+\)[[:punct:]]\?\s*:\s*\(async\)\?\s*\%(function\)\?\s*\%([[:alnum:]_]\+\)\?(\(.\{-}\))\%(\s*:\s*(\?\([[:alnum:][:space:]_[\].,|<>]\+\))\?\)\?\%(\s*=>\s*\)\?\s*[({]', \ 'match_group_names': ['funcName', 'async', 'parameters', 'returnType'], \ 'parameters': { \ 'match': s:parameters_match_pattern, \ 'match_group_names': ['name', 'type'], \ 'format': { -\ 'jsdoc': '@param {{type|!type}} {name} !description', +\ 'jsdoc': '@param {{type|!type}} {name} - !description', \ }, \ }, \ 'comment': { @@ -57,7 +57,6 @@ call add(b:doge_patterns, { \ 'jsdoc': [ \ '/**', \ ' * !description', -\ ' *', \ '%(async| * @{async})%', \ ' * @function {funcName|}', \ '%(parameters| * {parameters})%', @@ -90,7 +89,6 @@ call add(b:doge_patterns, { \ 'jsdoc': [ \ '/**', \ ' * !description', -\ ' *', \ '%(parentClassName| * @extends {parentClassName})%', \ '%(interfaceName| * @implements {interfaceName})%', \ ' */', @@ -122,7 +120,7 @@ call add(b:doge_patterns, { \ 'match': s:parameters_match_pattern, \ 'match_group_names': ['name', 'type'], \ 'format': { -\ 'jsdoc': '@param {{type|!type}} {name} !description', +\ 'jsdoc': '@param {{type|!type}} {name} - !description', \ }, \ }, \ 'comment': { @@ -131,7 +129,6 @@ call add(b:doge_patterns, { \ 'jsdoc': [ \ '/**', \ ' * !description', -\ ' *', \ '%(async| * @{async})%', \ '%(parameters| * {parameters})%', \ '%(returnType| * @return {{returnType}} !description)%', @@ -159,7 +156,7 @@ call add(b:doge_patterns, { \ 'match': s:parameters_match_pattern, \ 'match_group_names': ['name', 'type'], \ 'format': { -\ 'jsdoc': '@param {{type|!type}} {name} !description', +\ 'jsdoc': '@param {{type|!type}} {name} - !description', \ }, \ }, \ 'comment': { @@ -168,7 +165,6 @@ call add(b:doge_patterns, { \ 'jsdoc': [ \ '/**', \ ' * !description', -\ ' *', \ '%(async| * @{async})%', \ ' * @function {className}#{funcName}', \ '%(parameters| * {parameters})%', @@ -209,7 +205,7 @@ call add(b:doge_patterns, { \ 'match': s:parameters_match_pattern, \ 'match_group_names': ['name', 'type'], \ 'format': { -\ 'jsdoc': '@param {{type|!type}} {name} !description', +\ 'jsdoc': '@param {{type|!type}} {name} - !description', \ }, \ }, \ 'comment': { @@ -218,7 +214,6 @@ call add(b:doge_patterns, { \ 'jsdoc': [ \ '/**', \ ' * !description', -\ ' *', \ '%(async| * @{async})%', \ ' * @function {funcName|}', \ '%(parameters| * {parameters})%', @@ -230,4 +225,4 @@ call add(b:doge_patterns, { \}) let &cpoptions = s:save_cpo -unlet s:save_cpo +u diff --git a/test/filetypes/javascript/classes.vader b/test/filetypes/javascript/classes.vader index 9339b916..065bb812 100644 --- a/test/filetypes/javascript/classes.vader +++ b/test/filetypes/javascript/classes.vader @@ -14,13 +14,11 @@ Do (trigger doge): Expect javascript (generated comment with nothing but the text 'TODO'): /** * [TODO:description] - * */ class Child {} /** * [TODO:description] - * */ export class Child {} @@ -40,14 +38,12 @@ Do (trigger doge): Expect javascript (generated comment with @extends): /** * [TODO:description] - * * @extends Parent */ class Child extends Parent {} /** * [TODO:description] - * * @extends Parent */ export class Child extends Parent {} @@ -62,20 +58,18 @@ Given javascript (class without extends with implements): Do (trigger doge): \ - :8\ + :7\ \ Expect javascript (generated comment with @implements tag): /** * [TODO:description] - * * @implements CustomInterfaceName */ class Child implements CustomInterfaceName {} /** * [TODO:description] - * * @implements CustomInterfaceName */ export class Child implements CustomInterfaceName {} @@ -90,13 +84,12 @@ Given javascript (class with extends and with implements): Do (trigger doge): \ - :10\ + :9\ \ Expect javascript (generated comment with @extends and @implements tags): /** * [TODO:description] - * * @extends Parent * @implements CustomInterfaceName */ @@ -104,7 +97,6 @@ Expect javascript (generated comment with @extends and @implements tags): /** * [TODO:description] - * * @extends Parent * @implements CustomInterfaceName */ diff --git a/test/filetypes/javascript/es6.vader b/test/filetypes/javascript/es6.vader index 60c8c783..5e213c28 100644 --- a/test/filetypes/javascript/es6.vader +++ b/test/filetypes/javascript/es6.vader @@ -10,7 +10,6 @@ Do (trigger doge): Expect javascript (generated comment with the 'TODO' text and @function tags): /** * [TODO:description] - * * @function */ () => {} @@ -25,29 +24,27 @@ Given javascript (fat-arrow function with parameters without type hints using 'c Do (trigger doge): \ - :12\ + :11\ \ Expect javascript (generated comment with @function and @param tags): /** * [TODO:description] - * * @function myFunc - * @param {[TODO:type]} $p1 [TODO:description] - * @param {[TODO:type]} p2 [TODO:description] - * @param {[TODO:type]} p3 [TODO:description] - * @param {[TODO:type]} p4 [TODO:description] + * @param {[TODO:type]} $p1 - [TODO:description] + * @param {[TODO:type]} p2 - [TODO:description] + * @param {[TODO:type]} p3 - [TODO:description] + * @param {[TODO:type]} p4 - [TODO:description] */ const myFunc = ($p1 = 'value', p2 = [], p3, p4) => {} /** * [TODO:description] - * * @function myFunc - * @param {[TODO:type]} $p1 [TODO:description] - * @param {[TODO:type]} p2 [TODO:description] - * @param {[TODO:type]} p3 [TODO:description] - * @param {[TODO:type]} p4 [TODO:description] + * @param {[TODO:type]} $p1 - [TODO:description] + * @param {[TODO:type]} p2 - [TODO:description] + * @param {[TODO:type]} p3 - [TODO:description] + * @param {[TODO:type]} p4 - [TODO:description] */ let myFunc = ($p1 = 'value', p2 = [], p3, p4) => {} @@ -63,12 +60,11 @@ Do (trigger doge): Expect javascript (generated comment with @function, @param and @return tags): /** * [TODO:description] - * * @function myFunc - * @param {string} $p1 [TODO:description] - * @param {string[]} p2 [TODO:description] - * @param {number} p3 [TODO:description] - * @param {float} p4 [TODO:description] + * @param {string} $p1 - [TODO:description] + * @param {string[]} p2 - [TODO:description] + * @param {number} p3 - [TODO:description] + * @param {float} p4 - [TODO:description] * @return {string[]} [TODO:description] */ const myFunc = ($p1: string = 'value', p2: string[] = [], p3: number, p4: float): string[] {} @@ -90,16 +86,15 @@ Given javascript (fat-arrow functions with destructuring): Do (trigger doge): :2\ \ - :12\ + :11\ \ Expect javascript (generated comments with @function, @param and @return tags): class Test { /** * [TODO:description] - * * @function myMethod - * @param {number} b [TODO:description] + * @param {number} b - [TODO:description] */ myMethod = ({ b: number }) => { return this.add(b); @@ -107,8 +102,7 @@ Expect javascript (generated comments with @function, @param and @return tags): /** * [TODO:description] - * - * @param {number} b [TODO:description] + * @param {number} b - [TODO:description] * @return {number} [TODO:description] */ myMethod({ b: number }): number { @@ -134,8 +128,7 @@ Expect javascript (generated comment with @description and @param tags): class Test { /** * [TODO:description] - * - * @param {number} b [TODO:description] + * @param {number} b - [TODO:description] */ myMethod(public b: number) { return this.add(b); @@ -154,10 +147,9 @@ Do (trigger doge): Expect javascript (generated comment with @function, @param and @return tags): /** * [TODO:description] - * * @function Person#greet - * @param {string} p1 [TODO:description] - * @param {Immutable.List} p2 [TODO:description] + * @param {string} p1 - [TODO:description] + * @param {Immutable.List} p2 - [TODO:description] * @return {string[]} [TODO:description] */ Person.prototype.greet = (p1: string = 'default', p2: Immutable.List = Immutable.List()): string[] => {}; @@ -174,7 +166,6 @@ Do (trigger doge): Expect javascript (generated comment with @description and @function tags): /** * [TODO:description] - * * @function Person#greet */ Person.prototype.greet = () => {}; @@ -191,10 +182,9 @@ Do (trigger doge): Expect javascript (generated comment with @function, @param and @return tags): /** * [TODO:description] - * * @function myFunc - * @param {string} $p1 [TODO:description] - * @param {Foo|Bar|Baz} p2 [TODO:description] + * @param {string} $p1 - [TODO:description] + * @param {Foo|Bar|Baz} p2 - [TODO:description] * @return {Foo|Bar} [TODO:description] */ const myFunc = ($p1: string, p2: Foo | Bar | Baz): (Foo | Bar) => {}; @@ -208,14 +198,13 @@ Given javascript (async fat-arrow function with parameters with multiple type hi Do (trigger doge): \ -Expect javascript (generated comment with @function, @param and @return tags): +Expect javascript (generated comment with @async, @function, @param and @return tags): /** * [TODO:description] - * * @async * @function myFunc - * @param {string} $p1 [TODO:description] - * @param {Foo|Bar|Baz} p2 [TODO:description] + * @param {string} $p1 - [TODO:description] + * @param {Foo|Bar|Baz} p2 - [TODO:description] * @return {Foo|Bar} [TODO:description] */ const myFunc = async ($p1: string, p2: Foo | Bar | Baz): (Foo | Bar) => {}; diff --git a/test/filetypes/javascript/functions-inside-objects.vader b/test/filetypes/javascript/functions-inside-objects.vader index 698b2d62..f203bbac 100644 --- a/test/filetypes/javascript/functions-inside-objects.vader +++ b/test/filetypes/javascript/functions-inside-objects.vader @@ -14,14 +14,13 @@ Given javascript (anonymous function inside object without parameters): Do (trigger doge): :2\ \ - :10\ + :9\ \ Expect javascript (generated comment with nothing but the text 'TODO' and @function tag): var myObj = { /** * [TODO:description] - * * @function myFunc */ myFunc: function(/* inline comment */) { @@ -29,7 +28,6 @@ Expect javascript (generated comment with nothing but the text 'TODO' and @funct }, /** * [TODO:description] - * * @function myArrowFunc */ myArrowFunc: (/* inline comment */) => { @@ -55,33 +53,31 @@ Given javascript (functions with punctation with parameters with/without type hi Do (trigger doge): :2\ \ - :15\ + :14\ \ Expect javascript (generated comment with @async, @function and @param tags): var myObj = { /** * [TODO:description] - * * @async * @function my-func - * @param {string} $p1 [TODO:description] - * @param {array} p2 [TODO:description] - * @param {[TODO:type]} p3 [TODO:description] - * @param {[TODO:type]} p4 [TODO:description] + * @param {string} $p1 - [TODO:description] + * @param {array} p2 - [TODO:description] + * @param {[TODO:type]} p3 - [TODO:description] + * @param {[TODO:type]} p4 - [TODO:description] */ 'my-func': async function test($p1: string = 'value', p2: array = [], p3, p4 /* inline comment */) { // }, /** * [TODO:description] - * * @async * @function my-arrow-func - * @param {string} $p1 [TODO:description] - * @param {array} p2 [TODO:description] - * @param {[TODO:type]} p3 [TODO:description] - * @param {[TODO:type]} p4 [TODO:description] + * @param {string} $p1 - [TODO:description] + * @param {array} p2 - [TODO:description] + * @param {[TODO:type]} p3 - [TODO:description] + * @param {[TODO:type]} p4 - [TODO:description] * @return {1|2|3} [TODO:description] */ 'my-arrow-func': async ($p1: string = 'value', p2: array = [], p3, p4 /* inline comment */): ( 1 | 2 | 3 ) => { diff --git a/test/filetypes/javascript/functions.vader b/test/filetypes/javascript/functions.vader index de8378aa..85d87937 100644 --- a/test/filetypes/javascript/functions.vader +++ b/test/filetypes/javascript/functions.vader @@ -10,7 +10,6 @@ Do (trigger doge): Expect javascript (generated comment with nothing but the text 'TODO'): /** * [TODO:description] - * */ function myFunc(/* inline comment */) {} @@ -26,11 +25,10 @@ Do (trigger doge): Expect javascript (generated comment with @description and @param tags): /** * [TODO:description] - * - * @param {[TODO:type]} $p1 [TODO:description] - * @param {[TODO:type]} p2 [TODO:description] - * @param {[TODO:type]} p3 [TODO:description] - * @param {[TODO:type]} p4 [TODO:description] + * @param {[TODO:type]} $p1 - [TODO:description] + * @param {[TODO:type]} p2 - [TODO:description] + * @param {[TODO:type]} p3 - [TODO:description] + * @param {[TODO:type]} p4 - [TODO:description] */ function myFunc($p1 = 'value', p2 = [], p3, p4 /* inline comment */) {} @@ -46,11 +44,10 @@ Do (trigger doge): Expect javascript (generated comment with @param and @return tags): /** * [TODO:description] - * - * @param {string} $p1 [TODO:description] - * @param {string[]} p2 [TODO:description] - * @param {number} p3 [TODO:description] - * @param {float} p4 [TODO:description] + * @param {string} $p1 - [TODO:description] + * @param {string[]} p2 - [TODO:description] + * @param {number} p3 - [TODO:description] + * @param {float} p4 - [TODO:description] * @return {string[]} [TODO:description] */ function myFunc($p1: string = 'value', p2: string[] = [], p3: number, p4: float): string[] {} @@ -67,12 +64,11 @@ Do (trigger doge): Expect javascript (generated comment with @functon and @param tags): /** * [TODO:description] - * * @function myFunc - * @param {[TODO:type]} $p1 [TODO:description] - * @param {[TODO:type]} p2 [TODO:description] - * @param {[TODO:type]} p3 [TODO:description] - * @param {[TODO:type]} p4 [TODO:description] + * @param {[TODO:type]} $p1 - [TODO:description] + * @param {[TODO:type]} p2 - [TODO:description] + * @param {[TODO:type]} p3 - [TODO:description] + * @param {[TODO:type]} p4 - [TODO:description] */ var myFunc = function($p1 = 'value', p2 = [], p3, p4) {} @@ -88,12 +84,11 @@ Do (trigger doge): Expect javascript (generated comment with @function and @param tags): /** * [TODO:description] - * * @function myFunc - * @param {string} $p1 [TODO:description] - * @param {string[]} p2 [TODO:description] - * @param {number} p3 [TODO:description] - * @param {float} p4 [TODO:description] + * @param {string} $p1 - [TODO:description] + * @param {string[]} p2 - [TODO:description] + * @param {number} p3 - [TODO:description] + * @param {float} p4 - [TODO:description] * @return {string[]} [TODO:description] */ var myFunc = function($p1: string = 'value', p2: string[] = [], p3: number, p4: float): string[] {} @@ -141,10 +136,9 @@ Do (trigger doge): Expect javascript (generated comment with @function, @param and @return tags): /** * [TODO:description] - * * @function Person#greet - * @param {string} p1 [TODO:description] - * @param {Immutable.List} p2 [TODO:description] + * @param {string} p1 - [TODO:description] + * @param {Immutable.List} p2 - [TODO:description] * @return {string[]} [TODO:description] */ Person.prototype.greet = function (p1: string = 'default', p2: Immutable.List = Immutable.List()): string[] {}; @@ -161,7 +155,6 @@ Do (trigger doge): Expect javascript (generated comment with @description and @function tags): /** * [TODO:description] - * * @function Person#greet */ Person.prototype.greet = function () {} @@ -178,9 +171,8 @@ Do (trigger doge): Expect javascript (generated comment with @param and @return tags): /** * [TODO:description] - * - * @param {string} $p1 [TODO:description] - * @param {Foo|Bar|Baz} p2 [TODO:description] + * @param {string} $p1 - [TODO:description] + * @param {Foo|Bar|Baz} p2 - [TODO:description] * @return {Foo|Bar} [TODO:description] */ function myFunc($p1: string, p2: Foo | Bar | Baz): (Foo | Bar) {} @@ -197,12 +189,11 @@ Do (trigger doge): Expect javascript (generated comment with @async, and @param tags): /** * [TODO:description] - * * @async - * @param {[TODO:type]} $p1 [TODO:description] - * @param {[TODO:type]} p2 [TODO:description] - * @param {[TODO:type]} p3 [TODO:description] - * @param {[TODO:type]} p4 [TODO:description] + * @param {[TODO:type]} $p1 - [TODO:description] + * @param {[TODO:type]} p2 - [TODO:description] + * @param {[TODO:type]} p3 - [TODO:description] + * @param {[TODO:type]} p4 - [TODO:description] */ async function myFunc($p1 = 'value', p2 = [], p3, p4) {} @@ -218,11 +209,10 @@ Do (trigger doge): Expect javascript (generated comment with @description and @param tags): /** * [TODO:description] - * - * @param {[TODO:type]} $p1 [TODO:description] - * @param {[TODO:type]} p2 [TODO:description] - * @param {[TODO:type]} p3 [TODO:description] - * @param {[TODO:type]} p4 [TODO:description] + * @param {[TODO:type]} $p1 - [TODO:description] + * @param {[TODO:type]} p2 - [TODO:description] + * @param {[TODO:type]} p3 - [TODO:description] + * @param {[TODO:type]} p4 - [TODO:description] */ function* myFunc($p1 = 'value', p2 = [], p3, p4) {} @@ -238,11 +228,10 @@ Do (trigger doge): Expect javascript (generated comment with @async, and @param tags): /** * [TODO:description] - * * @async - * @param {[TODO:type]} $p1 [TODO:description] - * @param {[TODO:type]} p2 [TODO:description] - * @param {[TODO:type]} p3 [TODO:description] - * @param {[TODO:type]} p4 [TODO:description] + * @param {[TODO:type]} $p1 - [TODO:description] + * @param {[TODO:type]} p2 - [TODO:description] + * @param {[TODO:type]} p3 - [TODO:description] + * @param {[TODO:type]} p4 - [TODO:description] */ async function* myFunc($p1 = 'value', p2 = [], p3, p4) {}