-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #79 from alfa-laboratory/feat/func-prop-types
feat(*): add params information to func proptypes where possible
- Loading branch information
Showing
13 changed files
with
1,421 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ before_script: | |
|
||
script: | ||
- npm run lint | ||
- npm test | ||
|
||
after_script: | ||
- greenkeeper-lockfile-upload | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
const getMemberValuePath = require('react-docgen/dist/utils/getMemberValuePath').default; | ||
const resolveToValue = require('react-docgen/dist/utils/resolveToValue').default; | ||
const getPropertyName = require('react-docgen/dist/utils/getPropertyName').default; | ||
const parseJsDoc = require('react-docgen/dist/utils/parseJsDoc').default; | ||
const recast = require('recast'); | ||
|
||
const { types: { namedTypes: types } } = recast; | ||
// component-prop-types-js-doc-handler | ||
function componentPropTypesJsDocHandler(documentation, path) { | ||
let propTypesPath = getMemberValuePath(path, 'propTypes'); | ||
|
||
if (!propTypesPath) { | ||
return; | ||
} | ||
propTypesPath = resolveToValue(propTypesPath); | ||
if (!propTypesPath || !types.ObjectExpression.check(propTypesPath.node)) { | ||
return; | ||
} | ||
|
||
propTypesPath.get('properties').each((propertyPath) => { | ||
// we only support documentation of actual properties, not spread | ||
if (types.Property.check(propertyPath.node)) { | ||
const propName = getPropertyName(propertyPath); | ||
const propDescriptor = documentation.getPropDescriptor(propName); | ||
if (!propDescriptor.description || !propDescriptor.type) { | ||
return; | ||
} | ||
const jsDoc = parseJsDoc(propDescriptor.description); | ||
propDescriptor.description = jsDoc.description || propDescriptor.description; | ||
propDescriptor.type.params = jsDoc.params || []; | ||
propDescriptor.type.returns = jsDoc.returns; | ||
} | ||
}); | ||
} | ||
|
||
module.exports = componentPropTypesJsDocHandler; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
/* eslint-disable */ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
|
||
/** | ||
* Component description. | ||
*/ | ||
export default class A extends React.Component { | ||
static propTypes = { | ||
optionalArray: PropTypes.array, | ||
requiredArray: PropTypes.array.isRequired, | ||
/** | ||
* Prop documentation | ||
*/ | ||
optionalBool: PropTypes.bool, | ||
requiredBool: PropTypes.bool.isRequired, | ||
optionalFunc: PropTypes.func, | ||
requiredFunc: PropTypes.func.isRequired, | ||
optionalNumber: PropTypes.number, | ||
requiredNumber: PropTypes.number.isRequired, | ||
optionalObject: PropTypes.object, | ||
requiredObject: PropTypes.object.isRequired, | ||
optionalString: PropTypes.string, | ||
requiredString: PropTypes.string.isRequired, | ||
optionalSymbol: PropTypes.symbol, | ||
requiredSymbol: PropTypes.symbol.isRequired, | ||
optionalNode: PropTypes.node, | ||
requiredNode: PropTypes.node.isRequired, | ||
optionalElement: PropTypes.element, | ||
requiredElement: PropTypes.element.isRequired, | ||
optionalMessage: PropTypes.instanceOf(Message), | ||
requiredMessage: PropTypes.instanceOf(Message).isRequired, | ||
optionalEnum: PropTypes.oneOf(['News', 'Photos']), | ||
requiredEnum: PropTypes.oneOf(['News', 'Photos']).isRequired, | ||
optionalUnion: PropTypes.oneOfType([ | ||
PropTypes.string, | ||
PropTypes.number | ||
]), | ||
requiredUnion: PropTypes.oneOfType([ | ||
PropTypes.string, | ||
PropTypes.number | ||
]).isRequired, | ||
optionalArrayOf: PropTypes.arrayOf(PropTypes.number), | ||
requiredArrayOf: PropTypes.arrayOf(PropTypes.number).isRequired, | ||
optionalObjectOf: PropTypes.objectOf(PropTypes.number), | ||
requiredObjectOf: PropTypes.objectOf(PropTypes.number).isRequired, | ||
optionalAny: PropTypes.any, | ||
requiredAny: PropTypes.any.isRequired, | ||
optionalObjectWithShape: PropTypes.shape({ | ||
color: PropTypes.string, | ||
/** | ||
* Sub prop documentation | ||
*/ | ||
fontSize: PropTypes.number.isRequired, | ||
/** | ||
* @param {string} value | ||
*/ | ||
onChange: PropTypes.func, | ||
subShape: PropTypes.shape({ | ||
/** | ||
* Even deeper documentation | ||
*/ | ||
name: PropTypes.string, | ||
size: PropTypes.number | ||
}) | ||
}), | ||
/** | ||
* Callback with documentation | ||
* | ||
* @param {String} stringParam | ||
* @param {number} count | ||
* @param {React.MouseEvent} event | ||
* @param {React.KeyboardEvent} anotherEvent | ||
* @param {HTMLDivElement} element some html element | ||
* | ||
* @returns {string|number} | ||
*/ | ||
onClick: PropTypes.func, | ||
onChange: PropTypes.func | ||
}; | ||
|
||
render() { | ||
return null; | ||
} | ||
|
||
privateMethod(name) { | ||
} | ||
|
||
/** | ||
* Some description. | ||
* | ||
* @public | ||
*/ | ||
publicMethod1() { | ||
|
||
} | ||
|
||
/** | ||
* Maybe we just forgot to add params? | ||
* | ||
* @public | ||
*/ | ||
publicMethodWithouParams() { | ||
|
||
} | ||
|
||
/** | ||
* Some description. | ||
* | ||
* @public | ||
* @param {string} str1 Some description. | ||
* @param {String} str2 Some description. | ||
* @param {number} num1 Some description. | ||
* @param {Number} num2 Some description. | ||
* @param {Boolean} bool1 Some description. | ||
* @param {bool} bool2 Some description. | ||
* @param {boolean} bool3 Some description. | ||
* @param {string|number} union Some description. | ||
*/ | ||
publicWithParams(str1, str2, num1, num2, bool1, bool2, bool3, union) { | ||
} | ||
} |
Oops, something went wrong.