question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

eslint showing error when using variable from parent scope

See original GitHub issue

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 https://github.com/eslint/eslint/issues/12004

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:11 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
ljharbcommented, Jul 18, 2019

gotcha, in that case it seems like a bug.

0reactions
jzabalacommented, Jul 8, 2020

This one is fixed too with #2699

Read more comments on GitHub >

github_iconTop Results From Across the Web

eslint showing error when using variable from parent scope
renderContent is being detected as a component ; but either way you should be destructuring props directly inside your component, not later.
Read more >
Working with Rules - ESLint - Pluggable JavaScript Linter
The Scope#variables property contains an array of Variable objects. These are the variables declared in current scope. You can use these Variable objects...
Read more >
ESlint reports an error when I call my parent's function
In my parent controller I added my function to the $scope so that the function could be accessed from state's child. function MyParentController ......
Read more >
ESLint | WebStorm Documentation - JetBrains
WebStorm shows warnings and errors reported by ESLint right in the editor ... project or in its specific parts, see Configure linting scope....
Read more >
Scope - Beginner JavaScript - Wes Bos
console showing value of the typed variable within scope ... If you hover over the variable in VSCode, you will see an error...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found