Skip to content

Commit

Permalink
Upgrade typescript-to-proptypes
Browse files Browse the repository at this point in the history
  • Loading branch information
merceyz committed Jul 10, 2019
1 parent 8abb15e commit 10960a3
Show file tree
Hide file tree
Showing 26 changed files with 89 additions and 43 deletions.
15 changes: 3 additions & 12 deletions docs/scripts/formattedTSDemos.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,18 +71,7 @@ function getLineFeed(source) {

const fixBabelIssuesRegExp = new RegExp(/(?<=(\/>)|,)(\r?\n){2}/g);
function fixBabelGeneratorIssues(source) {
const lf = getLineFeed(source);

return (
source
.replace(fixBabelIssuesRegExp, lf)
// Linefeed after commentblock
.replace(/\*\/ (\w+)/g, `*/${lf} $1`)
// empty line before proptypes
.replace(/^(}(\);)?)(\r?\n\w+\.propTypes)/gm, `$1${lf}$3`)
// empty line after proptypes
.replace(/^(};)(\r?\n\w+)/gm, `$1${lf}$2`)
);
return source.replace(fixBabelIssuesRegExp, getLineFeed(source));
}

const TranspileResult = {
Expand All @@ -103,8 +92,10 @@ async function transpileFile(tsxPath, program, ignoreCache = false) {
}

const { code } = await babel.transformFileAsync(tsxPath, babelConfig);

const propTypesAST = typescriptToProptypes.parseFromProgram(tsxPath, program);
const codeWithPropTypes = typescriptToProptypes.inject(propTypesAST, code);

const prettified = prettier.format(codeWithPropTypes, { ...prettierConfig, filepath: tsxPath });
const formatted = fixBabelGeneratorIssues(prettified);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,9 @@ function DownshiftMultiple(props) {
);
}

DownshiftMultiple.propTypes = { classes: PropTypes.object.isRequired };
DownshiftMultiple.propTypes = {
classes: PropTypes.object.isRequired,
};

const useStyles = makeStyles(theme => ({
root: {
Expand Down
9 changes: 7 additions & 2 deletions docs/src/pages/components/breadcrumbs/RouterBreadcrumbs.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ function ListItemLink(props) {
);
}

ListItemLink.propTypes = { open: PropTypes.bool, to: PropTypes.string.isRequired };
ListItemLink.propTypes = {
open: PropTypes.bool,
to: PropTypes.string.isRequired,
};

const styles = theme => ({
root: {
Expand Down Expand Up @@ -116,6 +119,8 @@ class RouterBreadcrumbs extends React.Component {
}
}

RouterBreadcrumbs.propTypes = { classes: PropTypes.object.isRequired };
RouterBreadcrumbs.propTypes = {
classes: PropTypes.object.isRequired,
};

export default withStyles(styles)(RouterBreadcrumbs);
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ function TabContainer(props) {
);
}

TabContainer.propTypes = { children: PropTypes.node.isRequired, dir: PropTypes.string };
TabContainer.propTypes = {
children: PropTypes.node.isRequired,
dir: PropTypes.string,
};

const useStyles = makeStyles(theme => ({
root: {
Expand Down
4 changes: 3 additions & 1 deletion docs/src/pages/components/hidden/BreakpointDown.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ function BreakpointDown(props) {
);
}

BreakpointDown.propTypes = { width: PropTypes.oneOf(['lg', 'md', 'sm', 'xl', 'xs']).isRequired };
BreakpointDown.propTypes = {
width: PropTypes.oneOf(['lg', 'md', 'sm', 'xl', 'xs']).isRequired,
};

export default withWidth()(BreakpointDown);
4 changes: 3 additions & 1 deletion docs/src/pages/components/hidden/BreakpointOnly.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ function BreakpointOnly(props) {
);
}

BreakpointOnly.propTypes = { width: PropTypes.oneOf(['lg', 'md', 'sm', 'xl', 'xs']).isRequired };
BreakpointOnly.propTypes = {
width: PropTypes.oneOf(['lg', 'md', 'sm', 'xl', 'xs']).isRequired,
};

export default withWidth()(BreakpointOnly);
4 changes: 3 additions & 1 deletion docs/src/pages/components/hidden/BreakpointUp.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ function BreakpointUp(props) {
);
}

BreakpointUp.propTypes = { width: PropTypes.oneOf(['lg', 'md', 'sm', 'xl', 'xs']).isRequired };
BreakpointUp.propTypes = {
width: PropTypes.oneOf(['lg', 'md', 'sm', 'xl', 'xs']).isRequired,
};

export default withWidth()(BreakpointUp);
4 changes: 3 additions & 1 deletion docs/src/pages/components/hidden/GridIntegration.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ function GridIntegration(props) {
);
}

GridIntegration.propTypes = { width: PropTypes.oneOf(['lg', 'md', 'sm', 'xl', 'xs']).isRequired };
GridIntegration.propTypes = {
width: PropTypes.oneOf(['lg', 'md', 'sm', 'xl', 'xs']).isRequired,
};

export default withWidth()(GridIntegration);
5 changes: 4 additions & 1 deletion docs/src/pages/components/lists/VirtualizedList.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ function Row(props) {
);
}

Row.propTypes = { index: PropTypes.number.isRequired, style: PropTypes.object.isRequired };
Row.propTypes = {
index: PropTypes.number.isRequired,
style: PropTypes.object.isRequired,
};

export default function VirtualizedList() {
const classes = useStyles();
Expand Down
4 changes: 3 additions & 1 deletion docs/src/pages/components/snackbars/ConsecutiveSnackbars.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ class ConsecutiveSnackbars extends React.Component {
}
}

ConsecutiveSnackbars.propTypes = { classes: PropTypes.object.isRequired };
ConsecutiveSnackbars.propTypes = {
classes: PropTypes.object.isRequired,
};

export default withStyles(styles)(ConsecutiveSnackbars);
4 changes: 3 additions & 1 deletion docs/src/pages/components/tables/EnhancedTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,9 @@ const EnhancedTableToolbar = props => {
);
};

EnhancedTableToolbar.propTypes = { numSelected: PropTypes.number.isRequired };
EnhancedTableToolbar.propTypes = {
numSelected: PropTypes.number.isRequired,
};

const useStyles = makeStyles(theme => ({
root: {
Expand Down
5 changes: 4 additions & 1 deletion docs/src/pages/components/tabs/FullWidthTabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ function TabContainer({ children, dir }) {
);
}

TabContainer.propTypes = { children: PropTypes.node.isRequired, dir: PropTypes.string };
TabContainer.propTypes = {
children: PropTypes.node.isRequired,
dir: PropTypes.string,
};

const useStyles = makeStyles(theme => ({
root: {
Expand Down
4 changes: 3 additions & 1 deletion docs/src/pages/components/tabs/NavTabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ function TabContainer(props) {
);
}

TabContainer.propTypes = { children: PropTypes.node.isRequired };
TabContainer.propTypes = {
children: PropTypes.node.isRequired,
};

function LinkTab(props) {
return (
Expand Down
4 changes: 3 additions & 1 deletion docs/src/pages/components/tabs/ScrollableTabsButtonAuto.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ function TabContainer(props) {
);
}

TabContainer.propTypes = { children: PropTypes.node.isRequired };
TabContainer.propTypes = {
children: PropTypes.node.isRequired,
};

const useStyles = makeStyles(theme => ({
root: {
Expand Down
4 changes: 3 additions & 1 deletion docs/src/pages/components/tabs/ScrollableTabsButtonForce.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ function TabContainer(props) {
);
}

TabContainer.propTypes = { children: PropTypes.node.isRequired };
TabContainer.propTypes = {
children: PropTypes.node.isRequired,
};

const useStyles = makeStyles(theme => ({
root: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ function TabContainer(props) {
);
}

TabContainer.propTypes = { children: PropTypes.node.isRequired };
TabContainer.propTypes = {
children: PropTypes.node.isRequired,
};

const useStyles = makeStyles(theme => ({
root: {
Expand Down
4 changes: 3 additions & 1 deletion docs/src/pages/components/tabs/SimpleTabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ function TabContainer(props) {
);
}

TabContainer.propTypes = { children: PropTypes.node.isRequired };
TabContainer.propTypes = {
children: PropTypes.node.isRequired,
};

const useStyles = makeStyles(theme => ({
root: {
Expand Down
4 changes: 3 additions & 1 deletion docs/src/pages/components/tabs/TabsWrappedLabel.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ function TabContainer(props) {
);
}

TabContainer.propTypes = { children: PropTypes.node.isRequired };
TabContainer.propTypes = {
children: PropTypes.node.isRequired,
};

const useStyles = makeStyles(theme => ({
root: {
Expand Down
4 changes: 3 additions & 1 deletion docs/src/pages/components/text-fields/FormattedInputs.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ function TextMaskCustom(props) {
);
}

TextMaskCustom.propTypes = { inputRef: PropTypes.func.isRequired };
TextMaskCustom.propTypes = {
inputRef: PropTypes.func.isRequired,
};

function NumberFormatCustom(props) {
const { inputRef, onChange, ...other } = props;
Expand Down
8 changes: 6 additions & 2 deletions docs/src/pages/components/tooltips/CustomizedTooltips.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,9 @@ function ArrowTooltip(props) {
);
}

ArrowTooltip.propTypes = { title: PropTypes.node.isRequired };
ArrowTooltip.propTypes = {
title: PropTypes.node.isRequired,
};

const useStylesBootstrap = makeStyles(theme => ({
arrow: {
Expand Down Expand Up @@ -174,7 +176,9 @@ function BootstrapTooltip(props) {
);
}

BootstrapTooltip.propTypes = { title: PropTypes.node.isRequired };
BootstrapTooltip.propTypes = {
title: PropTypes.node.isRequired,
};

const HtmlTooltip = withStyles(theme => ({
tooltip: {
Expand Down
4 changes: 3 additions & 1 deletion docs/src/pages/css-in-js/basics/AdaptingHook.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ function MyButton(props) {
return <Button className={classes.root} {...other} />;
}

MyButton.propTypes = { color: PropTypes.oneOf(['blue', 'red']).isRequired };
MyButton.propTypes = {
color: PropTypes.oneOf(['blue', 'red']).isRequired,
};

export default function AdaptingHook() {
return (
Expand Down
4 changes: 3 additions & 1 deletion docs/src/pages/styles/basics/AdaptingHook.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ function MyButton(props) {
return <Button className={classes.root} {...other} />;
}

MyButton.propTypes = { color: PropTypes.oneOf(['blue', 'red']).isRequired };
MyButton.propTypes = {
color: PropTypes.oneOf(['blue', 'red']).isRequired,
};

export default function AdaptingHook() {
return (
Expand Down
4 changes: 3 additions & 1 deletion docs/src/pages/styles/basics/HigherOrderComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ function HigherOrderComponent(props) {
return <Button className={classes.root}>Higher-order component</Button>;
}

HigherOrderComponent.propTypes = { classes: PropTypes.object.isRequired };
HigherOrderComponent.propTypes = {
classes: PropTypes.object.isRequired,
};

export default withStyles(styles)(HigherOrderComponent);
4 changes: 3 additions & 1 deletion docs/src/pages/styles/basics/StressTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ const Component = React.memo(props => {
);
});

Component.propTypes = { backgroundColor: PropTypes.string.isRequired };
Component.propTypes = {
backgroundColor: PropTypes.string.isRequired,
};

export default function StressTest() {
const [backgroundColor, setBackgroundColor] = React.useState('#2196f3');
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@
"styled-components": "^4.1.1",
"tslint": "5.14.0",
"typescript": "3.2.2",
"typescript-to-proptypes": "^1.0.2",
"typescript-to-proptypes": "^1.0.3",
"url-loader": "^1.0.1",
"vrtest": "^0.2.0",
"webfontloader": "^1.6.28",
Expand Down
11 changes: 6 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@
"@babel/traverse" "^7.1.0"
"@babel/types" "^7.2.0"

"@babel/helpers@^7.1.2", "@babel/helpers@^7.4.4", "@babel/helpers@^7.5.0":
"@babel/helpers@^7.1.2", "@babel/helpers@^7.5.0":
version "7.5.2"
resolved "https://registry.yarnpkg.com/@babel/helpers/-/helpers-7.5.2.tgz#97424dc82fc0041f4c751119b4d2b1ec68cdb5ba"
integrity sha512-NDkkTqDvgFUeo8djXBOiwO/mFjownznOWvmP9hvNdfiFUmx0nwNOqxuaTTbxjH744eQsD9M5ubC7gdANBvIWPw==
Expand Down Expand Up @@ -13890,17 +13890,18 @@ typedarray@^0.0.6:
resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777"
integrity sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c=

typescript-to-proptypes@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/typescript-to-proptypes/-/typescript-to-proptypes-1.0.2.tgz#e5cd215200be11d976798c9f4febb0cef4e763bd"
integrity sha512-mDrmPtB2DGDoEIIMESPQGhTkK74nTH9ZXPYWVZFy5X1GI+/FcPg15hEiShu+USFJ5Zg2r3hTKbuO+NrEzhJNFg==
typescript-to-proptypes@^1.0.3:
version "1.0.3"
resolved "https://registry.yarnpkg.com/typescript-to-proptypes/-/typescript-to-proptypes-1.0.3.tgz#50a82675b80b006d57d932edfbb19d8ec212091f"
integrity sha512-PCUCwxtNn+x/dtlseY61S8NkxykT7qMbFaj7SoABwF6hCC3TrLqUHHhUuL9eF5WTnYQupTdt8l9u++pjTuxvxQ==
dependencies:
"@babel/core" "^7.5.0"
"@babel/plugin-syntax-class-properties" "^7.2.0"
"@babel/plugin-syntax-jsx" "^7.2.0"
"@babel/types" "^7.5.0"
lodash "^4.17.11"
typescript "3.5.2"
uuid "^3.3.2"

typescript@3.2.2:
version "3.2.2"
Expand Down

0 comments on commit 10960a3

Please sign in to comment.