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

Error: 'is missing in props validation' after update of ESLint to v5.4.0 #1957

Closed
Juuro opened this issue Aug 24, 2018 · 5 comments
Closed

Comments

@Juuro
Copy link

Juuro commented Aug 24, 2018

By now we validated our props like this:

class HelloEs6 extends React.Component {
  render() {
    return <div>Hello {this.props.name}</div>;
  }
}
HelloEs6.propTypes = {
  name: PropTypes.string.isRequired,
};

But after an update of ESLint from v4.19.1 to v5.4.0 we always get the 'is missing in props validation' error.

If we put the validation inside of the class it works perfectly like this:

class HelloEs6 extends React.Component {
  render() {
    return <div>Hello {this.props.name}</div>;
  }

  propTypes = {
    name: PropTypes.string.isRequired,
  };
}

Why is that the case? We couldn't find anything in the changelog according to this.

@Juuro Juuro changed the title 'is missing in props validation' error after update of ESLint to v5.4.0 Error: 'is missing in props validation' after update of ESLint to v5.4.0 Aug 24, 2018
@ljharb
Copy link
Member

ljharb commented Aug 24, 2018

That's confusing; the class field example is actually wildly incorrect - propTypes needs to be static on the class, not an instance field.

We have almost your exact example in our test cases, so it seems like something else is going on. Can you share your full eslint config?

@Juuro
Copy link
Author

Juuro commented Aug 28, 2018

Mh, I have this example from your rules documentation for prop-types: https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/prop-types.md propTypes works even if it's not defined as static. Maybe that is not "nice code" but it doesn't seem to be the problem here.

Here is our ESLint configuration:


{
  "settings": {
    "react": {
      "version": "16.3.14"
    }
  },
  "extends": [
    "eslint:recommended",
    "plugin:security/recommended",
    "plugin:react/recommended"
  ],
  "plugins": [
    "jest",
    "security"
  ],
  "parserOptions": {
    "ecmaVersion": 6,
    "sourceType": "module",
    "ecmaFeatures": {
      "jsx": true,
      "experimentalObjectRestSpread": true
    }
  },
  "parser": "babel-eslint",
  "globals": {
    "browser": true,
    "element": true,
    "by": true
  },
  "env": {
    "es6": true,
    "browser": true,
    "node": true,
    "jquery": true,
    "jest/globals": true
  },
  "rules": {
    "no-await-in-loop": 2,
    "quotes": [2, "single"],
    "no-console": 2,
    "no-debugger": 2,
    "accessor-pairs": 2,
    "no-var": 2,
    "array-callback-return": 2,
    "no-template-curly-in-string": 2,
    "semi": [2, "always"],
    "complexity": ["error", { "max": 10 }],
    "no-trailing-spaces": 2,
    "dot-location": [2, "property"],
    "eol-last": 0,
    "eqeqeq": 2,
    "no-unused-vars": 0,
    "guard-for-in": 2,
    "dot-notation": 2,
    "curly": 2,
    "default-case": 2,
    "consistent-return": 2,
    "no-underscore-dangle": 0,
    "no-alert": 2,
    "no-caller": 2,
    "no-eval": 2,
    "no-extra-bind": 2,
    "no-else-return": 2,
    "no-extra-label": 2,
    "no-lone-blocks": 2,
    "no-implicit-coercion": 2,
    "no-param-reassign": 2,
    "no-implicit-globals": 2,
    "no-octal-escape": 2,
    "no-implied-eval": 2,
    "no-new-wrappers": 2,
    "no-useless-concat": 2,
    "no-useless-return": 2,
    "no-label-var": 2,
    "no-undefined": 2,
    "prefer-promise-reject-errors": 2,
    "no-invalid-this": 2,
    "no-proto": 2,
    "no-with": 2,
    "no-return-assign": 2,
    "no-script-url": 2,
    "no-self-compare": 2,
    "no-throw-literal": 2,
    "no-return-await": 2,
    "no-iterator": 2,
    "no-multi-spaces": 2,
    "no-multi-str": 2,
    "no-new-func": 2,
    "no-labels": 2,
    "global-require": 2,
    "handle-callback-err": 2,
    "no-mixed-requires": 2,
    "no-new-require": 2,
    "no-path-concat": 2,
    "no-sync": 2,
    "key-spacing": ["error", {"afterColon": true}],
    "jsx-quotes": ["error", "prefer-double"],
    "object-curly-spacing": ["error", "never"],
    "prefer-const": ["error", {"destructuring": "any", "ignoreReadBeforeAssign": false}],
    "prefer-destructuring": ["error", {"VariableDeclarator": {"array": false,"object": true}, "AssignmentExpression": {"array": true, "object": false}}, {"enforceForRenamedProperties": false}],
    "no-duplicate-imports": ["error", { "includeExports": true }],
    "arrow-parens": ["error", "as-needed"],
    "quote-props": ["error", "as-needed"],
    "keyword-spacing": ["error", {"before": true}]
  }
}

@ljharb
Copy link
Member

ljharb commented Aug 28, 2018

React doesn't have a v16.3.14, btw, it only goes up to v16.3.2 before v16.4. However this, just like static get propTypes, is a red herring.

This should definitely work. cc @alexzherdev any ideas?

@alexzherdev
Copy link
Contributor

alexzherdev commented Aug 28, 2018

Ok, I'm a little bit confused - is this issue only about the fact that propTypes works as a non-static class field? That should be easy to fix.
There also appears to be an issue with HelloEs6.propTypes = {} form not being handled correctly. If that's the case, I'd ask for the actual component's code that doesn't work (because the example from the docs does work at least according to the tests).

@Juuro
Copy link
Author

Juuro commented Aug 30, 2018

Yes, it was the latter. But wie fixed it by ourselves. The problem was that we exported the class like

export const PersoenlicheDatenWithoutStore = PersoenlicheDaten;

After we changed this to

export {PersoenlicheDaten as PersoenlicheDatenWithoutStore};

It works like a charm.

I don't understand why the first version causes 'is missing in props validation' errors. But we wanted to update to the other syntax anyway.
Thank you for your help! If you have any idea why this error was caused I would be eager to lern something. :-)

@ghost ghost mentioned this issue Jan 17, 2019
1 task
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 🌴
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants