jfmengels / eslint-plugin-fp

ESLint rules for functional programming
MIT License
970 stars 36 forks source link

PropTypes for stateless components #16

Closed iamricard closed 7 years ago

iamricard commented 7 years ago

Hi 👋 ,

First off, great plugin! I was wondering if you'd accept a PR modifying fp/no-mutation to allow for a pattern such as this:

import React from 'react'

const Component = (props) => <div>{props.name}</div>

Component.propTypes = { name: React.PropTypes.string.isRequired }

export default Component

There doesn't seem to be a different way to define propType validation and use stateless components at the same time.

jfmengels commented 7 years ago

Hey @rcsole!

First off, great plugin!

Thanks :D

I was wondering if you'd accept a PR modifying fp/no-mutation to allow for a pattern such as this

This is already possible using the exceptions option in the rule. See https://github.com/jfmengels/eslint-plugin-fp/blob/master/docs/rules/no-mutation.md for how to set that up properly.

/* eslint fp/no-mutation: ["error", {"exceptions": [{"property": "propTypes"}]}] */
function Component(props) {
  // ...
}

Component.propTypes = {
  // ...
};

If you feel that the documentation is not clear, feel free to make a PR to try and make it clearer.

There doesn't seem to be a different way to define propType validation and use stateless components at the same time.

Yes, there is none in React that I'm aware of...