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

prop-types doesn't check nextProps of componentWillReceiveProps #1636

Closed
mqklin opened this issue Jan 9, 2018 · 5 comments
Closed

prop-types doesn't check nextProps of componentWillReceiveProps #1636

mqklin opened this issue Jan 9, 2018 · 5 comments

Comments

@mqklin
Copy link

mqklin commented Jan 9, 2018

  • ESLint Version: 4.15.0
  • Node Version: 8.7.0
  • npm Version: 5.5.1

parser babel-eslint

Configuration

/* global module, __dirname */
/* eslint-disable import/no-commonjs, import/no-nodejs-modules */

const path = require('path');

module.exports = {
  globals: {
    require: false,
    process: false,
    Promise: false,
    fbq: false,
    dataLayer: false,
    ga: false,
    mixpanel: false,
    yaCounter: false,
    Raven: false,

    // browser env
    localStorage: false,
    document: false,
    console: false,
    window: false,
    setTimeout: false,
    clearTimeout: false,
    setInterval: false,
    clearInterval: false,
    navigator: false,
    FormData: false,
  },
  parser: 'babel-eslint',
  parserOptions: {
    ecmaFeatures: {
      jsx: true,
    },
    sourceType: 'module',
  },
  plugins: [
    'react',
    'import',
    'class-property',
    'brackets',
  ],
  settings: {
    'import/resolver': {
      webpack: {
        config: path.resolve(__dirname, 'webpack-config/dev.js'),
      },
    },
    propWrapperFunctions: ['forbidExtraProps'],
  },
  rules: {
    'quote-props': ['error', 'as-needed'],
    'no-use-before-define': ['error', {functions: false, classes: false}],
    'space-before-blocks': ['error'],
    'no-redeclare': ['error'],
    'no-case-declarations': ['error'],
    'no-const-assign': ['error'],
    'key-spacing': ['error'],
    'keyword-spacing': ['error'],
    'no-dupe-class-members': ['error'],
    'comma-spacing': ['error'],
    'no-var': ['error'],
    'prefer-const': ['error'],
    'space-infix-ops': ['error'],
    'eol-last': ['error', 'always'],
    indent: ['error', 2, {SwitchCase: 1}],
    'no-mixed-spaces-and-tabs': ['error'],
    'linebreak-style': ['error', 'unix'],
    'default-case': ['error'],
    'no-console': ['error'],
    'no-alert': ['error'],
    'no-debugger': ['error'],
    'no-global-assign': ['error'],
    'no-dupe-args': ['error'],
    'no-dupe-keys': ['error'],
    'no-duplicate-case': ['error'],
    'no-empty': ['error', {allowEmptyCatch: true}],
    'no-extra-boolean-cast': ['error'],
    'no-extra-parens': ['error', 'functions'],
    'no-extra-semi': ['error'],
    'no-irregular-whitespace': ['error'],
    'no-multiple-empty-lines': ['error', {max: 2, maxEOF: 1}],
    'no-sparse-arrays': ['error'],
    'no-undef': ['error'],
    'no-unexpected-multiline': ['error'],
    'no-unused-expressions': ['error', {allowTaggedTemplates: true, allowTernary: true}],
    'no-unreachable': ['error'],
    semi: ['error', 'always', {omitLastInOneLineBlock: true}],
    'object-curly-spacing': ['error', 'never'],
    'arrow-parens': ['error', 'as-needed'],
    quotes: ['error', 'single'],
    'jsx-quotes': ['error'],
    curly: ['error'],
    'brace-style': ['error', 'stroustrup'],
    'no-multi-spaces': ['error'],
    'no-duplicate-imports': ['error'],
    'no-restricted-syntax': [
      'error',
      {
        selector: 'AssignmentExpression[left.object.name=\'window\']',
        message: 'Don\'t write to window!',
      },
    ],
    'comma-dangle': ['error', {
      arrays: 'always-multiline',
      objects: 'always-multiline',
      imports: 'always-multiline',
      exports: 'always-multiline',
      functions: 'always-multiline',
    }],

    'react/no-unused-state': 'error',
    'react/no-unused-prop-types': 'error',
    'react/prop-types': 'error',

    'react/jsx-uses-react': 'error',
    'react/jsx-uses-vars': 'error',
    'react/jsx-tag-spacing': ['error', {beforeSelfClosing: 'never'}],
    'react/jsx-no-target-blank': 'error',
    'react/jsx-no-undef': 'error',
    'react/jsx-no-duplicate-props': 'error',
    'react/jsx-key': 'error',
    'react/jsx-indent': ['error', 2],
    'react/jsx-indent-props': ['error', 2],

    'import/no-unresolved': 'error',
    'import/named': 'error',
    'import/default': 'error',
    'import/no-commonjs': 'error',
    'import/no-nodejs-modules': 'error',

    'class-property/class-property-semicolon': ['error', 'always'],

    'brackets/array-bracket-newline': 'error',
    'brackets/call-parens-newline': 'error',
    'brackets/conditional-parens-newline': 'error',
    'brackets/func-parens-newline': 'error',
    'brackets/object-curly-newline': 'error',

  },
};


What did you do? Please include the actual source code causing the issue, as well as the command that you used to run ESLint.

import {Component} from 'react';

export default class MyComponent extends Component {
  componentWillReceiveProps({x}) { // no error about x (but should be)
    const {y} = this.props; // 'y' is missing in props validation (react/prop-types)
  }
}

image

Some duplication of #814

@amerryma
Copy link
Contributor

amerryma commented Feb 8, 2018

Just wanted to clarify something. Should this also apply to the shouldComponentUpdate function?

@ljharb
Copy link
Member

ljharb commented Feb 8, 2018

Theoretically yes :-) please file a new issue if it’s not

@muhabalwan
Copy link

muhabalwan commented Jun 19, 2018

#1832 a related issue I'm guessing

@jcabrerazuniga
Copy link

I used like: componentWillReceiveProps(nextProps: Props)
I am getting syntax error at :
what is the syntax now?

@ljharb
Copy link
Member

ljharb commented Nov 2, 2018

That’s not JavaScript, that’s typescript or flow.

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

No branches or pull requests

5 participants