Skip to content

Commit e95c189

Browse files
c-vetterjgoz
authored andcommitted
Support TypeScript parameter properties
+ add typescript parser devDependency + add tests to requireParam and checkParamName + extend jsdocUtils Fixes #177
1 parent da25e1b commit e95c189

File tree

4 files changed

+37
-2
lines changed

4 files changed

+37
-2
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"@babel/plugin-transform-flow-strip-types": "^7.4.4",
2020
"@babel/preset-env": "^7.4.5",
2121
"@babel/register": "^7.4.4",
22+
"@typescript-eslint/parser": "^1.5.0",
2223
"babel-eslint": "^10.0.2",
2324
"babel-plugin-add-module-exports": "^1.0.2",
2425
"babel-plugin-istanbul": "^5.1.4",

src/jsdocUtils.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import _ from 'lodash';
22
import tagNames from './tagNames';
33

44
const getFunctionParameterNames = (functionNode : Object) : Array<string> => {
5-
return _.map(functionNode.params, (param) => {
5+
const functionParameterNameMapper = (param) => {
66
if (_.has(param, 'name')) {
77
return param.name;
88
}
@@ -23,8 +23,14 @@ const getFunctionParameterNames = (functionNode : Object) : Array<string> => {
2323
return param.argument.name;
2424
}
2525

26+
if (param.type === 'TSParameterProperty') {
27+
return functionParameterNameMapper(param.parameter);
28+
}
29+
2630
throw new Error('Unsupported function signature format.');
27-
});
31+
};
32+
33+
return _.map(functionNode.params, functionParameterNameMapper);
2834
};
2935

3036
/**

test/rules/assertions/checkParamNames.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,20 @@ export default {
274274
275275
};
276276
`
277+
},
278+
{
279+
code: `
280+
export class SomeClass {
281+
/**
282+
* @param property
283+
*/
284+
constructor(private property: string) {}
285+
}
286+
`,
287+
parser: '@typescript-eslint/parser',
288+
parserOptions: {
289+
sourceType: 'module'
290+
}
277291
}
278292
]
279293
};

test/rules/assertions/requireParam.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -673,6 +673,20 @@ export default {
673673
}
674674
}
675675
`
676+
},
677+
{
678+
code: `
679+
export class SomeClass {
680+
/**
681+
* @param property
682+
*/
683+
constructor(private property: string) {}
684+
}
685+
`,
686+
parser: '@typescript-eslint/parser',
687+
parserOptions: {
688+
sourceType: 'module'
689+
}
676690
}
677691
]
678692
};

0 commit comments

Comments
 (0)