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.

full classes compatibility (with static properties)

See original GitHub issue

I just upgraded to latest version and I am getting issue with classes used as react component. It seems some rules like displayName or prop-types are not able to read (or just don’t look) static fields.

import React, {Component, PropTypes} from "react"

class Widget extends Component {

  static displayName = "Widget"

  static childContextTypes = {
    styleVariables: PropTypes.object,
    RouteHandler: PropTypes.func,
  }

  static propTypes = {
    styleVariables: PropTypes.object,
    RouteHandler: PropTypes.func,
  }

  getChildContext() {
    return {
      styleVariables: this.props.styleVariables,
      RouteHandler: this.props.RouteHandler,
    }
  }
}

This code give me 3 errors:

   6:0   error  Widget component definition is missing display name         react/display-name
  24:22  error  'styleVariables' is missing in props validation for Widget  react/prop-types
  25:20  error  'RouteHandler' is missing in props validation for Widget    react/prop-types

It would be really cool to support this.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:9
  • Comments:35 (19 by maintainers)

github_iconTop GitHub Comments

27reactions
nshoescommented, Jul 12, 2017

@benmarten Yep, adding "parser": "babel-eslint" to my .eslintrc and installing it solved it for me as well.

17reactions
yannickcrcommented, Apr 17, 2015

@sebastienbarre I cannot reproduce your problem with eslint@0.19.0, eslint-plugin-react@2.1.1 and babel-eslint@3.0.1:

test.jsx

class Hello extends React.Component {
  static displayName = 'Widget';
  render() {
    return <div>Hello {this.props.name}</div>;
  }
}

.eslintrc

{
    "parser": "babel-eslint",
    "ecmaFeatures": {
        "classes": true,
        "jsx": true
    },
    "plugins": [
      "react"
    ],
    "rules": {
      "react/display-name": 1
    }
}
$ eslint --reset test.jsx # Does not find any error
Read more comments on GitHub >

github_iconTop Results From Across the Web

Static properties and methods - The Modern JavaScript Tutorial
Static methods does not depend on the class properties. It can work all on its own. The Whole Math class methods are static...
Read more >
static - JavaScript - MDN Web Docs - Mozilla
This page introduces public static properties of classes, which include static methods, static accessors, and static fields. ... Public static features are ...
Read more >
All about TypeScript Static Members | TypeScript OOP
Classes contain properties (methods and attributes) which hold variables and operations. Every time we define the properties of a class, they ...
Read more >
Static Classes and Static Class Members - C# guide
A non-static class can contain static methods, fields, properties, or events. The static member is callable on a class even when no instance...
Read more >
Static properties on a trait cannot be overriden by the class ...
If a trait defines a property then a class can not define a property with the same name unless it is compatible (same...
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