Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

react/prop-types does not validate missing propTypes for functions in version 7.12.3 #2134

Closed
Salles-FA opened this issue Jan 15, 2019 · 4 comments

Comments

@Salles-FA
Copy link

@ljharb closed the issue #1958 with the v7.12.1 released and he suggested to open a new issue if the problem persists.

I have the same problem with both v7.11.1, v7.12.1 and recently updated v7.12.3. I'm providing a self-contained repro as follows (As you can see the MyInput class reports the "eslint is missing in props validation [react/prop-types]" and the MyTest class don't. It is the same .jsx file and the reason is because of the spread props {...formikProps} ):

import React, { Component } from 'react';
import { Col, FormFeedback, FormGroup, Input, Label } from 'reactstrap';

import { Formik, Form } from 'formik';
import * as Yup from 'yup';

const getVal = (obj, keys) => keys.split('.').reduce((o, k) => (o || {})[k], obj);

class MyInput extends Component {
	constructor(props) {
		super(props);
		this.state = {};
	}

	render = () => {
		//#region This block of code reports [eslint] 'name' is missing in props validation [react/prop-types]
		const {
			className,
			disabled,
			errors,
			handleBlur,
			handleChange,
			id,
			label,
			maxLength,
			placeholder,
			touched,
			type,
			values,
			xs,
			sm,
			md,
			lg,
			xl,
			widths,
		} = this.props;
		//#endregion This block of code reports [eslint] 'name' is missing in props validation [react/prop-types]

		const value = getVal(values, id);
		const invalid = getVal(errors, id) && getVal(touched, id);

		return (
			<Col xs={xs} sm={sm} md={md} lg={lg} xl={xl} widths={widths}>
				<Label for={id}>{label}</Label>
				<Input
					placeholder={placeholder}
					maxLength={maxLength}
					type={type || 'text'}
					id={id}
					name={id}
					value={value || ''}
					onChange={handleChange}
					onBlur={handleBlur}
					className={`form-control ${invalid && 'is-invalid'} ${className || ''}`}
					disabled={(values && values.readOnly) || disabled}
				/>
				<FormFeedback tooltip>{getVal(errors, id)}</FormFeedback>
			</Col>
		);
	};
}

export default class MyTest extends Component {
	constructor(props) {
		super(props);

		this.initialValues = {
			test: '',
		};

		this.validationSchema = Yup.object().shape({
			test: Yup.string().required(),
		});
	}

	render = () => (
		<Formik
			//#region This block of code DON'T report [eslint] is missing in props validation [react/prop-types]
			initialValues={this.props.initialValues || this.initialValues}
			validationSchema={this.props.validationSchema || this.validationSchema}
			//#endregion This block of code DON'T report [eslint] is missing in props validation [react/prop-types]
			validateOnChange={false}>
			{formikProps => (
				<Form>
					<FormGroup row>
						<MyInput
							md="5"
							id="test"
							label="Test input"
							placeholder="Test placeholder"
							maxLength="10"
							{...formikProps} //__and that's because of the spread props in this line__
						/>
					</FormGroup>
				</Form>
			)}
		</Formik>
	);
}

My eslintrc.json

{
	"extends": [
		"eslint:recommended",
		"plugin:react/recommended",
		"react-app",
		"plugin:prettier/recommended",
		"prettier/react",
		"prettier/standard"
	],

	"env": {
		"es6": true,
		"browser": true
	},
	"rules": {
		"prettier/prettier": [
			"error",
			{
				"singleQuote": true,
				"printWidth": 120,
				"useTabs": true,
				"tabWidth": 4,
				"trailingComma": "all",
				"jsxBracketSameLine": true
			}
		],
		"no-unused-vars": [
			"error",
			{ "vars": "all", "args": "after-used", "caughtErrors": "all", "ignoreRestSiblings": false }
		],
		"padding-line-between-statements": ["error", { "blankLine": "always", "prev": "*", "next": "return" }],
		"lines-between-class-members": [2, "always"],
		"react/jsx-pascal-case": 0,
		"react/prop-types": [2, { "ignore": ["history"] }]
	}
}
@ljharb
Copy link
Member

ljharb commented Jan 17, 2019

(On a side note, there's zero reason for render to be an arrow function in a class field; that should be an instance method)

I've added a test case that passes; that suggests this is fixed on master but not yet released. I'm happy to reopen if the next release doesn't fix it.

@ljharb ljharb closed this as completed in 536bc35 Jan 17, 2019
@ljharb
Copy link
Member

ljharb commented Jan 17, 2019

v7.12.4 has been released.

This was referenced Jan 17, 2019
@Salles-FA
Copy link
Author

(On a side note, there's zero reason for render to be an arrow function in a class field; that should be an instance method)

I really appreciate it.

I've added a test case that passes; that suggests this is fixed on master but not yet released. I'm happy to reopen if the next release doesn't fix it.

Thank you! It's fixed now.

NimaSoroush pushed a commit to NimaSoroush/differencify that referenced this issue Feb 16, 2019
## The devDependency [eslint-plugin-react](https://github.com/yannickcr/eslint-plugin-react) was updated from `7.12.3` to `7.12.4`.
This version is **not covered** by your **current version range**.

If you don’t accept this pull request, your project will work just like it did before. However, you might be missing out on a bunch of new features, fixes and/or performance improvements from the dependency update.

---

<details>
<summary>Release Notes for v7.12.4</summary>

<h3>Fixed</h3>
<ul>
<li><a href="/yannickcr/eslint-plugin-react/blob/v7.12.4/docs/rules/no-unused-prop-types.md"><code>no-unused-prop-types</code></a>: avoid a crash (<a href="https://urls.greenkeeper.io/yannickcr/eslint-plugin-react/issues/2131" data-hovercard-type="issue" data-hovercard-url="/jsx-eslint/eslint-plugin-react/issues/2131/hovercard">#2131</a>, <a class="user-mention" data-hovercard-type="user" data-hovercard-url="/hovercards?user_id=45469" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://urls.greenkeeper.io/ljharb">@ljharb</a>)</li>
<li><a href="/yannickcr/eslint-plugin-react/blob/v7.12.4/docs/rules/prop-types.md"><code>prop-types</code></a>: avoid further crashes from nonexistent nodes in unusedPropTypes (<a href="https://urls.greenkeeper.io/yannickcr/eslint-plugin-react/issues/2127" data-hovercard-type="issue" data-hovercard-url="/jsx-eslint/eslint-plugin-react/issues/2127/hovercard">#2127</a>, <a class="user-mention" data-hovercard-type="user" data-hovercard-url="/hovercards?user_id=45469" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://urls.greenkeeper.io/ljharb">@ljharb</a>)</li>
<li><a href="/yannickcr/eslint-plugin-react/blob/v7.12.4/docs/rules/prop-types.md"><code>prop-types</code></a>: Read name of callee object (<a href="https://urls.greenkeeper.io/yannickcr/eslint-plugin-react/pull/2125" data-hovercard-type="pull_request" data-hovercard-url="/jsx-eslint/eslint-plugin-react/pull/2125/hovercard">#2125</a>, <a class="user-mention" data-hovercard-type="user" data-hovercard-url="/hovercards?user_id=817020" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://urls.greenkeeper.io/CrOrc">@CrOrc</a>)</li>
<li><a href="/yannickcr/eslint-plugin-react/blob/v7.12.4/docs/rules/prop-types.md"><code>prop-types</code></a>: Ignore reassignments when matching props declarations with components (<a href="https://urls.greenkeeper.io/yannickcr/eslint-plugin-react/issues/2051" data-hovercard-type="issue" data-hovercard-url="/jsx-eslint/eslint-plugin-react/issues/2051/hovercard">#2051</a>, <a href="https://urls.greenkeeper.io/yannickcr/eslint-plugin-react/issues/1957" data-hovercard-type="issue" data-hovercard-url="/jsx-eslint/eslint-plugin-react/issues/1957/hovercard">#1957</a>, <a class="user-mention" data-hovercard-type="user" data-hovercard-url="/hovercards?user_id=13209" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://urls.greenkeeper.io/yannickcr">@yannickcr</a>)</li>
<li><a href="/yannickcr/eslint-plugin-react/blob/v7.12.4/docs/rules/prop-types.md"><code>prop-types</code></a>, <a href="/yannickcr/eslint-plugin-react/blob/v7.12.4/docs/rules/no-unused-prop-types.md"><code>no-unused-prop-types</code></a>, <a href="/yannickcr/eslint-plugin-react/blob/v7.12.4/docs/rules/require-default-props.md"><code>require-default-props</code></a>: Detect components with return statement in switch/case (<a href="https://urls.greenkeeper.io/yannickcr/eslint-plugin-react/issues/2118" data-hovercard-type="issue" data-hovercard-url="/jsx-eslint/eslint-plugin-react/issues/2118/hovercard">#2118</a>, <a class="user-mention" data-hovercard-type="user" data-hovercard-url="/hovercards?user_id=13209" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://urls.greenkeeper.io/yannickcr">@yannickcr</a>)</li>
</ul>
<h3>Changed</h3>
<ul>
<li><a href="/yannickcr/eslint-plugin-react/blob/v7.12.4/docs/rules/prop-types.md"><code>prop-types</code></a>, <a href="/yannickcr/eslint-plugin-react/blob/v7.12.4/docs/rules/no-typos.md"><code>no-typos</code></a>: add passing test cases (<a href="https://urls.greenkeeper.io/yannickcr/eslint-plugin-react/issues/2123" data-hovercard-type="issue" data-hovercard-url="/jsx-eslint/eslint-plugin-react/issues/2123/hovercard">#2123</a>, <a href="https://urls.greenkeeper.io/yannickcr/eslint-plugin-react/issues/2128" data-hovercard-type="issue" data-hovercard-url="/jsx-eslint/eslint-plugin-react/issues/2128/hovercard">#2128</a>, <a href="https://urls.greenkeeper.io/yannickcr/eslint-plugin-react/issues/2136" data-hovercard-type="issue" data-hovercard-url="/jsx-eslint/eslint-plugin-react/issues/2136/hovercard">#2136</a>, <a href="https://urls.greenkeeper.io/yannickcr/eslint-plugin-react/issues/2134" data-hovercard-type="issue" data-hovercard-url="/jsx-eslint/eslint-plugin-react/issues/2134/hovercard">#2134</a>, <a class="user-mention" data-hovercard-type="user" data-hovercard-url="/hovercards?user_id=45469" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://urls.greenkeeper.io/ljharb">@ljharb</a>)</li>
</ul>
</details>

<details>
<summary>Commits</summary>
<p>The new version differs by 10 commits.</p>
<ul>
<li><a href="https://urls.greenkeeper.io/yannickcr/eslint-plugin-react/commit/433cc3f6fea3a202426cf8ea568aa4bf3fe7a415"><code>433cc3f</code></a> <code>Update CHANGELOG and bump version</code></li>
<li><a href="https://urls.greenkeeper.io/yannickcr/eslint-plugin-react/commit/536bc35643eacfacbeb2391c8ee49903b97954dc"><code>536bc35</code></a> <code>[Tests] <code>prop-types</code>: add case from #2134</code></li>
<li><a href="https://urls.greenkeeper.io/yannickcr/eslint-plugin-react/commit/df7ffc1b43964e5589f4c24eb8eaf03e1cb9a437"><code>df7ffc1</code></a> <code>[Tests] <code>no-typos</code>: test case from #2136</code></li>
<li><a href="https://urls.greenkeeper.io/yannickcr/eslint-plugin-react/commit/c7e5f384821d273f27c71030951fb6f02da5cfc6"><code>c7e5f38</code></a> <code>[Tests] improve version detection tests.</code></li>
<li><a href="https://urls.greenkeeper.io/yannickcr/eslint-plugin-react/commit/2dd2277cc4166e368a1dd172cfcebedcf930c212"><code>2dd2277</code></a> <code>[Tests] <code>prop-types</code>: add now-passing test case</code></li>
<li><a href="https://urls.greenkeeper.io/yannickcr/eslint-plugin-react/commit/84652b6527161f651a671754fb5f619296c3654e"><code>84652b6</code></a> <code>[Fix] <code>no-unused-prop-types</code>: avoid a crash</code></li>
<li><a href="https://urls.greenkeeper.io/yannickcr/eslint-plugin-react/commit/58ed9e9716f74dbf758766a5ac22425be411181f"><code>58ed9e9</code></a> <code>[Fix] <code>prop-types</code>: avoid further crashes from nonexistent nodes in unusedPropTypes</code></li>
<li><a href="https://urls.greenkeeper.io/yannickcr/eslint-plugin-react/commit/7f7b96d155dcb43baa3f438aa7c4720f0aa94298"><code>7f7b96d</code></a> <code>[Fix] <code>prop-types</code>: Read name of callee object.</code></li>
<li><a href="https://urls.greenkeeper.io/yannickcr/eslint-plugin-react/commit/5fc50aa9238768674cf2a2ca1d9676be629a920a"><code>5fc50aa</code></a> <code>[Fix] Ignore reassignments when matching props declarations with components</code></li>
<li><a href="https://urls.greenkeeper.io/yannickcr/eslint-plugin-react/commit/ba80a4c01b1086f6fd1202ebc9c262fc5f05b65b"><code>ba80a4c</code></a> <code>[Fix] Detect components with return statement in switch/case</code></li>
</ul>
<p>See the <a href="https://urls.greenkeeper.io/yannickcr/eslint-plugin-react/compare/2f5cec96eca70cfe579038c8b9a81ba5a6a88594...433cc3f6fea3a202426cf8ea568aa4bf3fe7a415">full diff</a></p>
</details>

<details>
  <summary>FAQ and help</summary>

  There is a collection of [frequently asked questions](https://greenkeeper.io/faq.html). If those don’t help, you can always [ask the humans behind Greenkeeper](https://github.com/greenkeeperio/greenkeeper/issues/new).
</details>

---


Your [Greenkeeper](https://greenkeeper.io) bot 🌴
@johnarnfield
Copy link

Seems like this is still an issue in version 7.17.0

Prop types are not validated in a function component with a return of:

return (
    ordering.length > 0 && (
      <Paginator items={ordering} pageSize={10} />
    )
)

But are with a function component with a return of:

  if (ordering.length > 0) {
    return false;
  }

  return (
    <Paginator items={ordering} pageSize={10} />
  )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

3 participants