An open API service indexing awesome lists of open source software.

https://github.com/ammaraskar/eslint-injected-proptypes

ESLint prop types rule for React that avoids problems with injected props
https://github.com/ammaraskar/eslint-injected-proptypes

Last synced: 9 months ago
JSON representation

ESLint prop types rule for React that avoids problems with injected props

Awesome Lists containing this project

README

          

[![Travis Build State](https://travis-ci.org/ammaraskar/eslint-injected-proptypes.svg?branch=master)](https://travis-ci.org/ammaraskar/eslint-injected-proptypes)
[![codecov](https://codecov.io/gh/ammaraskar/eslint-injected-proptypes/branch/master/graph/badge.svg)](https://codecov.io/gh/ammaraskar/eslint-injected-proptypes)
[![npm](https://img.shields.io/npm/v/eslint-plugin-injected-proptypes.svg)](https://www.npmjs.com/package/eslint-plugin-injected-proptypes)

# Install

1. Install the package:

`npm install --dev eslint-plugin-injected-proptypes`

`yarn add --dev eslint-plugin-injected-proptypes`

2. Add `"plugins": ["injected-proptypes"]` to your eslint config file.

# Prevent missing propTypes in React components (non-injected-prop-types)

This rule ensures that all your React components have propTypes set for all of their used properties.
However, it ignores common injected properties such as those introduced by Redux's `mapDispatchToProps` and
`mapStateToProps`. See [eslint-plugin-react/#553](https://github.com/yannickcr/eslint-plugin-react/issues/553)
for more details.

## Rule Details

Examples of **incorrect** code for this rule:

```js
const Foo = ({ propMissingType }) =>
(
{propMissingType}
);
```

Examples of **correct** code for this rule:

```js
const Foo = ({providedProp, injectedProp}) =>
(
{providedProp}
{injectedProp}
);

const mapStateToProps = state => ({
injectedProp: state.fooBar
});

Foo.propTypes = {
providedProp: PropTypes.string.isRequired
};

export default connect(mapStateToProps)(Foo);
```

### Options

Consult the documentation for the original rule here:
https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/prop-types.md