Skip to content

eslint showing error when using variable from parent scope #2352

Closed
@afucher

Description

@afucher

Tell us about your environment

  • ESLint Version: 6.0.1
  • Node Version: v10.15.3
  • npm Version: 6.4.1

What parser (default, Babel-ESLint, etc.) are you using?
default
Please show your full configuration:

Configuration

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 React from 'react';

interface Props {
    readonly history: number[];
}

export const MyHistory = (props: Props) => {
    const renderContent = () => {
        if (props.history.length > 0) {
            return <div> My history here</div>
        }
        return <div> No historical events</div>
    };

    return renderContent();
};
npm run eslint --fix --ext .tsx --ext .ts src

What did you expect to happen?
eslint show no errors

What actually happened? Please include the actual, raw output from ESLint.

  9:19  error  'history' is missing in props validation         react/prop-types
  9:27  error  'history.length' is missing in props validation  react/prop-types

Additional info: issue first created on eslint repo eslint/eslint#12004

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