Skip to content

Commit

Permalink
Remove JSX propTypes checks
Browse files Browse the repository at this point in the history
  • Loading branch information
gaearon committed Feb 20, 2024
1 parent a515d75 commit d7d3ca0
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 632 deletions.
5 changes: 0 additions & 5 deletions packages/react-art/npm/Circle.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
'use strict';

var assign = Object.assign;
var PropTypes = require('prop-types');
var React = require('react');
var ReactART = require('react-art');

Expand All @@ -34,10 +33,6 @@ var Shape = ReactART.Shape;
var Circle = createReactClass({
displayName: 'Circle',

propTypes: {
radius: PropTypes.number.isRequired,
},

render: function render() {
var radius = this.props.radius;

Expand Down
11 changes: 0 additions & 11 deletions packages/react-art/npm/Rectangle.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
'use strict';

var assign = Object.assign;
var PropTypes = require('prop-types');
var React = require('react');
var ReactART = require('react-art');

Expand All @@ -41,16 +40,6 @@ var Path = ReactART.Path;
var Rectangle = createReactClass({
displayName: 'Rectangle',

propTypes: {
width: PropTypes.number.isRequired,
height: PropTypes.number.isRequired,
radius: PropTypes.number,
radiusTopLeft: PropTypes.number,
radiusTopRight: PropTypes.number,
radiusBottomRight: PropTypes.number,
radiusBottomLeft: PropTypes.number,
},

render: function render() {
var width = this.props.width;
var height = this.props.height;
Expand Down
8 changes: 0 additions & 8 deletions packages/react-art/npm/Wedge.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
'use strict';

var assign = Object.assign;
var PropTypes = require('prop-types');
var React = require('react');
var ReactART = require('react-art');

Expand All @@ -37,13 +36,6 @@ var Path = ReactART.Path;
var Wedge = createReactClass({
displayName: 'Wedge',

propTypes: {
outerRadius: PropTypes.number.isRequired,
startAngle: PropTypes.number.isRequired,
endAngle: PropTypes.number.isRequired,
innerRadius: PropTypes.number,
},

circleRadians: Math.PI * 2,

radiansPerDegree: Math.PI / 180,
Expand Down
39 changes: 0 additions & 39 deletions packages/react-art/src/__tests__/ReactART-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -456,18 +456,6 @@ describe('ReactARTComponents', () => {
expect(circle.toJSON()).toMatchSnapshot();
});

it('should warn if radius is missing on a Circle component', () => {
expect(() =>
ReactTestRenderer.create(
<Circle stroke="green" strokeWidth={3} fill="blue" />,
),
).toErrorDev(
'Warning: Failed prop type: The prop `radius` is marked as required in `Circle`, ' +
'but its value is `undefined`.' +
'\n in Circle (at **)',
);
});

it('should generate a <Shape> with props for drawing the Rectangle', () => {
const rectangle = ReactTestRenderer.create(
<Rectangle width={50} height={50} stroke="green" fill="blue" />,
Expand Down Expand Up @@ -529,19 +517,6 @@ describe('ReactARTComponents', () => {
expect(rectangle.toJSON()).toMatchSnapshot();
});

it('should warn if width/height is missing on a Rectangle component', () => {
expect(() =>
ReactTestRenderer.create(<Rectangle stroke="green" fill="blue" />),
).toErrorDev([
'Warning: Failed prop type: The prop `width` is marked as required in `Rectangle`, ' +
'but its value is `undefined`.' +
'\n in Rectangle (at **)',
'Warning: Failed prop type: The prop `height` is marked as required in `Rectangle`, ' +
'but its value is `undefined`.' +
'\n in Rectangle (at **)',
]);
});

it('should generate a <Shape> with props for drawing the Wedge', () => {
const wedge = ReactTestRenderer.create(
<Wedge outerRadius={50} startAngle={0} endAngle={360} fill="blue" />,
Expand All @@ -555,18 +530,4 @@ describe('ReactARTComponents', () => {
);
expect(wedge.toJSON()).toBeNull();
});

it('should warn if outerRadius/startAngle/endAngle is missing on a Wedge component', () => {
expect(() => ReactTestRenderer.create(<Wedge fill="blue" />)).toErrorDev([
'Warning: Failed prop type: The prop `outerRadius` is marked as required in `Wedge`, ' +
'but its value is `undefined`.' +
'\n in Wedge (at **)',
'Warning: Failed prop type: The prop `startAngle` is marked as required in `Wedge`, ' +
'but its value is `undefined`.' +
'\n in Wedge (at **)',
'Warning: Failed prop type: The prop `endAngle` is marked as required in `Wedge`, ' +
'but its value is `undefined`.' +
'\n in Wedge (at **)',
]);
});
});
96 changes: 45 additions & 51 deletions packages/react-dom/src/__tests__/ReactFunctionComponent-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ describe('ReactFunctionComponent', () => {
};

getChildContext() {
return {test: this.props.test};
return { test: this.props.test };
}

render() {
Expand Down Expand Up @@ -122,7 +122,7 @@ describe('ReactFunctionComponent', () => {
function FunctionComponentWithChildContext() {
return null;
}
FunctionComponentWithChildContext.getDerivedStateFromProps = function () {};
FunctionComponentWithChildContext.getDerivedStateFromProps = function() { };

const container = document.createElement('div');

Expand All @@ -133,7 +133,7 @@ describe('ReactFunctionComponent', () => {
});
}).toErrorDev(
'FunctionComponentWithChildContext: Function ' +
'components do not support getDerivedStateFromProps.',
'components do not support getDerivedStateFromProps.',
);
});

Expand All @@ -155,12 +155,12 @@ describe('ReactFunctionComponent', () => {
});
}).toErrorDev(
'FunctionComponentWithChildContext(...): childContextTypes cannot ' +
'be defined on a function component.',
'be defined on a function component.',
);
});

it('should not throw when stateless component returns undefined', async () => {
function NotAComponent() {}
function NotAComponent() { }
const container = document.createElement('div');
const root = ReactDOMClient.createRoot(container);
await expect(
Expand Down Expand Up @@ -189,13 +189,13 @@ describe('ReactFunctionComponent', () => {
__DEV__
? 'Function components cannot have string refs. We recommend using useRef() instead.'
: // It happens because we don't save _owner in production for
// function components.
'Element ref was specified as a string (me) but no owner was set. This could happen for one of' +
' the following reasons:\n' +
'1. You may be adding a ref to a function component\n' +
"2. You may be adding a ref to a component that was not created inside a component's render method\n" +
'3. You have multiple copies of React loaded\n' +
'See https://reactjs.org/link/refs-must-have-owner for more information.',
// function components.
'Element ref was specified as a string (me) but no owner was set. This could happen for one of' +
' the following reasons:\n' +
'1. You may be adding a ref to a function component\n' +
"2. You may be adding a ref to a component that was not created inside a component's render method\n" +
'3. You have multiple copies of React loaded\n' +
'See https://reactjs.org/link/refs-must-have-owner for more information.',
);
});

Expand All @@ -222,14 +222,14 @@ describe('ReactFunctionComponent', () => {
});
}).toErrorDev(
'Warning: Function components cannot be given refs. ' +
'Attempts to access this ref will fail. ' +
'Did you mean to use React.forwardRef()?\n\n' +
'Check the render method ' +
'of `ParentUsingStringRef`.\n' +
' in FunctionComponent (at **)\n' +
' in div (at **)\n' +
' in Indirection (at **)\n' +
' in ParentUsingStringRef (at **)',
'Attempts to access this ref will fail. ' +
'Did you mean to use React.forwardRef()?\n\n' +
'Check the render method ' +
'of `ParentUsingStringRef`.\n' +
' in FunctionComponent (at **)\n' +
' in div (at **)\n' +
' in Indirection (at **)\n' +
' in ParentUsingStringRef (at **)',
);

// No additional warnings should be logged
Expand Down Expand Up @@ -264,14 +264,14 @@ describe('ReactFunctionComponent', () => {
});
}).toErrorDev(
'Warning: Function components cannot be given refs. ' +
'Attempts to access this ref will fail. ' +
'Did you mean to use React.forwardRef()?\n\n' +
'Check the render method ' +
'of `ParentUsingFunctionRef`.\n' +
' in FunctionComponent (at **)\n' +
' in div (at **)\n' +
' in Indirection (at **)\n' +
' in ParentUsingFunctionRef (at **)',
'Attempts to access this ref will fail. ' +
'Did you mean to use React.forwardRef()?\n\n' +
'Check the render method ' +
'of `ParentUsingFunctionRef`.\n' +
' in FunctionComponent (at **)\n' +
' in div (at **)\n' +
' in Indirection (at **)\n' +
' in ParentUsingFunctionRef (at **)',
);
expect(ref).not.toHaveBeenCalled();

Expand All @@ -287,7 +287,7 @@ describe('ReactFunctionComponent', () => {
// When owner uses JSX, we can use exact line location to dedupe warnings
class AnonymousParentUsingJSX extends React.Component {
render() {
return <FunctionComponent name="A" ref={() => {}} />;
return <FunctionComponent name="A" ref={() => { }} />;
}
}

Expand Down Expand Up @@ -317,7 +317,7 @@ describe('ReactFunctionComponent', () => {
render() {
return React.createElement(FunctionComponent, {
name: 'A',
ref: () => {},
ref: () => { },
});
}
}
Expand Down Expand Up @@ -346,7 +346,7 @@ describe('ReactFunctionComponent', () => {
render() {
return React.createElement(FunctionComponent, {
name: 'A',
ref: () => {},
ref: () => { },
});
}
}
Expand Down Expand Up @@ -391,7 +391,7 @@ describe('ReactFunctionComponent', () => {
};
}
render() {
return <Child ref={function () {}} />;
return <Child ref={function() { }} />;
}
}

Expand All @@ -403,12 +403,12 @@ describe('ReactFunctionComponent', () => {
});
}).toErrorDev(
'Warning: Function components cannot be given refs. ' +
'Attempts to access this ref will fail. ' +
'Did you mean to use React.forwardRef()?\n\n' +
'Check the render method ' +
'of `Parent`.\n' +
' in Child (at **)\n' +
' in Parent (at **)',
'Attempts to access this ref will fail. ' +
'Did you mean to use React.forwardRef()?\n\n' +
'Check the render method ' +
'of `Parent`.\n' +
' in Child (at **)\n' +
' in Parent (at **)',
);
});

Expand All @@ -425,18 +425,15 @@ describe('ReactFunctionComponent', () => {
});
}).toErrorDev(
'Each child in a list should have a unique "key" prop.\n\n' +
'Check the render method of `Child`.',
'Check the render method of `Child`.',
);
});

// TODO: change this test after we deprecate default props support
// for function components
it('should support default props and prop types', async () => {
it('should support default props', () => {
function Child(props) {
return <div>{props.test}</div>;
}
Child.defaultProps = {test: 2};
Child.propTypes = {test: PropTypes.string};
Child.defaultProps = { test: 2 };

await expect(async () => {
const container = document.createElement('div');
Expand All @@ -447,9 +444,6 @@ describe('ReactFunctionComponent', () => {
});
}).toErrorDev([
'Warning: Child: Support for defaultProps will be removed from function components in a future major release. Use JavaScript default parameters instead.',
'Warning: Failed prop type: Invalid prop `test` of type `number` ' +
'supplied to `Child`, expected `string`.\n' +
' in Child (at **)',
]);
});

Expand All @@ -461,7 +455,7 @@ describe('ReactFunctionComponent', () => {
};

getChildContext() {
return {lang: 'en'};
return { lang: 'en' };
}

render() {
Expand All @@ -472,7 +466,7 @@ describe('ReactFunctionComponent', () => {
function Child(props, context) {
return <div>{context.lang}</div>;
}
Child.contextTypes = {lang: PropTypes.string};
Child.contextTypes = { lang: PropTypes.string };

const el = document.createElement('div');

Expand All @@ -484,7 +478,7 @@ describe('ReactFunctionComponent', () => {
});

it('should work with arrow functions', async () => {
let Child = function () {
let Child = function() {
return <div />;
};
// Will create a new bound function without a prototype, much like a native
Expand All @@ -501,7 +495,7 @@ describe('ReactFunctionComponent', () => {
});

it('should allow simple functions to return null', async () => {
const Child = function () {
const Child = function() {
return null;
};
await expect(async () => {
Expand Down
Loading

0 comments on commit d7d3ca0

Please sign in to comment.