Skip to content

Imported propTypes triggers false positives #2357

Closed
@monsieurnebo

Description

@monsieurnebo

Hello,

Context

Package Version
eslint ~6.0.1
eslint-plugin-react ~7.14.2

The situation

After updating ESLint, I'm encountering false positives when importing propTypes (that are used in multiple places, for instance).

Let's take a simple example:

// sharedPropTypes.js

import PropTypes from "prop-types";

export default {
  steps : PropTypes.array,
};
// MyComponent.jsx

import React from "react";
import sharedPropTypes from "./sharedPropTypes";

const propTypes = {
  ...sharedPropTypes,
};

function MyComponent(props) {
  // Using steps.map somewhere
}

This scenario is triggering the following lint errors:
error 'steps.map' is missing in props validation react/prop-types

Which is new.

Please note that declaring propTypes in the component file is working fine:

// MyComponent.jsx

import React from "react";
import PropTypes from "prop-types";
import sharedPropTypes from "./sharedPropTypes";

const propTypes = {
  steps : PropTypes.array
};

function MyComponent(props) {
  // Using steps.map somewhere
}

A lead

After some searches, it seems that ESLint is more sensitive since #2301 .

  1. Could it be the source?
  2. How should I manage this situation in a clean way?

Related issues

#2352
#2343

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions