Skip to content

no-unused-prop-types does not trigger if class does not use any properties #1162

Closed
@Wilfred

Description

import React from "react";

var Hello = React.createClass({
  propTypes: {
    name: React.PropTypes.string
  },
  render: function() {
    return <div>Hello Bob</div>;
  }
});

This is almost identical to the first example in the docs.

$ eslint --no-eslintrc --parser-options="{sourceType: \"module\", ecmaVersion: 6, ecmaFeatures: {jsx:true}}" --plugin react --rule react/no-unused-prop-types:error js/Hello.jsx
# No errors shown.

By contrast, this does trigger:

import React from "react";

var Hello = React.createClass({
  propTypes: {
    name: React.PropTypes.string
  },
  render: function() {
    return <div>Hello Bob {this.props.foo}</div>;
  }
});
$ eslint --no-eslintrc --parser-options="{sourceType: \"module\", ecmaVersion: 6, ecmaFeatures: {jsx:true}}" --plugin react --rule react/no-unused-prop-types:error js/Hello.jsx

js/Hello.jsx
  5:11  error  'name' PropType is defined but prop is never used  react/no-unused-prop-types

✖ 1 problem (1 error, 0 warnings)

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